lisäyksiä

This commit is contained in:
Teemu Järvisalo
2024-07-27 00:18:28 +03:00
parent a7eed4cefb
commit fa12676bee
2 changed files with 220 additions and 146 deletions

View File

@ -102,18 +102,29 @@ float sdTriPrism( vec3 p, vec2 h, float rot )
// ANIMATION //
//////////////////
const float TWOPI = 6.28318530718;
vec3 lookAtPoint = vec3(0, -1., 0.);
// Rotate ring with duration d and startTime s
float ringRotateFunc(float maxCycles, float startTime, float timeFact) {
float phase = ((u_time * timeFact) - startTime) / TWOPI;
phase = min(phase, maxCycles);
return TWOPI * phase;
const vec3 glyph1Pos = vec3(1.7,-1.1,0.0);
const vec3 glyph2Pos = vec3(2.0,0.0,0.0);
const vec3 glyph3Pos = vec3(1.5,1.4,0.0);
const vec3 glyph4Pos = vec3(0.0,2.0,0.0);
const vec3 glyph5Pos = vec3(1.5,1.4,0.0);
const vec3 glyph6Pos = vec3(1.5 * -1.,1.4,0.0);
const vec3 glyph7Pos = vec3(1.7 * -1.,-1.1,0.0);
// with duration d, startTime s and speed up with timeFact
float timedSine(float maxCycles, float startTime, float timeFact) {
float pi = TWOPI / 2.0;
startTime *= timeFact;
float phase = ((u_time * timeFact) - startTime) / pi;
phase = min(phase, maxCycles);
return pi * 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);
float factor = 9.0 + 9.0*clamp(sin(timedSine(2.0, startTime, 2.5) * 0.05), -0.9, 0.9);
return factor;
}
@ -129,9 +140,9 @@ vec3 ringAnim( in vec3 p) {
p.xy = rot2D(calcFactor(STARTDELAY)) * p.xy;
}
if(u_time >= OTHERDELAY) {
p.xy = rot2D(calcFactor(OTHERDELAY) * -1.0) * p.xy;
}
// if(u_time >= OTHERDELAY) {
// p.xy = rot2D(calcFactor(OTHERDELAY) * -1.0) * p.xy;
// }
return p;
}
@ -139,12 +150,11 @@ vec3 ringAnim( in vec3 p) {
// Animate prism movements
float prismAnim(in float x, in float delay) {
if(u_time >= delay) {
x += (0.045*clamp(sin((ringRotateFunc(2.4, delay*10.0, 10.0) * 0.4)),-0.9, 0.9));
x += (0.045*clamp(sin((timedSine(2.0, delay, 10.0) * 0.4)),-0.9, 0.9));
}
return x;
}
//////////////
// SCENE //
//////////////
@ -197,14 +207,25 @@ vec2 map(in vec3 p)
// We can now call each prism by it's index
// draw all except the middle bottom prism
if (i > 0) {
q.x -= 1.95;
q.x = prismAnim(q.x, float(i)*13.);
q.x -= 1.95;
vec3 q2 = q;
q2.x = prismAnim(q2.x, float(i)*13.);
float d4 = sdTriPrism(vec3(q.x, q.y - 0.0 , q.z - 0.0), vec2(0.2,0.2), 0.5) - 0.02;
float prismOut = sdTriPrism(vec3(q2.x - 0.14, q2.y - 0.0 , q2.z), vec2(0.22,0.22), 0.5) - 0.01;
float prismIn = sdTriPrism(vec3(q2.x, q2.y, q2.z ), vec2(0.2,0.12), 0.5) - 0.02;
float prismTop = sdTriPrism(vec3(q.x - 0.06, q.y, q.z), vec2(0.10,0.15), 0.5) - 0.01;
//float d4 = sdTriPrism(vec3(q.x, q.y - 0.0 , q.z - 0.0), vec2(0.2,0.2), 0.5) - 0.02;
float d4 = max(-prismOut, prismIn);
d4 = min(d4, prismTop);
d = min(d, d4);
if (d==d4) {
mat = 4.;
}
if(d==prismTop) {
if(u_time > 13.5 && i == 1) {
mat = 5.;
}
}
}
index += 1.0;
@ -353,9 +374,44 @@ vec3 cameraPos()
{
cPos += vec3(0, clamp(7.5-u_time,-1.,0.), 0.);
}
if (u_time > 12.) {
cPos = vec3(2.0,-1.0,1.0);
}
return cPos;
}
vec3 cameraPointAt(vec3 p) {
if(u_time > 12.) {
p = glyph1Pos;
}
return p;
}
// flash screen with glyph color when it is locked
vec3 colorFlashesAnim(in vec3 col) {
vec3 flashColor = vec3(0.95, 0.35, 0.06);
float delay = 13.2;
if(u_time > delay) {
float x = smoothstep(-1.0,0.8,sin((timedSine(0.38, delay*2.0, 2.0)*2.0)));
col = mix(col, flashColor * (x * 1.4), x * 0.76);
}
return col;
}
// zoom camera on glyph lock for extra oomph
float cameraZoomAnim(float o) {
float delay = 13.0;
if(u_time > delay) {
o -= smoothstep(-0.7,0.5,sin((timedSine(0.4, delay, 1.0)*2.0))) * 0.2;
}
return o;
}
void main()
{
// Initialization
@ -363,11 +419,13 @@ void main()
vec3 ro = cameraPos();
vec3 rd = getCameraRayDir(uv, ro, vec3(0, -1., 0.), 1.); // ray direction
vec3 rd = getCameraRayDir(uv, ro, cameraPointAt(lookAtPoint), 1.); // ray direction
vec3 col = vec3(0); // color
float d = rayMarch(ro, rd);
// ro.z = cameraZoomAnim(ro.z);
if (d < 500.) {
// Lighting
vec3 p = ro + rd * d;
@ -411,11 +469,15 @@ void main()
}
else if(mat==4.){
col *= vec3(.1,0.1,0.1);
} else if(mat ==5.) {
col *= vec3(0.95, 0.35, 0.06);
}
float fogAmount = 0.02;
col = col*exp(-d*fogAmount) + applyFog(col, d, rd, vec3(0., .3, -1.), fogAmount) * (1.0-exp(-d*fogAmount));
// col = colorFlashesAnim(col); // animated color flash
} else {
col = vec3(0.1529, 0.1765, 0.3922) + rd.y * 0.4;
}