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);