Vesi efekti

This commit is contained in:
2024-07-24 18:40:11 +03:00
parent 4389be6ef8
commit 37bec1279f

View File

@ -24,11 +24,49 @@ float smax( float a, float b, float k )
return max(a, b) + h*h*0.25/k;
}
float hash(vec2 p)
{
p = 50.*fract( p*0.3183099);
return fract( p.x*p.y*(p.x+p.y) );
}
float noise( in vec2 p )
{
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) ),
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);
}
float displacement( vec3 p )
{
return noise(10.*p.xy+u_time) + 0.5*noise(10.*(p.xy+2.0)-u_time);
}
/////////////////
// GEOMETRY //
/////////////////
float sdCylinder(vec3 p, vec3 a, vec3 b, float r)
{
vec3 ba = b - a;
vec3 pa = p - a;
float baba = dot(ba,ba);
float paba = dot(pa,ba);
float x = length(pa*baba-ba*paba) - r*baba;
float y = abs(paba-baba*0.5)-baba*0.5;
float x2 = x*x;
float y2 = y*y*baba;
float d = (max(x,y)<0.0)?-min(x2,y2):(((x>0.0)?x2:0.0)+((y>0.0)?y2:0.0));
return sign(d)*sqrt(abs(d))/baba;
}
float sdBox( in vec2 p, in vec2 r )
{
return length( max(abs(p)-r,0.0) );
@ -201,6 +239,21 @@ vec2 map( in vec3 p)
stepDist += stepHeight * 2.0;
}
float water = 1000.;
if (u_time > 2.0){
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), (2. - (u_time*2.0 - 2.0*2.0)));
float cylinder3 = sdCylinder ( p, vec3(0.,0.,1.), vec3(0.,0.,-1.), 1.6);
float disp = 0.;
if (u_time > 5.0){
disp = displacement(p+4.)*min(((u_time-5.0)*0.5), 0.25);
}
cylinder1 = cylinder1 + disp;
water = max(-cylinder2, cylinder1);
water = max(water, cylinder3);
}
d = min(d, water);
return vec2( d );
}