glow toimii!! final size: 4076

This commit is contained in:
2024-07-31 03:26:05 +03:00
parent d184eba529
commit 5db872e091
3 changed files with 238 additions and 276 deletions

View File

@ -9,15 +9,8 @@ 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);
}
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) {
@ -37,7 +30,7 @@ float hash(vec2 p, int algo)
float h = dot(p,vec2(127.1,311.7));
return fract(sin(h)*43758.5453123);
}
p = 50.*fract( p*0.3183099);
p = 50. * fract( p*0.3183099);
return fract( p.x*p.y*(p.x+p.y) );
}
@ -57,9 +50,9 @@ float noise(vec2 p, float scale, int a)
/////////////////
// GEOMETRY //
/////////////////
float sdSphere(vec3 p, float r) {
/*float sdSphere(vec3 p, float r) {
return length(p)-r;
}
}*/
float sdCappedCylinder( vec3 p, float h, float r )
{
@ -87,22 +80,24 @@ float sdTriPrism( vec3 p, vec2 h, float rot )
// POSITIONS
//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 glyph4Pos = vec3(0.0,2.0,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
float STARTDELAY = 9.;
float STARTDELAY = 9., glow = 0.;
// COLORS
vec3 fogColor1 = vec3(0.49, 0.18, 0.49), // fog color1
vec3
glyph3Pos = vec3(1.5,1.4,0.0),
glyph5Pos = vec3(-1.5,1.4,0.0),
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.),
chevronColor = vec3(0.46, 0.0, 0.9),
SEA_BASE = vec3(0.0, 0.1, 0.3),
SEA_WATER_COLOR =vec3(0.11, 0.16, 0.18);
@ -148,9 +143,9 @@ float sea_octave(vec2 uv, float choppy) {
return pow(1.0-pow(wv.x * wv.y,0.65),choppy);
}
vec2 map(vec3 p, int displace)
vec3 map(vec3 p, int displace)
{
float mat = 0.,
float mat = 0., glo = 1e3,
// Ring boxes
an = PI/12.,
step,
@ -171,67 +166,25 @@ vec2 map(vec3 p, int displace)
// Depth slice rings
d = smax( d, abs(p.z)-.1, .02 );
// Prisms
for(float i = 0.; i < 8.; i++ ) {
an = 24.67 / (PI * 2.); // sector size
q = p;
anRot = an + (i+1.) * PI / 4.;
// Nudge first and the last prism out of the ground
if (i == 1.) anRot += .2;
if (i == 7.) anRot -= .2;
q.xy = rot2D(anRot) * q.xy;
float rotateDelay = STARTDELAY + (i - 1.) * 2. + 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; // new point for movable parts
if(u_time > rotateDelay) q2.x = prismAnim(vec2(q2.x, rotateDelay));
float prismTop = sdTriPrism(vec3(q.x - .06, q.y, q.z), vec2(.1,.15), .5)-.01;
d2 = max(- sdTriPrism(vec3(q2.x - .14, q2.y - 0. , q2.z), vec2(.22,.22), .5) - .01 , sdTriPrism(vec3(q2.x, q2.y, q2.z ), vec2(.2,.12), .5) - .02);
d2 = min(d2, prismTop);
d = min(d, d2);
// glyph locking thing material
if (d == d2) mat = 4.;
// glyph locking prism material
if( d == prismTop && u_time > rotateDelay + .2) mat = 5.;
}
}
d2 =sdSphere(p-vec3(0.,0.,0.), 1.0);
d=min(d, d2);
if (d == d2) mat = 5.;
//Rotating glyphs
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 + noise(p.xy*100.,1e-3,0);
d2 = sdBox2( q2.xyz - vec3(1.75,0.,0.), vec3(.04, .14, .05) ) - .02;
d = min(d, d2);
if (d==d2) mat = 6.;
// Gate Base
d2 = 1e3;
float stepDist = 1.5;
float stepDist = 1.5, h = 0.0, d3, choppy=4., freq=0.6, amp=.2;
for(int i = 0; i < 4; i++) {
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) - 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 +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;
d2 = 1e3;
float h = 0.0, d3, choppy=4., freq=0.6, amp=.2;
d2 += noise(p.xz * 50.+200., .01, 0); // - noise (p.yz*2.+1.5, 0.15,0);
d = min(d, d2);
if (d==d2) mat = 2.0;
if (displace == 1) {
vec2 uv = p.xy;
@ -246,22 +199,61 @@ vec2 map(vec3 p, int displace)
d2 = max(-sdCappedCylinder(p, 2.0, min((2.0 - (u_time - 23.0)*3.),2.3)), sdCappedCylinder(p, .025, 1.6) - h*0.15);
d2 = max(d2, sdCappedCylinder ( p, 0.3, 1.7));
d = min(d, d2);
if (d==d2) mat = 1.0;
if (d==d2) {
mat = 1.0;
}
return vec2( d, mat );
// sand
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;
// Prisms
for(float i = 0.; i < 8.; i++ ) {
an = 24.67 / (PI * 2.); // sector size
q = p;
anRot = an + (i+1.) * PI / 4.;
// Nudge first and the last prism out of the ground
if (i == 1.) anRot += .2;
if (i == 7.) anRot -= .2;
q.xy = rot2D(anRot) * q.xy;
float rotateDelay = STARTDELAY + (i - 1.) * 2. + 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; // new point for movable parts
if(u_time > rotateDelay) q2.x = prismAnim(vec2(q2.x, rotateDelay));
float prismTop = sdTriPrism(vec3(q.x - .06, q.y, q.z), vec2(.1,.15), .5) -.01;
d2 = max(-sdTriPrism(vec3(q2.x - .14, q2.y - 0. , q2.z), vec2(.22), .5) - .01 , sdTriPrism(vec3(q2.x, q2.y, q2.z ), vec2(.2,.12), .5) - .02);
d2 = min(d2, prismTop);
d = min(d, d2);
// glyph locking thing material
if (d == d2) mat = 4.;
// glyph locking prism material
if( d == prismTop) if(u_time > rotateDelay + .2) {
mat = 5.;
glo = prismTop;
}
}
}
return vec3( d, mat, glo);
}
////////////////
// DRAWING //
////////////////
float rayMarch(vec3 ro, vec3 rd) {
float rayMarch(vec3 ro, vec3 rd, int a) {
float d,t = 0.; // total distance travelled
// Raymarching
for (int i = 0; i < 90; i++) {
for (int i = 0; i < 100; i++) {
d = map(ro + rd * t, 0).x; // Get distance to objects
t += d; // "march" the ray
if (d < 1e-3 || t > 400.) break;
if (a==0) glow += 0.03/(1.0 + 2.*pow(map(ro + rd * t, 0).z, 6.3));
if (d < 1e-4 || t > 400.) break;
}
return t;
}
@ -277,7 +269,7 @@ vec3 getNormal(vec3 p) {
float getLight(vec3 p, vec3 lightPos, float intensity, float shadow, vec3 n) {
vec3 l = no(lightPos - p);
float dif = cl(dot(n, l), 0., intensity),
d = rayMarch(p+n*.0025, l);
d = rayMarch(p+n*.0025, l, 1);
if(d<length(lightPos-p)) dif *= shadow;
return dif;
}
@ -365,9 +357,7 @@ vec3 cameraPointAt() {
if (u_time > 10.5) p = vec3(1.7,-1.1,0.);
// look gate at distance
if(u_time > 12.) p = vec3(0.);
if(u_time > 13.5) {
p = mix(glyph3Pos,glyph5Pos, (u_time-13.5)*0.13);
}
if(u_time > 13.5) p = mix(glyph3Pos,glyph5Pos, (u_time-13.5)*0.13);
if(u_time > 19.5) p = vec3(0.);
return p;
}
@ -392,27 +382,22 @@ vec3 sceneGate(vec2 uv)
vec3 ro = cameraPos(),
rd = getCameraRayDir(uv, ro, cameraPointAt(), cl((28.-u_time)*-2.,2.,25.)),
col = vec3(0.);
float d = rayMarch(ro, rd);
float d = rayMarch(ro, rd,0), mat = 0.;
if (d < 150.) {
if (d < 200.) {
// Lighting
vec3 p = ro + rd * d,
n = getNormal(p);
float mat = map(p,0).y,
mat = map(p,0).y;
// Light 1 Arguments
// 1: Ray starting point
// 2: Light position
// 3: Light intensity
// 4: Shadow intensity
// Light 2
dif = getLight(p, vec3( 10., 15., 25.), 1., .2,n);
col += dif * light1Color;
dif = getLight(p, vec3( 4., 2., -15.), 1., 1.,n);
col += dif * light2Color;
// Lights
col += light1Color * getLight(p, vec3( 10., 15., 25.), 1., .2,n);
col += light2Color * getLight(p, vec3( 4., 2., -15.), 1., 1.,n);
// indirect lightning -> vec3 in normalize is light direction
col += indirColor * cl( dot( n, no(vec3(0. , 1., 10.))), 0., 1.);
@ -427,27 +412,14 @@ vec3 sceneGate(vec2 uv)
if(mat==4.)
col *= vec3(0.0, 0.08, 0.11) + addSpecular(n,rd,0.3,0.7);
if(mat ==5.)
{
float exponent = 2.; // lower number makes lighting go deeper into sphere
float fresnel = pow(clamp(1.-dot(n, -rd), 0., 1.), exponent)*0.8;
vec3 rimColor = chevronColor;
vec3 sphereColor = chevronColor + fresnel * rimColor;
col = sphereColor; // activated glyph color
}
if(mat == 6.) {
col = chevronColor * pow(cl(1. -dot(n, -rd), 0., 1.), .4);
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);
col = colorFlashesAnim(col); // animated color flash
return postProcess(col);
}
col += glow * chevronColor;
return postProcess(colorFlashesAnim(applyFog(col, d, rd, vec3(0., -.1, -1.), .01)));
}
void main() {
vec2 uv = (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y;
gl_FragColor = vec4(sceneGate(uv), 1.);
gl_FragColor = vec4(sceneGate( (gl_FragCoord.xy * 2. - u_resolution.xy) / u_resolution.y), 1.);
}