final 0.2 - 4094 bytes
This commit is contained in:
68
shader.glsl
68
shader.glsl
@ -9,6 +9,16 @@ uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
const float PI = 22./7.;
|
||||
|
||||
vec3 no(vec3 v)
|
||||
{
|
||||
return normalize(v);
|
||||
}
|
||||
|
||||
float cl(float a, float b, float c)
|
||||
{
|
||||
return clamp(a,b,c);
|
||||
}
|
||||
|
||||
// Rotate
|
||||
mat2 rot2D(float angle) {
|
||||
float s = sin(angle), c = cos(angle);
|
||||
@ -104,7 +114,7 @@ float timedSine(vec3 i) {
|
||||
|
||||
float calcFactor (float startTime)
|
||||
{
|
||||
return STARTDELAY + STARTDELAY*clamp(sin(timedSine(vec3(1.5, startTime, 4.)) * 0.06), -.9, .9);
|
||||
return STARTDELAY + STARTDELAY*cl(sin(timedSine(vec3(1.5, startTime, 4.)) * 0.06), -.9, .9);
|
||||
}
|
||||
|
||||
// Animate ring movements
|
||||
@ -122,7 +132,7 @@ vec3 ringAnim(vec3 p) {
|
||||
// Animate prism movements
|
||||
float prismAnim(vec2 i) {
|
||||
if(u_time >= i.y) {
|
||||
i.x += (.045*clamp(sin((timedSine(vec3(3., i.y, 40.)) * .4)),-.8, .8));
|
||||
i.x += (.045*cl(sin((timedSine(vec3(3., i.y, 40.)) * .4)),-.8, .8));
|
||||
}
|
||||
return i.x;
|
||||
}
|
||||
@ -195,7 +205,7 @@ vec2 map(vec3 p, int displace)
|
||||
vec3 p2 = ringAnim(p), q2=p2;
|
||||
an = PI/16.;
|
||||
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;
|
||||
d2 = sdBox2( q2.xyz - vec3(1.75,0.,0.), vec3(.04, .14, .05) ) - .02 + noise(p.xy*100.,1e-3,0);
|
||||
d = min(d, d2);
|
||||
if (d==d2) mat = 6.;
|
||||
|
||||
@ -203,17 +213,17 @@ vec2 map(vec3 p, int displace)
|
||||
d2 = 1e3;
|
||||
float stepDist = 1.5;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
step = sdBox2(vec3(p.x,p.y+stepDist,p.z), vec3(2., .1,stepDist)) - .05;
|
||||
step = sdBox2(vec3(p.x,p.y+stepDist+0.05,p.z), vec3(2., .2,stepDist)) - .05;
|
||||
d2 = min(d2, step);
|
||||
stepDist += .2;
|
||||
}
|
||||
d2 += noise(p.xz * 50.+200., .01, 0);
|
||||
d2 += noise(p.xz * 50.+200., .01, 0) - noise (p.yz*2.+1.5, 0.15,0);
|
||||
d = min(d, d2*0.7);
|
||||
if (d==d2*0.7) mat = 2.0;
|
||||
|
||||
|
||||
// sand
|
||||
d2 = (p.y + 4.25) + noise((vec2((p.x*.04),(p.z-40.)*.04))+100., 15., 0)*1.5;
|
||||
d2 = (p.y +3.7) + noise((vec2((p.x),(p.z*.44-40.))*.04)+100., 20., 0) + .25*sin(p.z*.5+u_time);
|
||||
d = min(d,d2);
|
||||
if (d==d2) mat = 3.0;
|
||||
|
||||
@ -248,7 +258,7 @@ float rayMarch(vec3 ro, vec3 rd) {
|
||||
for (int i = 0; i < 90; i++) {
|
||||
d = map(ro + rd * t, 0).x; // Get distance to objects
|
||||
t += d; // "march" the ray
|
||||
if (abs(d) < .001 || t > 400.) break;
|
||||
if (d < 1e-3 || t > 400.) break;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@ -258,14 +268,14 @@ vec3 getNormal(vec3 p) {
|
||||
map(p-e.xyy,1).x,
|
||||
map(p-e.yxy,1).x,
|
||||
map(p-e.yyx,1).x);
|
||||
return normalize(n);
|
||||
return no(n);
|
||||
}
|
||||
|
||||
float getLight(vec3 p, vec3 lightPos, float intensity, float shadow, vec3 n) {
|
||||
vec3 l = normalize(lightPos - p);
|
||||
float dif = clamp(dot(n, l), 0., intensity),
|
||||
vec3 l = no(lightPos - p);
|
||||
float dif = cl(dot(n, l), 0., intensity),
|
||||
d = rayMarch(p+n*.0025, l);
|
||||
if(abs(d)<length(lightPos-p)) dif *= shadow;
|
||||
if(d<length(lightPos-p)) dif *= shadow;
|
||||
return dif;
|
||||
}
|
||||
|
||||
@ -295,12 +305,12 @@ vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float b ) {
|
||||
|
||||
vec3 getCameraRayDir(vec2 uv, vec3 p, vec3 l, float z)
|
||||
{
|
||||
vec3 f = normalize(l-p),
|
||||
r = normalize(cross(vec3(0.,1.,0.), f)),
|
||||
vec3 f = no(l-p),
|
||||
r = no(cross(vec3(0.,1.,0.), f)),
|
||||
u = cross(f,r),
|
||||
c = f*z,
|
||||
i = c + uv.x*r + uv.y*u,
|
||||
d = normalize(i);
|
||||
d = no(i);
|
||||
return d;
|
||||
}
|
||||
|
||||
@ -310,12 +320,12 @@ vec3 postProcess(vec3 col) {
|
||||
// Colour mapping
|
||||
col *= vec3(.9, 0.8, 0.7);
|
||||
// gamma
|
||||
col = pow( col, vec3(.4545) );
|
||||
col = pow( col, vec3(.45) );
|
||||
// Contrast = a
|
||||
col = smoothstep(0., 1., col);
|
||||
|
||||
// fade out at the end
|
||||
col += 1.2 - vec3(clamp((32. - u_time)*.35, 0., 1.2));
|
||||
col += 1.2 - vec3(cl((32. - u_time)*.35, 0., 1.2));
|
||||
return col;
|
||||
}
|
||||
|
||||
@ -323,8 +333,8 @@ vec3 cameraPos()
|
||||
{
|
||||
// first zoom in to the gate
|
||||
|
||||
vec3 cPos = vec3(0., clamp(6.-u_time,2.,6.), clamp((75.-u_time*8.),6.,75.));
|
||||
if (u_time > 7.5) cPos += vec3(0., clamp(7.5-u_time,-1.,0.), 0.);
|
||||
vec3 cPos = vec3(0., cl(6.-u_time,2.,6.), cl((100.-u_time*11.),6.,100.));
|
||||
if (u_time > 7.5) cPos += vec3(0., cl(7.5-u_time,-1.,0.), 0.);
|
||||
// close up shot for 1st glyph lock
|
||||
if (u_time > 10.5) cPos = vec3(2.,-1.,1.);
|
||||
// zoom away for 2nd glyph animation
|
||||
@ -332,15 +342,15 @@ vec3 cameraPos()
|
||||
if (u_time > 13.5) {
|
||||
cPos = vec3(0., 0., 4.);
|
||||
cPos.yz *= rot2D(-0.6-(cos(u_time-15.))*0.2);
|
||||
cPos.xz *= rot2D(sin((u_time-16.5)*0.5)*.6);
|
||||
cPos.xz *= rot2D(sin((u_time-16.5)*0.3));
|
||||
}
|
||||
if (u_time > 19.5)
|
||||
{
|
||||
cPos = vec3(3., -.7, 4.);
|
||||
}
|
||||
if (u_time > 22.) {
|
||||
cPos.yz *= rot2D(((1.-cos(u_time-22.))*0.25)*-0.1);
|
||||
cPos.xz *= rot2D(sin((u_time-22.)*0.2)*.6);
|
||||
if (u_time > 21.8) {
|
||||
cPos.yz *= rot2D(((1.-cos(u_time-21.8))*-0.025));
|
||||
cPos.xz *= rot2D(sin((u_time-21.8)*0.07));
|
||||
}
|
||||
|
||||
return cPos;
|
||||
@ -353,11 +363,7 @@ vec3 cameraPointAt() {
|
||||
// look gate at distance
|
||||
if(u_time > 12.) p = vec3(0.);
|
||||
if(u_time > 13.5) {
|
||||
p = mix(glyph3Pos,glyph4Pos, (u_time-13.5)*0.3);
|
||||
}
|
||||
if(u_time > 16.8)
|
||||
{
|
||||
p = mix(glyph4Pos,glyph5Pos, clamp((u_time-16.8)*0.3,0.,1.));
|
||||
p = mix(glyph3Pos,glyph5Pos, (u_time-13.5)*0.13);
|
||||
}
|
||||
if(u_time > 19.5) p = vec3(0.);
|
||||
return p;
|
||||
@ -374,14 +380,14 @@ vec3 colorFlashesAnim(vec3 col) {
|
||||
|
||||
vec3 addSpecular(vec3 nor, vec3 rod, float amount, float phong)
|
||||
{
|
||||
return vec3(specular(nor,normalize(vec3(0.0,0.3,0.8)),normalize(rod),pow(10.,phong)))*amount;
|
||||
return vec3(specular(nor,no(vec3(0.0,0.3,0.8)),no(rod),pow(10.,phong)))*amount;
|
||||
}
|
||||
|
||||
vec3 sceneGate(vec2 uv)
|
||||
{
|
||||
// Initialization
|
||||
vec3 ro = cameraPos(),
|
||||
rd = getCameraRayDir(uv, ro, cameraPointAt(), clamp((25.-u_time)*-1.,2.,25.)),
|
||||
rd = getCameraRayDir(uv, ro, cameraPointAt(), cl((28.-u_time)*-2.,2.,25.)),
|
||||
col = vec3(0.);
|
||||
float d = rayMarch(ro, rd);
|
||||
|
||||
@ -405,12 +411,12 @@ vec3 sceneGate(vec2 uv)
|
||||
col += dif * light2Color;
|
||||
|
||||
// indirect lightning -> vec3 in normalize is light direction
|
||||
col += indirColor * clamp( dot( n, normalize(vec3(0. , 1., 10.))), 0., 1.);
|
||||
col += indirColor * cl( dot( n, no(vec3(0. , 1., 10.))), 0., 1.);
|
||||
|
||||
if(mat==0.)
|
||||
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 = getSeaColor(p, n, no(vec3(0.0,0.3,0.8)),no(rd));
|
||||
if(mat==2.)
|
||||
col *= vec3(.8, .8, .5);
|
||||
if(mat==3.)
|
||||
|
||||
Reference in New Issue
Block a user