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;
// Rotate ring with duration d and startTime s
float ringRotateFunc(float d, float s, float timeFact) {
float maxCycles = d;
float startTime = s;
float ringRotateFunc(float maxCycles, float startTime, float timeFact) {
float phase = ((u_time * timeFact) - startTime) / TWOPI;
phase = min(phase, maxCycles);
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
vec3 ringAnim( in vec3 p) {
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
if( u_time >= STARTDELAY ) {
p.xy = rot2D(factor) * p.xy;
p.xy = rot2D(calcFactor(STARTDELAY)) * p.xy;
}
if(u_time >= 14.0) {
factor = 9.0+9.0*clamp(sin(ringRotateFunc(2.0, 14.0, 1.0) * 0.05), -0.9, 0.9);
p.xy = rot2D(factor * -1.0) * p.xy;
if(u_time >= OTHERDELAY) {
p.xy = rot2D(calcFactor(OTHERDELAY) * -1.0) * p.xy;
}
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.);
sand += noise(p.yz, .25);
sand += 0.025*noise(p.xz*50.+100., .05);
d = min(d,sand);
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 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 disp = 0.;
disp = displacement(p)*clamp(((u_time-14.0)*0.5), 0., 0.25);
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
d = min(d, water);
}
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 cylinder3 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1.), 1.6);
float disp = 0.;
disp = displacement(p)*clamp(((u_time-14.0)*0.5), 0., 0.25);
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
d = min(d, water);
if (d==water)
{
@ -321,17 +327,14 @@ vec3 getCameraRayDir(vec2 uv, vec3 p, vec3 l, float z)
}
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)
vec2 screenCoord = gl_FragCoord.xy/u_resolution.xy;
// Vignette
float radius = 0.9;
float d = smoothstep(radius, radius-0.4, length(screenCoord-vec2(0.5)));
col = mix(col, col * d, .9);
//float radius = 0.9;
//float d = smoothstep(radius, radius-0.4, length(screenCoord-vec2(0.5)));
//col = mix(col, col * d, .9);
// Contrast = a
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 = 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;
}
@ -404,13 +401,13 @@ void main()
col *= vec3(.3,0.3,0.3);
}
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.){
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.){
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.){
col *= vec3(.1,0.1,0.1);

View File

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