This commit is contained in:
2024-07-24 23:36:31 +03:00
parent 37bec1279f
commit 83606f875e
4 changed files with 178 additions and 134 deletions

View File

@ -30,12 +30,12 @@ float hash(vec2 p)
return fract( p.x*p.y*(p.x+p.y) );
}
float noise( in vec2 p )
float noise( in vec2 p, float scale )
{
vec2 i = floor( p );
vec2 f = fract( p );
vec2 u = f*f*(3.0-2.0*f);
return -0.2+0.2*mix( mix( hash( i + vec2(0.0,0.0) ),
return -scale+scale*mix( mix( hash( i + vec2(0.0,0.0) ),
hash( i + vec2(1.0,0.0) ), u.x),
mix( hash( i + vec2(0.0,1.0) ),
hash( i + vec2(1.0,1.0) ), u.x), u.y);
@ -44,7 +44,7 @@ float noise( in vec2 p )
float displacement( vec3 p )
{
return noise(10.*p.xy+u_time) + 0.5*noise(10.*(p.xy+2.0)-u_time);
return noise(10.*p.xy+u_time, 0.2) + 0.5*noise(10.*(p.xy+2.0)-u_time, 0.2);
}
/////////////////
@ -101,10 +101,10 @@ float sdTriPrism( vec3 p, vec2 h, float rot )
//////////////////
// ANIMATION //
//////////////////
const float TWOPI = 6.28318530718;
// Rotate ring with duration d and startTime s
float ringRotateFunc(float d, float s, float timeFact) {
const float TWOPI = 6.28318530718;
float maxCycles = d;
float startTime = s;
float phase = ((u_time * timeFact) - startTime) / TWOPI;
@ -151,11 +151,12 @@ return x;
vec2 map( in vec3 p)
{
float mat = 0.;
// Stargate
// Ring boxes
const float an = 6.283185/24.0;
float sector = round(atan(p.y,p.x)/an);
const float an = TWOPI/24.0;
float sector = floor(atan(p.y,p.x)/an + 0.5);
float angrot = sector*an;
vec3 q = p;
q.xy = mat2(cos(angrot),-sin(angrot),
@ -180,8 +181,8 @@ vec2 map( in vec3 p)
//vec3 p2 = prismAnim(p);
float secDist = 6.283185 / 8.0; // sector distance
float angle = ((24.67 / 6.283185 )); // sector size
float secDist = TWOPI / 8.0; // sector distance
float angle = ((24.67 / TWOPI )); // sector size
vec3 q = p;
float rotationIncrement = angle + (index * secDist);
@ -193,7 +194,7 @@ vec2 map( in vec3 p)
rotationIncrement = rotationIncrement - 0.2;
}
float prismSector = round(atan(p.y,p.x)/(rotationIncrement));
float prismSector = floor(atan(p.y,p.x)/(rotationIncrement) + 0.5);
q.xy = rot2D(rotationIncrement) * q.xy;
// We can now call each prism by it's index
@ -219,8 +220,8 @@ vec2 map( in vec3 p)
//Rotating glyphs
vec3 p2 = ringAnim(p);
float an2 = (6.283185/32.0);
float sector2 = round((atan(p2.y,p2.x)/an2) );
float an2 = (TWOPI/32.0);
float sector2 = floor((atan(p2.y,p2.x)/an2) + 0.5 );
float angrot2 = sector2*an2;
vec3 q2 = p2;
q2.xy = rot2D(angrot2)*q2.xy;
@ -232,9 +233,11 @@ vec2 map( in vec3 p)
const float stepHeight = 0.1;
float stepDist = 1.5;
const float stepWidth = 2.0;
float steps = 1000.;
for(int i = 0; i < 4; i++) {
float step = sdBox2(vec3(p.x,p.y+stepDist,p.z), vec3(stepWidth,stepHeight,stepDist)) - 0.05;
steps = min(steps, step);
d = min(d, step);
stepDist += stepHeight * 2.0;
}
@ -251,10 +254,18 @@ vec2 map( in vec3 p)
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
}
d = min(d, water);
d = min(d, water);
}
return vec2( d );
if (d==min(water,0.1))
{
mat = 1.0;
}
else if (d==min(steps, 0.1))
{
mat = 2.0;
}
return vec2( d, mat );
}
////////////////
@ -357,13 +368,13 @@ void main( )
col += vec3(dif * vec3(0.5,0.2,0.1));
if(mat==0.){
col *= vec3(0,0,1);
col *= vec3(1,1,1);
}
else if(mat==1.){
col *= vec3(0,1,0);
col *= (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)) + vec3(0.,0.,0.5);
}
else if(mat==2.){
col *= vec3(1,0,0);
col *= vec3(0.545,0.27,0.074) - 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);
}
}
gl_FragColor = vec4(col, 1);
@ -374,23 +385,7 @@ void main( )
// ************* post-process pass ******************
// Uncomment this to try a post-processing "effect"
vec4 c = texture2D(texture_sampler, (gl_FragCoord.xy / u_resolution )),
c1 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, 0.0)) / u_resolution) ),
c2 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(0.0, 1.0)) / u_resolution) ),
c3 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, 1.0)) / u_resolution) ),
c4 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, 1.0)) / u_resolution) ),
c5 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, 0.0)) / u_resolution) ),
c6 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(-1.0, -1.0)) / u_resolution) ),
c7 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(0.0, -1.0)) / u_resolution) ),
c8 = texture2D(texture_sampler, ((gl_FragCoord.xy + vec2(1.0, -1.0)) / u_resolution) )
;
// weird emboss effect
// gl_FragColor = (c - c1 - c2 - c3 - c4 + c5 + c6 + c7 + c8) / 2.0;
// some sort of gamma correction with smoothing
gl_FragColor = sqrt(c * 2.0 + c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8) / 3.0;
gl_FragColor = texture2D(texture_sampler, (gl_FragCoord.xy / u_resolution ));
}
}