Add specular to materials

This commit is contained in:
2024-07-29 17:22:13 +03:00
parent ba77e88342
commit 7fbe712d53

View File

@ -4,7 +4,7 @@
* Contact: tdmaav@gmail.com * Contact: tdmaav@gmail.com
*/ */
precision mediump float; //precision mediump float;
uniform vec2 u_resolution; uniform vec2 u_resolution;
uniform float u_time; uniform float u_time;
const float PI = 22./7.; const float PI = 22./7.;
@ -238,11 +238,7 @@ vec2 map(vec3 p, int displace)
} }
} }
float cs = sdCappedCylinder(p, .025, 1.6) - h*0.15; float cs = sdCappedCylinder(p, .025, 1.6) - h*0.15;
if (u_time < 25.) { d2 = max(-sdCappedCylinder(p, 2.0, clamp((2.0 - (u_time*3.0 - 3.0*23.0)),0.,2.3)), cs);
d2 = max(-sdCappedCylinder(p, 2.0, clamp((2.0 - (u_time*2.0 - 2.0*23.0)),0.,2.3)), cs);
} else {
d2 = cs;
}
d2 = max(d2, sdCappedCylinder ( p, 0.3, 1.7)); d2 = max(d2, sdCappedCylinder ( p, 0.3, 1.7));
d = min(d, d2); d = min(d, d2);
if (d==d2) mat = 1.0; if (d==d2) mat = 1.0;
@ -260,7 +256,7 @@ float rayMarch(vec3 ro, vec3 rd) {
for (int i = 0; i < 90; i++) { for (int i = 0; i < 90; i++) {
d = map(ro + rd * t, 0).x; // Get distance to objects d = map(ro + rd * t, 0).x; // Get distance to objects
t += d; // "march" the ray t += d; // "march" the ray
if (abs(d) < .002 || t > 400.) break; if (abs(d) < .001 || t > 400.) break;
} }
return t; return t;
} }
@ -322,7 +318,7 @@ vec3 getCameraRayDir(vec2 uv, vec3 p, vec3 l, float z)
vec3 postProcess(vec3 col) { vec3 postProcess(vec3 col) {
// Vignette // Vignette
col *= smoothstep(0.9, 0.5, length(gl_FragCoord.xy/u_resolution.xy-vec2(.5))); //col *= smoothstep(0.9, 0.5, length(gl_FragCoord.xy/u_resolution.xy-vec2(.5)));
// Colour mapping // Colour mapping
col *= vec3(.9, 0.8, 0.7); col *= vec3(.9, 0.8, 0.7);
// gamma // gamma
@ -342,13 +338,6 @@ vec3 cameraPos()
// zoom away for 2nd glyph animation // zoom away for 2nd glyph animation
if (u_time > 12.) cPos = vec3(-1., -1., 4.); if (u_time > 12.) cPos = vec3(-1., -1., 4.);
//close up shot for the 2nd glyph lock
// !NOTE: disabled by petri due takes alot of space and has small visual impact on the scene
/*
float delay = 11.2;
if(u_time > delay) cPos.z += (0.25 - smoothstep(-0.7,0.5,sin((timedSine(1.5, delay, 35.0))))) * 0.1;
*/
return cPos; return cPos;
} }
@ -401,16 +390,16 @@ vec3 sceneGate(vec2 uv)
col += indirColor * clamp( dot( n, normalize(vec3(0. , 1., 10.))), 0., 1.); col += indirColor * clamp( dot( n, normalize(vec3(0. , 1., 10.))), 0., 1.);
if(mat==0.) if(mat==0.)
col *= vec3(.3); col *= vec3(.3) + vec3(specular(n,normalize(vec3(0.0,0.3,0.8)),normalize(rd),60.0))*0.5;
else if(mat==1.){ else if(mat==1.){
col = getSeaColor(p, n, normalize(vec3(0.0,0.3,0.8)),normalize(rd)); //col = vec3(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)); col = getSeaColor(p, n, normalize(vec3(0.0,0.3,0.8)),normalize(rd)); //col = vec3(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(.3, .1, .0); // - 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(.3, .1, .0)+ vec3(specular(n,normalize(vec3(0.0,0.3,0.8)),normalize(rd),60.0))*0.1; // - 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(.8, .8, .5) + noise(p.xz*500.+100., .3,0); // + noise(p.xz*1000.+5000., 0.1) + noise(p.xz*1000.+5000., 0.1); col *= vec3(.8, .8, .5) + noise(p.xz*500.+100., .3,0); // + 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); col *= vec3(.1)+ vec3(specular(n,normalize(vec3(0.0,0.3,0.8)),normalize(rd),60.0))*0.5;
else if(mat ==5.) else if(mat ==5.)
col *= chevronColor; // activated glyph color col *= chevronColor; // activated glyph color