This commit is contained in:
2024-05-28 22:53:49 +03:00
parent 063624d7bb
commit 9b0e678611
6 changed files with 86 additions and 116 deletions

0
4k_test.zip Normal file
View File

BIN
4k_test2.zip Normal file

Binary file not shown.

View File

@ -59,7 +59,7 @@ EXE_LINKER_PROGRAM=Crinkler
QUOTE=\" QUOTE=\"
CRINKLER_ORDERTRIES=4000 CRINKLER_ORDERTRIES=400
AUDIO_BUFFER_ALLOCATED_LENGTH=5257472 AUDIO_BUFFER_ALLOCATED_LENGTH=5257472
AUDIO_SAMPLING_RATE=44100 AUDIO_SAMPLING_RATE=44100

View File

@ -8,7 +8,7 @@ include $(PARENT_CONFIG)
# Visuals # Visuals
EXE_LINKER_PROGRAM=Crinkler EXE_LINKER_PROGRAM=Crinkler
CRINKLER_ORDERTRIES=4000 CRINKLER_ORDERTRIES=400
SHADER_FILE=shader_minified.h SHADER_FILE=shader_minified.h
TIME_UNIFORM_NAME='v' TIME_UNIFORM_NAME='v'
RESOLUTION_UNIFORM_NAME='m' RESOLUTION_UNIFORM_NAME='m'

View File

@ -3,16 +3,6 @@ uniform vec2 resolution;
uniform sampler2D texture_sampler; uniform sampler2D texture_sampler;
uniform sampler2D texts; uniform sampler2D texts;
#define MAX_STEPS 100
#define MAX_DIST 20.
#define SURF_DIST .001
#define TAU 6.283185
#define PI 3.141592
#define FOG_DENSITY 0.01
struct Obj { struct Obj {
float distance; // distance map float distance; // distance map
int material; // material Id int material; // material Id
@ -25,8 +15,7 @@ mat2 Rot(float a) {
} }
vec3 applyFog(in vec3 color, in float distance) { vec3 applyFog(in vec3 color, in float distance) {
float fogAmount = 1.0 - exp(-distance *0.01);
float fogAmount = 1.0 - exp(-distance*FOG_DENSITY);
vec3 fogColor = vec3(0.17, 0.16, 0.24); vec3 fogColor = vec3(0.17, 0.16, 0.24);
return mix( color, fogColor, fogAmount ); return mix( color, fogColor, fogAmount );
} }
@ -95,13 +84,13 @@ Obj castRay(vec3 ro, vec3 rd) {
float t = 0.0; float t = 0.0;
Obj res = Obj(-1., -1); Obj res = Obj(-1., -1);
for(int i=0; i<MAX_STEPS; i++) { for(int i=0; i<100; i++) {
vec3 p = ro + rd * t; vec3 p = ro + rd * t;
res = mapScene(p); res = mapScene(p);
t += res.distance; t += res.distance;
if (t > MAX_DIST || res.distance < abs(SURF_DIST*t) ) break; if (t > 20.0 || res.distance < abs(0.001*t) ) break;
} }
if (t > MAX_DIST) t = -1.0; if (t > 20.0) t = -1.0;
res.distance = t; res.distance = t;
return res; return res;
} }
@ -109,7 +98,7 @@ Obj castRay(vec3 ro, vec3 rd) {
float castShadow(vec3 ro, vec3 rd) { float castShadow(vec3 ro, vec3 rd) {
float res = 1.0; float res = 1.0;
float t = 0.001; float t = 0.001;
for(int i = 0; i < MAX_STEPS; i++) { for(int i = 0; i < 100; i++) {
vec3 pos = ro + t* rd; vec3 pos = ro + t* rd;
float h = mapScene(pos).distance; float h = mapScene(pos).distance;
res = min(res, 10.0*h/t); res = min(res, 10.0*h/t);
@ -191,10 +180,6 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, int material) {
float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.); float sun_dif = clamp(dot(n, SUN_DIR), 0., 1.);
final += outMaterial * vec3(0.0353, 0.2667, 0.4784) * sun_dif; final += outMaterial * vec3(0.0353, 0.2667, 0.4784) * sun_dif;
} }
// final += texture( iChannel0, ref ).rgb * fresnel( Ks, n, -dir );
// vec3 col = vec3(0.4)* ref.x;
//vec3 col = vec3(0.0588, 0.0588, 0.1216);// - vec3(0.149, 0.0863, 0.2314) * v.x;
//final += col * fresnel( vec3(.5), ref, -dir );
return final; return final;
} }
@ -202,12 +187,9 @@ vec3 shading(vec3 v, vec3 n, vec3 dir, int material) {
void main() void main()
{ {
vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y; vec2 p = (gl_FragCoord.xy * 2. - resolution.xy) / min(resolution.x, resolution.y);
// vec2 p = (2.0 * gl_FragCoord.xy - resolution.xy) / resolution.y;
float angle = time*0.4; float angle = time*0.4;
// angle = 2.0; // comment to rotate
// gl_FragColor = vec4(vec3(sdCog2d(p)), 1.);
// return;
// camera
vec3 ta = vec3(0.0, 0., 0.0); vec3 ta = vec3(0.0, 0., 0.0);
vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle)) vec3 ro = ta + vec3(4.*sin(angle), cos(angle), 4.*cos(angle)); // *cos(angle))
@ -228,6 +210,5 @@ void main()
// apply fog // apply fog
col = applyFog(col, t.distance); col = applyFog(col, t.distance);
} }
gl_FragColor = vec4( pow(col, vec3(1.0/1.3) ), 1.0 );
gl_FragColor = vec4( pow( col, vec3(1.0/1.3) ), 1.0 );
} }

View File

@ -9,152 +9,141 @@
const char *__temp_cleaned_shader_glsl = const char *__temp_cleaned_shader_glsl =
"uniform float v;" "uniform float v;"
"uniform vec2 m;" "uniform vec2 m;"
"uniform sampler2D e,d;\n" "uniform sampler2D e,d;struct Obj{float distance;int material;};"
"#define MAX_STEPS 100\n"
"#define MAX_DIST 20.\n"
"#define SURF_DIST.001\n"
"#define TAU 6.283185\n"
"#define PI 3.141592\n"
"#define FOG_DENSITY 0.01\nstruct Obj{float distance;int material;};"
"mat2 n(float v)" "mat2 n(float v)"
"{" "{"
"float m=sin(v),d=cos(v);" "float f=sin(v),y=cos(v);"
"return mat2(d,-m,m,d);" "return mat2(y,-f,f,y);"
"}" "}"
"vec3 n(vec3 v,float m)" "float n(vec3 v,float m)"
"{" "{"
"float d=1.-exp(-m*FOG_DENSITY);" "vec2 f=vec2(m,abs(v.z)-.15);"
"return mix(v,vec3(.17,.16,.24),d);" "return min(max(f.x,f.y),0.)+length(max(f,0.));"
"}"
"float s(vec3 v,float m)"
"{"
"vec2 d=vec2(m,abs(v.z)-.15);"
"return min(max(d.x,d.y),0.)+length(max(d,0.));"
"}" "}"
"float s(vec2 v)" "float s(vec2 v)"
"{" "{"
"float d=1.-smoothstep(-.2,.8,sin(atan(v.y,v.x)*12.))*.14;" "float f=1.-smoothstep(-.2,.8,sin(atan(v.y,v.x)*12.))*.14;"
"return smoothstep(d,d+2.,length(v)*2.);" "return smoothstep(f,f+2.,length(v)*2.);"
"}" "}"
"float x(float m,float v)" "float s(float f,float v)"
"{" "{"
"float d=max(.02-abs(-m-v),0.);" "float m=max(.02-abs(-f-v),0.);"
"return max(-m,v)+d*d*.25/.02;" "return max(-f,v)+m*m*.25/.02;"
"}" "}"
"float x(vec3 v)" "float x(vec3 v)"
"{" "{"
"vec3 m=vec3(0),d=v-m,y=vec3(0,0,1)-m;" "vec3 f=vec3(0),m=v-f,y=vec3(0,0,1)-f;"
"return length(d-y*clamp(dot(d,y)/dot(y,y),0.,1.))-.2;" "return length(m-y*clamp(dot(m,y)/dot(y,y),0.,1.))-.2;"
"}" "}"
"float p(vec3 v,float m)" "float x(vec3 v,float m)"
"{" "{"
"v.xy*=n(m);" "v.xy*=n(m);"
"float d=s(v,s(v.xy)),y=x(v-vec3(0,0,-.5));" "float f=n(v,s(v.xy)),y=x(v-vec3(0,0,-.5));"
"return.8*x(y,d)-.001;" "return.8*s(y,f)-.001;"
"}" "}"
"Obj p(vec3 m)" "Obj f(vec3 m)"
"{" "{"
"float d=1e10;" "float f=1e10;"
"Obj e=Obj(m.y+1.5+sin(m.z*.6)*.2+sin(m.x*1.3)*.1,0);" "Obj e=Obj(m.y+1.5+sin(m.z*.6)*.2+sin(m.x*1.3)*.1,0);"
"{" "{"
"float y=p(m+vec3(1,0,0),v);" "float y=x(m+vec3(1,0,0),v);"
"d=min(d,y);" "f=min(f,y);"
"}" "}"
"{" "{"
"float y=p(m+vec3(.5,-.87,0),-v);" "float y=x(m+vec3(.5,-.87,0),-v);"
"d=min(d,y);" "f=min(f,y);"
"}" "}"
"{" "{"
"float y=p(m+vec3(.5,.87,0),-v);" "float y=x(m+vec3(.5,.87,0),-v);"
"d=min(d,y);" "f=min(f,y);"
"}" "}"
"Obj y=Obj(d,1);" "Obj y=Obj(f,1);"
"return e.distance>y.distance?" "return e.distance>y.distance?"
"y:" "y:"
"e;" "e;"
"}" "}"
"Obj t(vec3 v,vec3 m)" "Obj f(vec3 v,vec3 y)"
"{" "{"
"float d=0.;" "float m=0.;"
"Obj r=Obj(-1.,-1);" "Obj r=Obj(-1.,-1);"
"for(int y=0;y<MAX_STEPS;y++)" "for(int e=0;e<100;e++)"
"{" "{"
"vec3 e=v+m*d;" "vec3 c=v+y*m;"
"r=p(e);" "r=f(c);"
"d+=r.distance;" "m+=r.distance;"
"if(d>MAX_DIST||r.distance<abs(SURF_DIST*d))" "if(m>20.||r.distance<abs(.001*m))"
"break;" "break;"
"}" "}"
"if(d>MAX_DIST)" "if(m>20.)"
"d=-1.;" "m=-1.;"
"r.distance=d;" "r.distance=m;"
"return r;" "return r;"
"}" "}"
"float f(vec3 v,vec3 m)" "float p(vec3 v,vec3 m)"
"{" "{"
"float d=1.,y=.001;" "float y=1.,r=.001;"
"for(int r=0;r<MAX_STEPS;r++)" "for(int e=0;e<100;e++)"
"{" "{"
"vec3 e=v+y*m;" "vec3 c=v+r*m;"
"float c=p(e).distance;" "float n=f(c).distance;"
"d=min(d,10.*c/y);" "y=min(y,10.*n/r);"
"if(abs(c)<.001*y)" "if(abs(n)<.001*r)"
"break;" "break;"
"y+=c;" "r+=n;"
"if(y>20.)" "if(r>20.)"
"break;" "break;"
"}" "}"
"return clamp(d,0.,1.);" "return clamp(y,0.,1.);"
"}" "}"
"vec3 f(vec3 v)" "vec3 p(vec3 v)"
"{" "{"
"vec2 m=vec2(.001,0);" "vec2 m=vec2(.001,0);"
"vec3 d=vec3(p(v+m.xyy).distance-p(v-m.xyy).distance,p(v+m.yxy).distance-p(v-m.yxy).distance,p(v+m.yyx).distance-p(v-m.yyx).distance);" "vec3 y=vec3(f(v+m.xyy).distance-f(v-m.xyy).distance,f(v+m.yxy).distance-f(v-m.yxy).distance,f(v+m.yyx).distance-f(v-m.yyx).distance);"
"return normalize(d);" "return normalize(y);"
"}" "}"
"vec3 f(vec3 m,vec3 v,vec3 d)" "vec3 f(vec3 v,vec3 m,vec3 y)"
"{" "{"
"return m+(1.-m)*pow(clamp(1.-dot(v,d),0.,1.),5.);" "return v+(1.-v)*pow(clamp(1.-dot(m,y),0.,1.),5.);"
"}" "}"
"vec3 f(vec3 v,vec3 d,vec3 m,int y)" "vec3 f(vec3 v,vec3 y,vec3 m,int c)"
"{" "{"
"float e=1.;" "float e=1.;"
"vec3 r=vec3(0),c=reflect(m,d),a=vec3(.5),i=vec3(1),n=vec3(.1255);" "vec3 r=vec3(0),d=reflect(m,y),n=vec3(.5),a=vec3(1),O=vec3(.1255);"
"if(y==0)" "if(c==0)"
"n=vec3(.1412),e=3.1;" "O=vec3(.1412),e=3.1;"
"else if(y==1)" "else if(c==1)"
"n=vec3(.1765,.1961,.2275),e=21.;" "O=vec3(.1765,.1961,.2275),e=21.;"
"{" "{"
"vec3 x=normalize(vec3(-2,.3,10)-v),O=vec3(max(0.,dot(x,c))),l=f(a,normalize(x-m),x);" "vec3 x=normalize(vec3(-2,.3,10)-v),i=vec3(max(0.,dot(x,d))),l=f(n,normalize(x-m),x);"
"O=pow(O,vec3(e));" "i=pow(i,vec3(e));"
"r+=n*O*(vec3(.71,.51,.72)*5.)*mix(i*vec3(max(0.,dot(x,d))),O,l);" "r+=O*i*(vec3(.71,.51,.72)*5.)*mix(a*vec3(max(0.,dot(x,y))),i,l);"
"}" "}"
"{" "{"
"vec3 x=normalize(vec3(5,5,-20)-v),O=vec3(max(0.,dot(x,c))),l=f(a,normalize(x-m),x);" "vec3 x=normalize(vec3(5,5,-20)-v),i=vec3(max(0.,dot(x,d))),l=f(n,normalize(x-m),x);"
"O=pow(O,vec3(e));" "i=pow(i,vec3(e));"
"r+=n*O*(vec3(.14,.36,.83)*7.)*mix(i*vec3(max(0.,dot(x,d))),O,l);" "r+=O*i*(vec3(.14,.36,.83)*7.)*mix(a*vec3(max(0.,dot(x,y))),i,l);"
"}" "}"
"{" "{"
"vec3 x=vec3(0,.4,1);" "vec3 x=vec3(0,.4,1);"
"float O=clamp(dot(d,x),0.,1.),l=f(v+d*.02,x);" "float i=clamp(dot(y,x),0.,1.),l=p(v+y*.02,x);"
"r+=n*vec3(1.1,1.2,1.5)*O*O*l;" "r+=O*vec3(1.1,1.2,1.5)*i*i*l;"
"}" "}"
"r+=n*vec3(.0353,.2667,.4784)*clamp(dot(d,vec3(0,.6,-1)),0.,1.);" "r+=O*vec3(.0353,.2667,.4784)*clamp(dot(y,vec3(0,.6,-1)),0.,1.);"
"return r;" "return r;"
"}" "}"
"void main()" "void main()"
"{" "{"
"vec2 d=(2.*gl_FragCoord.xy-m.xy)/m.y;" "vec2 y=(gl_FragCoord.xy*2.-m.xy)/min(m.x,m.y);"
"float y=v*.4;" "float x=v*.4;"
"vec3 e=vec3(0),x=e+vec3(4.*sin(y),cos(y),4.*cos(y)),O=normalize(e-x),c=normalize(cross(O,vec3(0,1,0))),l=normalize(d.x*c+d.y*normalize(cross(c,O))+1.4*O),r=vec3(.1451,.1098,.1608)-vec3(.9725,.5176,0)*l.y;" "vec3 e=vec3(0),i=e+vec3(4.*sin(x),cos(x),4.*cos(x)),c=normalize(e-i),r=normalize(cross(c,vec3(0,1,0))),l=normalize(y.x*r+y.y*normalize(cross(r,c))+1.4*c),d=vec3(.1451,.1098,.1608)-vec3(.9725,.5176,0)*l.y;"
"Obj i=t(x,l);" "Obj n=f(i,l);"
"if(i.distance>0.)" "if(n.distance>0.)"
"{" "{"
"vec3 a=x+l*i.distance,s=f(a);" "vec3 a=i+l*n.distance,O=p(a);"
"r=f(a,s,l,i.material);" "d=f(a,O,l,n.material);"
"r=n(r,i.distance);" "d=mix(d,vec3(.17,.16,.24),1.-exp(-n.distance*.01));"
"}" "}"
"gl_FragColor=vec4(pow(r,vec3(1./1.3)),1);" "gl_FragColor=vec4(pow(d,vec3(1./1.3)),1);"
"}"; "}";
#endif // SHADER_MINIFIED_H_ #endif // SHADER_MINIFIED_H_