värit ja materiaalit

This commit is contained in:
Teemu Järvisalo
2024-07-29 22:53:43 +03:00
parent 719e6d367d
commit 6c6de97a23
3 changed files with 142 additions and 141 deletions

View File

@ -4,7 +4,7 @@
* Contact: tdmaav@gmail.com
*/
precision mediump float;
// precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;
const float PI = 22./7.;
@ -90,14 +90,14 @@ float STARTDELAY = 9.;
// COLORS
vec3 fogColor1 = vec3(.4, .2, .4), // fog color1
fogColor2 = vec3(.7, .4, .2), // fog color2
indirColor = vec3(.2, .1, .3), // indirect light color
light1Color = vec3(.9, .5, .7),
light2Color = vec3(.8, .7, .5),
vec3 fogColor1 = vec3(0.49, 0.18, 0.49), // fog color1
fogColor2 = vec3(0.93, 0.37, 0.16), // fog color2
indirColor = vec3(0.29, 0.28, 0.33), // indirect light color
light1Color = vec3(0.82, 0.5, 0.9),
light2Color = vec3(0.79, 0.66, 0.43),
chevronColor = vec3(.9, .3, 0.),
SEA_BASE = vec3(0.0, 0.1, 0.2),
SEA_WATER_COLOR =vec3(0.4,0.5,0.3);
SEA_BASE = vec3(0.0, 0.1, 0.3),
SEA_WATER_COLOR =vec3(0.11, 0.16, 0.18);
// with duration d, startTime s and speed up with timeFact
@ -148,8 +148,7 @@ vec2 map(vec3 p, int displace)
an = PI/12.,
anRot = floor(atan(p.y,p.x)/an + .5)*an;
vec3 q = p;
q.xy = mat2(cos(anRot),-sin(anRot),
sin(anRot), cos(anRot))*q.xy;
q.xy = rot2D(anRot)*q.xy;
float d = length(max(abs(q.xy - vec2(1.8,0.))-vec2(0.24,0.14),0.)) - .02,
// Main ring
@ -200,7 +199,7 @@ vec2 map(vec3 p, int displace)
q2.xy = rot2D(floor((atan(p2.y,p2.x)/an) + .5)*an)*q2.xy;
d2 = sdBox2( q2.xyz - vec3(1.75,0.,0.), vec3(.04, .14, .05) ) - .02;
d = min(d, d2);
if (d==d2) mat = 4.;
if (d==d2) mat = 6.;
// Gate Base
d2 = 1e3;
@ -281,12 +280,8 @@ float specular(vec3 normal,vec3 lightPos,vec3 rayOrigin,float specular) {
}
vec3 getSeaColor(vec3 p, vec3 n, vec3 l, vec3 eye) {
float fresnel = clamp(1.0 - dot(n,-eye), 0.0, 1.0);
fresnel = min(pow(fresnel,5.0), 0.5);
vec3 reflected = vec3(0.0, 0.5, 1.),
refracted = SEA_BASE + diffuse(n,l,60.0) * SEA_WATER_COLOR * 0.3,
color = mix(refracted,reflected,fresnel);
color += vec3(specular(n,l,eye,60.0))*0.3;
vec3 color = SEA_BASE + diffuse(n,l,60.0) * SEA_WATER_COLOR * 0.3;
color += vec3(specular(n,l,eye,60.0))*0.2;
return color;
}
@ -355,9 +350,9 @@ vec3 colorFlashesAnim(vec3 col) {
return col;
}
vec3 addSpecular(vec3 nor, vec3 rod, float amount)
vec3 addSpecular(vec3 nor, vec3 rod, float amount, float phong)
{
return vec3(specular(nor,normalize(vec3(0.0,0.3,0.8)),normalize(rod),60.0))*amount;
return vec3(specular(nor,normalize(vec3(0.0,0.3,0.8)),normalize(rod),pow(10.,phong)))*amount;
}
vec3 sceneGate(vec2 uv)
@ -389,19 +384,22 @@ vec3 sceneGate(vec2 uv)
// indirect lightning -> vec3 in normalize is light direction
col += indirColor * clamp( dot( n, normalize(vec3(0. , 1., 10.))), 0., 1.);
if(mat==0.)
col *= vec3(.3) + addSpecular(n,rd,0.5);
col *= vec3(0.21, 0.35, 0.33) + addSpecular(n,rd,.5, 2.);
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));
if(mat==2.)
col *= vec3(.3, .1, .0)+ addSpecular(n,rd,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);
col *= vec3(.8, .8, .5) + addSpecular(n,rd,.1,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);
if(mat==3.)
col *= vec3(.8, .8, .5) + noise(p.xz*500.+1e5, .3,0); // + noise(p.xz*1000.+5000., 0.1) + noise(p.xz*1000.+5000., 0.1);
if(mat==4.)
col *= vec3(.1)+ addSpecular(n,rd,0.5);
col *= vec3(0.0, 0.08, 0.11) + addSpecular(n,rd,0.3,0.7);
if(mat ==5.)
col *= chevronColor; // activated glyph color
if(mat == 6.) {
col *= vec3(0.01, 0.04, 0.06) + addSpecular(n,rd,.1, 2.5);
}
}
col = applyFog(col, d, rd, vec3(0., -.1, -1.), .01);