animaatiot ja värit

This commit is contained in:
Teemu Järvisalo
2024-07-28 19:17:28 +03:00
parent 0f6b4dd3e1
commit 8f7befa8db
2 changed files with 201 additions and 174 deletions

View File

@ -102,8 +102,9 @@ float sdTriPrism( vec3 p, vec2 h, float rot )
// ANIMATION //
//////////////////
const float TWOPI = 6.28318530718;
vec3 lookAtPoint = vec3(0, -0.5, 0.);
// POSITIONS
vec3 lookAtPoint = vec3(0, -0.5, 0.);
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);
@ -112,6 +113,21 @@ 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);
// DELAYS
const float STARTDELAY = 9.0;
const float glyphPhase = 2.0;
// COLORS
vec3 glyphColor = vec3(0.95, 0.35, 0.06); // glyph color
vec3 color1 = vec3(0.44, 0.29, 0.46); // fog color1
vec3 color2 = vec3(0.75, 0.45, 0.23); // fog color2
vec3 color3 = vec3(0.29, 0.17, 0.35); // indirect light color
vec3 color4 = vec3(0.7, 0.27, 0.09); // sky color1
vec3 color5 = vec3(0.09, 0.05, 0.66); // sky color2
vec3 light1Color = vec3(0.91, 0.57, 0.73);
vec3 light2Color = vec3(0.83, 0.71, 0.54);
// with duration d, startTime s and speed up with timeFact
float timedSine(float maxCycles, float startTime, float timeFact) {
float pi = TWOPI / 2.0;
@ -123,31 +139,29 @@ float timedSine(float maxCycles, float startTime, float timeFact) {
float calcFactor (float startTime)
{
float factor = 9.0 + 9.0*clamp(sin(timedSine(2.0, startTime, 2.5) * 0.05), -0.9, 0.9);
float factor = 9.0 + 9.0*clamp(sin(timedSine(1.5, startTime, 4.0) * 0.06), -0.9, 0.9);
return factor;
}
// Animate ring movements
vec3 ringAnim( in vec3 p) {
const float STARTDELAY = 9.0;
const float OTHERDELAY = 15.0;
// delay start
if( u_time >= STARTDELAY ) {
p.xy = rot2D(calcFactor(STARTDELAY)) * p.xy;
for (float i = 0.0; i<7.0; i++) {
float rotateDelay = STARTDELAY + (i * glyphPhase);
if(u_time > rotateDelay) {
if(mod(i,2.0) >= 1.0) {
p.xy = rot2D(calcFactor(rotateDelay) * -1.0) * p.xy;
} else {
p.xy = rot2D(calcFactor(rotateDelay)) * p.xy;
}
}
}
if(u_time >= OTHERDELAY) {
p.xy = rot2D(calcFactor(OTHERDELAY) * -1.0) * p.xy;
}
return p;
}
// Animate prism movements
float prismAnim(in float x, in float delay) {
if(u_time >= delay && u_time <= delay + 1.0) {
x += (0.045*clamp(sin((timedSine(3.0, delay, 20.0) * 0.4)),-0.8, 0.8));
if(u_time >= delay) {
x += (0.045*clamp(sin((timedSine(3.0, delay, 40.0) * 0.4)),-0.8, 0.8));
}
return x;
}
@ -201,26 +215,33 @@ vec2 map(in vec3 p)
q.xy = rot2D(rotationIncrement) * q.xy;
float rotateDelay = STARTDELAY + ((index - 2.0) * glyphPhase + 1.5);
// We can now call each prism by it's index
// draw all except the middle bottom prism
if (i > 0) {
q.x -= 1.95;
vec3 q2 = q;
q2.x = prismAnim(q2.x, float(i)*13.);
vec3 q2 = q; // new point for movable parts
if(u_time > rotateDelay) {
q2.x = prismAnim(q2.x, rotateDelay);
}
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) {
// glyph locking thing material
if (d == d4) {
mat = 4.;
}
if(d==prismTop) {
if(u_time > 13.5 && i == 1) {
mat = 5.;
// glyph locking prism material
if(d == prismTop) {
if(u_time > rotateDelay + 0.2) {
mat = 5.;
}
}
}
@ -261,10 +282,10 @@ vec2 map(in vec3 p)
float water = 1000.;
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 cylinder2 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1), clamp((2.0 - (u_time*2.0 - 2.0*23.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);
disp = displacement(p)*clamp(((u_time-24.0)*0.5), 0., 0.25);
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
@ -293,11 +314,11 @@ float rayMarch(vec3 ro, vec3 rd) {
float t = 0.; // total distance travelled
float d;
// Raymarching
for (int i = 0; i < 200; i++) {
for (int i = 0; i < 100; i++) {
vec3 p = ro + rd * t; // "cast" rays
d = map(p).x; // Get distance to objects
t += d; // "march" the ray
if (d < .001 || t > 800.) break;
if (d < .001 || t > 500.) break;
}
return t;
}
@ -326,8 +347,8 @@ float getLight(vec3 p, vec3 lightPos, float intensity, float shadow) {
vec3 applyFog(vec3 col, float t, vec3 rd, vec3 lightDir, float b ) {
float fogAmount = 1.0 - exp(-t*b);
float sunAmount = max( dot(rd, lightDir), 0.0 );
vec3 fogColor = mix( vec3(0.2667, 0.2941, 0.3451), // blue
vec3(0.302, 0.3176, 0.3725), // yellow
vec3 fogColor = mix( color1, // blue
color2, // yellow
pow(sunAmount,8.0) );
return mix( col, fogColor, fogAmount );
}
@ -366,9 +387,10 @@ vec3 postProcess(vec3 col) {
// zoom camera on glyph lock for extra oomph
float cameraZoomAnim(float o) {
float delay = 13.45;
float delay = 11.2;
if(u_time > delay) {
o -= (0.25 - smoothstep(-0.7,0.5,sin((timedSine(1.5, delay, 8.0))))) * 0.2;
o += (0.25 - smoothstep(-0.7,0.5,sin((timedSine(1.5, delay, 35.0))))) * 0.1;
}
return o;
@ -384,12 +406,12 @@ vec3 cameraPos()
}
// close up shot for 1st glyph lock
if (u_time > 12.) {
if (u_time > 10.5) {
cPos = vec3(2.0,-1.0,1.0);
}
//zoom away for 2nd glyph animation
if (u_time > 15.) {
if (u_time > 12.) {
cPos = vec3(-1.0, -1.0, 4.0);
}
@ -403,11 +425,11 @@ vec3 cameraPos()
vec3 cameraPointAt(vec3 p) {
// look at 1st glyph
if(u_time > 12.) {
if(u_time > 10.5) {
p = glyph1Pos;
}
if(u_time > 15.) {
if(u_time > 12.) {
p = vec3(0.0,0.1,0.0);
}
@ -416,11 +438,11 @@ vec3 cameraPointAt(vec3 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.5;
float delay = 11.25;
if(u_time > delay) {
float x = smoothstep(-1.0,0.8,sin((timedSine(0.8, delay, 8.0)*2.0)));
col = mix(col, flashColor * (x * 1.4), x * 0.76);
col = mix(col, glyphColor * (x * 1.4), x * 0.76);
}
return col;
}
@ -455,16 +477,16 @@ void main()
// Light 2
dif = getLight(p, vec3( -3, 5, 5), 1., 0.2);
// Color for light 2
col += vec3(dif * vec3(0.502, 0.2824, 0.102));
col += vec3(dif * light1Color);
dif = getLight(p, vec3( 3, -2, 5), 0.75, .8);
// Color for light 2
col += vec3(dif * vec3(0.2784, 0.3647, 0.6588));
col += vec3(dif * light2Color);
vec3 n = getNormal(p);
vec3 dir = vec3(1. , 10., 1.);
float ind = clamp( dot( n, normalize(dir )), 0.0, 1.0 );
col += vec3(0.1216, 0.1216, 0.1137) * ind;
col += color3 * ind;
if(mat==0.){
col *= vec3(.3,0.3,0.3);
@ -481,16 +503,14 @@ 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);
col *= glyphColor; // activated glyph color
}
float fogAmount = 0.02;
col = col*exp(-d*fogAmount) + applyFog(col, d, rd, vec3(0., .3, -1.), fogAmount) * (1.0-exp(-d*fogAmount));
} else {
col = vec3(0.1529, 0.1765, 0.3922) + rd.y * 0.4;
col = mix(color4, color5, rd.y * 1.2);
}
col = colorFlashesAnim(col); // animated color flash