Optimointeja

This commit is contained in:
2024-07-26 19:35:31 +03:00
parent 98263cafaa
commit a7eed4cefb
2 changed files with 155 additions and 155 deletions

View File

@ -104,27 +104,33 @@ float sdTriPrism( vec3 p, vec2 h, float rot )
const float TWOPI = 6.28318530718; const float TWOPI = 6.28318530718;
// Rotate ring with duration d and startTime s // Rotate ring with duration d and startTime s
float ringRotateFunc(float d, float s, float timeFact) { float ringRotateFunc(float maxCycles, float startTime, float timeFact) {
float maxCycles = d;
float startTime = s;
float phase = ((u_time * timeFact) - startTime) / TWOPI; float phase = ((u_time * timeFact) - startTime) / TWOPI;
phase = min(phase, maxCycles); phase = min(phase, maxCycles);
return TWOPI * phase; return TWOPI * phase;
} }
float calcFactor (float startTime)
{
const float FACTOR = 9.0;
float factor = FACTOR+FACTOR*clamp(sin(ringRotateFunc(2.0, startTime, 1.0) * 0.05), -0.9, 0.9);
return factor;
}
// Animate ring movements // Animate ring movements
vec3 ringAnim( in vec3 p) { vec3 ringAnim( in vec3 p) {
const float STARTDELAY = 9.0; const float STARTDELAY = 9.0;
const float OTHERDELAY = 14.0;
float factor = 9.0+9.0*clamp(sin(ringRotateFunc(2.0, 0.0, 1.0) * 0.05), -0.9, 0.9); float factor = 0.;
// delay start // delay start
if( u_time >= STARTDELAY ) { if( u_time >= STARTDELAY ) {
p.xy = rot2D(factor) * p.xy; p.xy = rot2D(calcFactor(STARTDELAY)) * p.xy;
} }
if(u_time >= 14.0) { if(u_time >= OTHERDELAY) {
factor = 9.0+9.0*clamp(sin(ringRotateFunc(2.0, 14.0, 1.0) * 0.05), -0.9, 0.9); p.xy = rot2D(calcFactor(OTHERDELAY) * -1.0) * p.xy;
p.xy = rot2D(factor * -1.0) * p.xy;
} }
return p; return p;
@ -231,20 +237,20 @@ vec2 map(in vec3 p)
} }
float sand = (p.y + 4.25) + 1.5*noise((vec2((p.x*0.04),(p.z-40.0)*0.04))+100., 15.); float sand = (p.y + 4.25) + 1.5*noise((vec2((p.x*0.04),(p.z-40.0)*0.04))+100., 15.);
sand += noise(p.yz, .25);
sand += 0.025*noise(p.xz*50.+100., .05);
d = min(d,sand); d = min(d,sand);
float water = 1000.; float water = 1000.;
if (u_time > 2.0){ float cylinder1 = sdCylinder ( p, vec3(0.,0.,0.0), vec3(0.,0.,-0.01), 1.6);
float cylinder1 = sdCylinder ( p, vec3(0.,0.,0.0), vec3(0.,0.,-0.01), 1.6); float cylinder2 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1), clamp((2.0 - (u_time*2.0 - 2.0*13.0)),0.,2.0));
float cylinder2 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1), (2. - (u_time*2.0 - 2.0*13.0))); float cylinder3 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1.), 1.6);
float cylinder3 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1.), 1.6); float disp = 0.;
float disp = 0.; disp = displacement(p)*clamp(((u_time-14.0)*0.5), 0., 0.25);
disp = displacement(p)*clamp(((u_time-14.0)*0.5), 0., 0.25); cylinder1 = cylinder1 + disp;
cylinder1 = cylinder1 + disp; water = max(-cylinder2, cylinder1);
water = max(-cylinder2, cylinder1); water = max(water, cylinder3);
water = max(water, cylinder3); d = min(d, water);
d = min(d, water);
}
if (d==water) if (d==water)
{ {
@ -321,17 +327,14 @@ vec3 getCameraRayDir(vec2 uv, vec3 p, vec3 l, float z)
} }
vec3 postProcess(vec3 col) { vec3 postProcess(vec3 col) {
// float random = noise(gl_FragCoord.xy, 0.01+u_time);
// float random2 = noise(gl_FragCoord.xy, .2+u_time);
//col += 0.075*clamp(vec3(0.5*random, 0.5*random2, 0.5*random), 0.02, 1.); // dither
// Normalized pixel coordinates (from 0 to 1) // Normalized pixel coordinates (from 0 to 1)
vec2 screenCoord = gl_FragCoord.xy/u_resolution.xy; vec2 screenCoord = gl_FragCoord.xy/u_resolution.xy;
// Vignette // Vignette
float radius = 0.9; //float radius = 0.9;
float d = smoothstep(radius, radius-0.4, length(screenCoord-vec2(0.5))); //float d = smoothstep(radius, radius-0.4, length(screenCoord-vec2(0.5)));
col = mix(col, col * d, .9); //col = mix(col, col * d, .9);
// Contrast = a // Contrast = a
col = mix(col, smoothstep(0.0, 1.0, col), 0.9); col = mix(col, smoothstep(0.0, 1.0, col), 0.9);
@ -340,12 +343,6 @@ vec3 postProcess(vec3 col) {
col *= vec3(1.0, 1.0, 1.0); col *= vec3(1.0, 1.0, 1.0);
col = pow( col, vec3(1.0/2.2) ); // gamma col = pow( col, vec3(1.0/2.2) ); // gamma
// fade in at the beginning
//col*=vec3(clamp((u_time-1.8)*0.5,0., 1.));
// fade out at the end
// col*=vec3(clamp((120.-u_time)*.35, 0., 1.));
return col; return col;
} }
@ -404,13 +401,13 @@ void main()
col *= vec3(.3,0.3,0.3); col *= vec3(.3,0.3,0.3);
} }
else if(mat==1.){ else if(mat==1.){
col *= (noise(5.*(p.xy+2.)+u_time, -1.0) * noise(50.*(p.xy+2.), -0.4) + 0.5*noise(20.*(p.xy+2.0)-u_time, -0.5) * noise(5.*(p.xy+2.0), -0.75))*smoothstep(0.,0.75,(u_time-5.0)*0.1) + vec3(0.,0.,0.5*noise(10.*(p.xy+4.0)-u_time, -0.5)) + vec3(0.,0.,0.5); col *= vec3(0.,0.,0.5); // + (noise(5.*(p.xy+2.)+u_time, -1.0) * noise(50.*(p.xy+2.), -0.4) + 0.5*noise(20.*(p.xy+2.0)-u_time, -0.5) * noise(5.*(p.xy+2.0), -0.75))*smoothstep(0.,0.75,(u_time-5.0)*0.1) + vec3(0.,0.,0.5*noise(10.*(p.xy+4.0)-u_time, -0.5));
} }
else if(mat==2.){ else if(mat==2.){
col *= vec3(0.3608, 0.1765, 0.0471) - 0.2*noise((vec2(100.*p.x+300.,75.*p.z+150.0)), -2.2) * noise((vec2(15.*p.x+2.0,3.*p.z+2.)), -1.) + noise((vec2(15.*p.x+2.4,3.*p.z+2.)), -0.25); col *= vec3(0.3608, 0.1765, 0.0471); // - 0.2*noise((vec2(100.*p.x+300.,75.*p.z+150.0)), -2.2) * noise((vec2(15.*p.x+2.0,3.*p.z+2.)), -1.) + noise((vec2(15.*p.x+2.4,3.*p.z+2.)), -0.25);
} }
else if(mat==3.){ else if(mat==3.){
col *= vec3(0.8471, 0.8549, 0.4667) + noise(p.yz*1000.+5000., 0.1) + noise(p.xy*1000.+5000., 0.1); col *= vec3(0.8471, 0.8549, 0.4667); // + noise(p.xz*1000.+5000., 0.1) + noise(p.xz*1000.+5000., 0.1);
} }
else if(mat==4.){ else if(mat==4.){
col *= vec3(.1,0.1,0.1); col *= vec3(.1,0.1,0.1);

View File

@ -32,19 +32,19 @@ const char *__temp_cleaned_shader_glsl =
"}" "}"
"float m(vec3 y)" "float m(vec3 y)"
"{" "{"
"return n(10.*y.xy+v+999.,.4)+.5*n(10.*(y.xz+2.)-v+999.,.4);" "return n(10.*y.xy+v+999.,.2)+.5*n(10.*(y.xy+2.)-v+999.,.2);"
"}" "}"
"float m(vec3 v,vec3 m,float y)" "float m(vec3 v,vec3 y,vec3 m,float x)"
"{" "{"
"vec3 x=vec3(0),f=m-x,a=v-x;" "vec3 f=m-y,a=v-y;"
"float s=dot(f,f),c=dot(a,f),n=length(a*s-f*c)-y*s,z=abs(c-s*.5)-s*.5,i=n*n,l=z*z*s,d=max(n,z)<0.?" "float i=dot(f,f),c=dot(a,f),s=length(a*i-f*c)-x*i,n=abs(c-i*.5)-i*.5,d=s*s,z=n*n*i,l=max(s,n)<0.?"
"-min(i,l):" "-min(d,z):"
"(n>0.?" "(s>0.?"
"i:" "d:"
"0.)+(z>0.?" "0.)+(n>0.?"
"l:" "z:"
"0.);" "0.);"
"return sign(d)*sqrt(abs(d))/s;" "return sign(l)*sqrt(abs(l))/i;"
"}" "}"
"float m(vec3 v,vec3 y)" "float m(vec3 v,vec3 y)"
"{" "{"
@ -66,171 +66,174 @@ const char *__temp_cleaned_shader_glsl =
"float m=length(v.xy)*sign(-v.y)*f.x,a=abs(v.z)-f.y;" "float m=length(v.xy)*sign(-v.y)*f.x,a=abs(v.z)-f.y;"
"return length(max(vec2(m,a),0.))+min(max(m,a),0.);" "return length(max(vec2(m,a),0.))+min(max(m,a),0.);"
"}" "}"
"float p(float y,float x,float a)" "float m(float y,float x,float a)"
"{" "{"
"float f=(v*a-x)/(2.*acos(-1.));" "float f=(v*a-x)/(2.*acos(-1.));"
"f=min(f,y);" "f=min(f,y);"
"return 2.*acos(-1.)*f;" "return 2.*acos(-1.)*f;"
"}" "}"
"vec3 t(vec3 y)" "float t(float v)"
"{"
"return 9.+9.*clamp(sin(m(2.,v,1.)*.05),-.9,.9);"
"}"
"vec3 h(vec3 y)"
"{" "{"
"float f=9.+9.*clamp(sin(p(2.,0.,1.)*.05),-.9,.9);"
"if(v>=9.)" "if(v>=9.)"
"y.xy=n(f)*y.xy;" "y.xy=n(t(9.))*y.xy;"
"if(v>=14.)" "if(v>=14.)"
"f=9.+9.*clamp(sin(p(2.,14.,1.)*.05),-.9,.9),y.xy=n(f*-1.)*y.xy;" "y.xy=n(t(14.)*-1.)*y.xy;"
"return y;" "return y;"
"}" "}"
"float p(float y,float f)" "float h(float y,float f)"
"{" "{"
"if(v>=f)" "if(v>=f)"
"y+=.045*clamp(sin(p(2.4,f*10.,10.)*.4),-.9,.9);" "y+=.045*clamp(sin(m(2.4,f*10.,10.)*.4),-.9,.9);"
"return y;" "return y;"
"}" "}"
"vec2 a(vec3 f)" "vec2 a(vec3 y)"
"{" "{"
"float y=0.;" "float f=0.;"
"const float x=2.*acos(-1.)/24.;" "const float a=2.*acos(-1.)/24.;"
"float a=floor(atan(f.y,f.x)/x+.5)*x;" "float x=floor(atan(y.y,y.x)/a+.5)*a;"
"vec3 i=f;" "vec3 i=y;"
"i.xy=mat2(cos(a),-sin(a),sin(a),cos(a))*i.xy;" "i.xy=mat2(cos(x),-sin(x),sin(x),cos(x))*i.xy;"
"float s=length(max(abs(i.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02;" "float r=length(max(abs(i.xy-vec2(1.8,0))-vec2(.24,.14),0.))-.02;"
"s=min(s,abs(length(f.xy)-1.8)-.2);" "r=min(r,abs(length(y.xy)-1.8)-.2);"
"float r=abs(length(f.xy)-1.75)-.08;" "float s=abs(length(y.xy)-1.75)-.08;"
"r=n(r,abs(f.z-.1)-.04,.005);" "s=n(s,abs(y.z-.1)-.04,.005);"
"s=max(-r,s);" "r=max(-s,r);"
"s=n(s,abs(f.z)-.1,.02);" "r=n(r,abs(y.z)-.1,.02);"
"float z=1.;" "float l=1.;"
"for(int c=0;c<8;c++)" "for(int c=0;c<8;c++)"
"{" "{"
"vec3 d=f;" "vec3 e=y;"
"float l=24.67/(2.*acos(-1.))+z*(2.*acos(-1.)/8.);" "float z=24.67/(2.*acos(-1.))+l*(2.*acos(-1.)/8.);"
"if(c==1)" "if(c==1)"
"l+=.2;" "z+=.2;"
"if(c==7)" "if(c==7)"
"l-=.2;" "z-=.2;"
"d.xy=n(l)*d.xy;" "e.xy=n(z)*e.xy;"
"if(c>0)" "if(c>0)"
"{" "{"
"d.x-=1.95;" "e.x-=1.95;"
"d.x=p(d.x,float(c));" "e.x=h(e.x,float(c)*13.);"
"float h=p(vec3(d))-.02;" "float d=p(vec3(e))-.02;"
"s=min(s,h);" "r=min(r,d);"
"if(s==h)" "if(r==d)"
"y=4.;" "f=4.;"
"}" "}"
"z+=1.;" "l+=1.;"
"}" "}"
"vec3 d=t(f);" "vec3 c=h(y);"
"float c=2.*acos(-1.)/32.;" "float z=2.*acos(-1.)/32.;"
"vec3 l=d;" "vec3 e=c;"
"l.xy=n(floor(atan(d.y,d.x)/c+.5)*c)*l.xy;" "e.xy=n(floor(atan(c.y,c.x)/z+.5)*z)*e.xy;"
"float h=m(l.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;" "float d=m(e.xyz-vec3(1.75,0,0),vec3(.04,.14,.05))-.02;"
"s=min(s,h);" "r=min(r,d);"
"if(s==h)" "if(r==d)"
"y=4.;" "f=4.;"
"float e=1.5,g=1e3;" "float u=1.5,g=1e3;"
"for(int u=0;u<4;u++)" "for(int t=0;t<4;t++)"
"{" "{"
"float C=m(vec3(f.x,f.y+e,f.z),vec3(2,.1,e))-.05;" "float C=m(vec3(y.x,y.y+u,y.z),vec3(2,.1,u))-.05;"
"g=min(g,C);" "g=min(g,C);"
"s=min(s,C);" "r=min(r,C);"
"e+=.2;" "u+=.2;"
"}" "}"
"float C=1e3;" "float C=y.y+4.25+1.5*n(vec2(y.x*.04,(y.z-40.)*.04)+1e2,15.);"
"if(v>2.)" "C+=n(y.yz,.25);"
"{" "C+=.025*n(y.xz*50.+1e2,.05);"
"float u=m(f,vec3(0,0,-.01),1.6),D=m(f,vec3(0,0,-1),2.-v*2.+26.),b=0.;" "r=min(r,C);"
"if(v>2.)" "float t=1e3,D=m(y,vec3(0),vec3(0,0,-.01),1.6),F=m(y,vec3(0,0,1),vec3(0,0,-1),clamp(2.-v*2.+26.,0.,2.)),G=m(y,vec3(0,0,1),vec3(0,0,-1),1.6),k=0.;"
"b=m(f)*min((v-14.)*.5,.25);" "k=m(y)*clamp((v-14.)*.5,0.,.25);"
"u+=b;" "D+=k;"
"C=max(-D+b,u);" "t=max(-F,D);"
"s=min(s,C);" "t=max(t,G);"
"}" "r=min(r,t);"
"float u=f.y+4.25+n(f.xz*.04+1e2,9.);" "if(r==t)"
"s=min(s,u);" "f=1.;"
"if(s==C)" "else if(r==g)"
"y=1.;" "f=2.;"
"else if(s==min(g,.1))" "else if(r==C)"
"y=2.;" "f=3.;"
"else if(s==u)" "return vec2(r,f);"
"y=3.;"
"return vec2(s,y);"
"}" "}"
"float a(vec3 v,vec3 y)" "float a(vec3 v,vec3 y)"
"{" "{"
"float f=0.,s;" "float f=0.,r;"
"for(int i=0;i<200;i++)" "for(int i=0;i<200;i++)"
"{" "{"
"vec3 m=v+y*f;" "vec3 x=v+y*f;"
"s=a(m).x;" "r=a(x).x;"
"f+=s;" "f+=r;"
"if(abs(s)<.001||f>8e2)" "if(r<.001||f>8e2)"
"break;" "break;"
"}" "}"
"return f;" "return f;"
"}" "}"
"vec3 h(vec3 v)" "vec3 e(vec3 v)"
"{" "{"
"float m=a(v).x;" "float f=a(v).x;"
"vec2 f=vec2(.01,0);" "vec2 y=vec2(.01,0);"
"vec3 y=m-vec3(a(v-f.xyy).x,a(v-f.yxy).x,a(v-f.yyx));" "vec3 r=f-vec3(a(v-y.xyy).x,a(v-y.yxy).x,a(v-y.yyx));"
"return normalize(y);" "return normalize(r);"
"}" "}"
"float a(vec3 v,vec3 f,float y,float m)" "float a(vec3 v,vec3 y,float f,float m)"
"{" "{"
"vec3 s=normalize(f-v),x=h(v);" "vec3 x=normalize(y-v),r=e(v);"
"float i=clamp(dot(x,s),0.,y),c=a(v+x*.0025,s);" "float i=clamp(dot(r,x),0.,f),c=a(v+r*.0025,x);"
"if(c<length(f-v))" "if(c<length(y-v))"
"i*=m;" "i*=m;"
"return i;" "return i;"
"}" "}"
"vec3 h(vec2 v,vec3 y)" "vec3 e(vec2 y,vec3 v)"
"{" "{"
"vec3 f=normalize(vec3(0,-1,0)-y),s=normalize(cross(vec3(0,1,0),f));" "vec3 f=normalize(vec3(0,-1,0)-v),a=normalize(cross(vec3(0,1,0),f));"
"return normalize(f+v.x*s+v.y*cross(f,s));" "return normalize(f+y.x*a+y.y*cross(f,a));"
"}" "}"
"vec3 i(vec3 v)" "vec3 i(vec3 v)"
"{" "{"
"vec2 f=gl_FragCoord.xy/y.xy;"
"v=mix(v,v*smoothstep(.9,.5,length(f-vec2(.5))),.9);"
"v=mix(v,smoothstep(0.,1.,v),.9);" "v=mix(v,smoothstep(0.,1.,v),.9);"
"v*=vec3(1);" "v*=vec3(1);"
"return pow(v,vec3(1./2.2));" "return pow(v,vec3(1./2.2));"
"}" "}"
"vec3 a()"
"{"
"vec3 y=vec3(0,clamp(6.-v,2.,6.),clamp(75.-v*8.,6.,75.));"
"if(v>7.5)"
"y+=vec3(0,clamp(7.5-v,-1.,0.),0);"
"return y;"
"}"
"void main()" "void main()"
"{" "{"
"vec2 f=(gl_FragCoord.xy*2.-y.xy)/y.y;" "vec2 v=(gl_FragCoord.xy*2.-y.xy)/y.y;"
"vec3 s=vec3(0,2,6);" "vec3 f=a(),r=e(v,f),m=vec3(0);"
"s.yz*=n(sin(v)*.5);" "float x=a(f,r);"
"s.xz*=n(cos(v)*.5);" "if(x<5e2)"
"vec3 m=h(f,s),x=vec3(0);"
"float c=a(s,m);"
"if(c<5e2)"
"{" "{"
"vec3 d=s+m*c;" "vec3 c=f+r*x;"
"float l=a(d).y,r=0.;" "float s=a(c).y,t=0.;"
"r=a(d,vec3(-3,5,5),1.,.2);" "t=a(c,vec3(-3,5,5),1.,.2);"
"x+=vec3(r*vec3(.502,.2824,.102));" "m+=vec3(t*vec3(.502,.2824,.102));"
"r=a(d,vec3(3,-2,5),.75,.8);" "t=a(c,vec3(3,-2,5),.75,.8);"
"x+=vec3(r*vec3(.2784,.3647,.6588));" "m+=vec3(t*vec3(.2784,.3647,.6588));"
"vec3 g=h(d);" "vec3 d=e(c);"
"x+=vec3(.1216,.1216,.1137)*clamp(dot(g,normalize(vec3(1,10,1))),0.,1.);" "m+=vec3(.1216,.1216,.1137)*clamp(dot(d,normalize(vec3(1,10,1))),0.,1.);"
"if(l==0.)" "if(s==0.)"
"x*=vec3(.3);" "m*=vec3(.3);"
"else if(l==1.)" "else if(s==1.)"
"x*=(n(5.*(d.xy+2.)+v,-1.)*n(50.*(d.xy+2.),-.4)+.5*n(20.*(d.xy+2.)-v,-.5)*n(5.*(d.xy+2.),-.75))*smoothstep(0.,.75,(v-5.)*.1)+vec3(0,0,.5*n(10.*(d.xy+4.)-v,-.5))+vec3(0,0,.5);" "m*=vec3(0,0,.5);"
"else if(l==2.)" "else if(s==2.)"
"x*=vec3(.3608,.1765,.0471)-.2*n(vec2(1e2*d.x+3e2,75.*d.z+150.),-2.2)*n(vec2(15.*d.x+2.,3.*d.z+2.),-1.)+n(vec2(15.*d.x+2.4,3.*d.z+2.),-.25);" "m*=vec3(.3608,.1765,.0471);"
"else if(l==3.)" "else if(s==3.)"
"x*=vec3(.8471,.8549,.4667)+n(d.yz*1e3,.1)+n(d.xy*1e3,.1);" "m*=vec3(.8471,.8549,.4667);"
"else if(l==4.)" "else if(s==4.)"
"x*=vec3(.1);" "m*=vec3(.1);"
"x=x*exp(-c*.02)+mix(x,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(m,vec3(0,.3,-1)),0.),8.)),1.-exp(-c*.02))*(1.-exp(-c*.02));" "m=m*exp(-x*.02)+mix(m,mix(vec3(.2667,.2941,.3451),vec3(.302,.3176,.3725),pow(max(dot(r,vec3(0,.3,-1)),0.),8.)),1.-exp(-x*.02))*(1.-exp(-x*.02));"
"}" "}"
"else" "else"
" x=vec3(.1529,.1765,.3922)+m.y*.4;" " m=vec3(.1529,.1765,.3922)+r.y*.4;"
"gl_FragColor=vec4(i(x),1);" "gl_FragColor=vec4(i(m),1);"
"}"; "}";
#endif // SHADER_MINIFIED_H_ #endif // SHADER_MINIFIED_H_