Animated19.47-degree Kelvin V-wake interference wave train trailing a moving watercraft.
Water & Ice
water-impact-splash-crown.glsl · 231 lines · GLSL ES 3.00 · MIT
#version 300 es
// Water Impact Splash Crown (water-impact-splash-crown.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/01_impact_splash_crown.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float)
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-01-impact-splash-crown
// Three-dimensional impact crown. A thin sheet rises, sheds beads, folds and settles.
// uResolution in framebuffer pixels. Optional uTime in seconds; zero shows an intermediate stage.
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;
float hash(vec2 v) {
vec3 p=fract(v.xyx*vec3(.1031,.1030,.0973));
p+=dot(p,p.yzx+33.33);
return fract((p.x+p.y)*p.z);
}
float noise2(vec2 p) {
vec2 i=floor(p), f=fract(p);
f=f*f*(3.0-2.0*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.0),f.x),f.y);
}
float fbm(vec2 p) {
mat2 octave=mat2(1.73,1.12,-1.12,1.73);
float value=0.0, weight=.53;
for(int i=0;i<4;i++){
value+=weight*noise2(p); p=octave*p+vec2(9.4,17.1); weight*=.50;
}
return value;
}
float sq(float v) { return v*v; }
float gauss(float v) { return exp(-v*v); }
float pixel() { return 2.0/min(uResolution.x,uResolution.y); }
vec2 screen() { return (gl_FragCoord.xy-.5*uResolution)*pixel(); }
vec3 studio(vec3 r) {
// Softboxes, a dark flag and a warm bounce card seen in specular reflection.
vec3 c=mix(vec3(.067,.083,.096),vec3(.44,.57,.67),smoothstep(-.5,.85,r.y));
float left=dot(r,normalize(vec3(-.64,.72,.23)));
float back=dot(r,normalize(vec3(.41,.43,-.80)));
c+=vec3(.94,1.02,1.06)*smoothstep(.82,.90,left);
c+=vec3(1.01,.79,.51)*smoothstep(.92,.975,back);
c*=1.0-.66*smoothstep(.89,.97,dot(r,normalize(vec3(.89,.24,.30))));
return c;
}
vec3 cameraRay(vec2 uv,vec3 eye,vec3 target,float scale) {
vec3 f=normalize(target-eye), right=normalize(cross(f,vec3(0,1,0)));
return normalize(f+scale*(right*uv.x+cross(right,f)*uv.y));
}
vec4 finish(vec3 color) {
return vec4(clamp(color,0.0,1.0),1.0);
}
struct Event { float age; float lift; float radius; float height; };
Event impact() {
float t=fract(.305+max(uTime,0.0)*.112);
float lift=smoothstep(.025,.23,t)*(1.0-smoothstep(.48,.91,t));
return Event(t,lift,.24+.48*sqrt(t),.020+.46*lift);
}
float crest(float a,Event e) {
float phase=11.0*a+.83*sin(3.0*a+.6)+.32*sin(5.0*a-.7);
float fingers=pow(.5+.5*cos(phase),2.35);
float uneven=.54+.27*sin(4.0*a+1.7)+.17*cos(2.0*a+.4);
return e.height*(.71+.12*sin(3.0*a)+(.38+.57*uneven)*fingers);
}
float sheetRadius(float y,float a,Event e) {
float t=clamp(y/max(e.height,.015),0.0,1.65);
return e.radius+.115*t*t+.030*exp(-t*11.0)+.018*t*cos(11.0*a+.83*sin(3.0*a+.6));
}
vec3 rimPoint(float a,Event e) {
float y=crest(a,e), r=sheetRadius(y,a,e);
return vec3(r*cos(a),y,r*sin(a));
}
float sheetField(vec3 p,Event e) {
return length(p.xz)-sheetRadius(p.y,atan(p.z,p.x),e);
}
vec3 sheetNormal(vec3 p,Event e) {
float a=atan(p.z,p.x), cap=crest(a,e);
float r=max(.01,length(p.xz));
vec2 radial=p.xz/r, tangent=vec2(-radial.y,radial.x);
float dy=(sheetRadius(p.y+.001,a,e)-sheetRadius(p.y-.001,a,e))/.002;
float da=(sheetRadius(p.y,a+.001,e)-sheetRadius(p.y,a-.001,e))/.002;
vec2 side=radial-tangent*da/r;
vec3 normal=normalize(vec3(side.x,-dy,side.y));
// Roll the sheet normal over its thickened upper edge.
float lip=exp(-abs(cap-p.y)*108.0);
float capSlope=(crest(a+.002,e)-crest(a-.002,e))/.004;
vec3 upper=normalize(vec3(-tangent.x*capSlope/r,1,-tangent.y*capSlope/r));
return normalize(normal+.97*lip*upper);
}
float poolHeight(float r,Event e) {
float x=r-e.radius;
float ring=.010*sin(32.0*x-19.0*e.age)*exp(-sq((x-.24)/.44));
float cavity=-.10*exp(-sq(r/max(.1,e.radius*.82)))*e.lift;
return ring+cavity+.045*gauss(x/.082)*e.lift;
}
vec3 pool(vec3 eye,vec3 ray,Event e) {
if(ray.y>-.012) return studio(ray)*.68;
// Evaluate the ripple normal at the mean water plane. This remains stable
// for grazing rays seen through the slender wall.
float t=max(0.0,-eye.y/ray.y);
vec3 p=eye+t*ray; float r=max(.001,length(p.xz));
float slope=(poolHeight(r+.002,e)-poolHeight(r-.002,e))/.004;
vec2 g=slope*p.xz/r;
vec3 n=normalize(vec3(-g.x,1,-g.y));
vec3 rr=refract(ray,n,.7502);
vec2 bed=p.xz+rr.xz*(.32/max(.1,-rr.y));
float sand=fbm(bed*5.0);
vec3 col=mix(vec3(.093,.230,.267),vec3(.28,.402,.37),sand);
float f=.066+.90*pow(1.0-clamp(dot(-ray,n),0.0,1.0),4.0);
col=mix(col,studio(reflect(ray,n)),f);
col+=vec3(.07,.115,.111)*clamp(slope,0.0,.65)*exp(-.75*r);
return col;
}
float sphereHit(vec3 eye,vec3 ray,vec3 center,float radius) {
vec3 q=eye-center; float b=dot(q,ray), h=b*b-dot(q,q)+radius*radius;
return h>0.0?-b-sqrt(h):100.0;
}
vec3 sampleCrown(vec2 uv,Event e) {
vec3 eye=vec3(1.64,1.52,3.34);
vec3 ray=cameraRay(uv,eye,vec3(0,.22,0),.255);
vec3 background=pool(eye,ray,e);
float groundT=(-.10-eye.y)/min(ray.y,-.01);
float start=max(0.0,length(eye)-1.38);
float end=min(groundT,length(eye)+1.25);
float t=start, previous=sheetField(eye+t*ray,e);
vec3 n=vec3(0,1,0);
bool hit=false;
// Bracket the two sides of the open sheet directly. Even a subpixel lip
// cannot be skipped because intersections are tested against the midsurface.
for(int j=1;j<=64;j++){
float next=mix(start,end,float(j)/64.0);
float current=sheetField(eye+next*ray,e);
if(previous*current<=0.0) {
float lo=t, hi=next;
for(int i=0;i<10;i++){
float mid=.5*(lo+hi);
if(sheetField(eye+mid*ray,e)*previous>0.0) lo=mid; else hi=mid;
}
float root=.5*(lo+hi);
vec3 p=eye+root*ray;
if(p.y>=-.005 && p.y<=crest(atan(p.z,p.x),e)){
t=root; n=sheetNormal(p,e); hit=true; break;
}
}
t=next; previous=current;
}
float nearest=hit?t:100.0;
// Resolve the rolled rim as short connected round segments. Their
// projections remain finite where the transparent sheet turns edge-on.
bool onRim=false;
vec3 a0=rimPoint(0.0,e);
for(int j=1;j<=208;j++){
vec3 b=rimPoint(6.2831853*float(j)/208.0,e);
vec3 axis=b-a0;
float len=length(axis);
axis/=max(.00001,len);
vec3 w=eye-a0;
vec3 v=ray-axis*dot(ray,axis), offset=w-axis*dot(w,axis);
float alongRay=dot(v,offset), v2=max(.000001,dot(v,v));
float rimY=.5*(a0.y+b.y);
float radius=.0055+.0075*smoothstep(.43,.78,rimY);
float h=alongRay*alongRay-v2*(dot(offset,offset)-radius*radius);
if(h>=0.0){
float td=(-alongRay-sqrt(h))/v2;
float along=dot(w+td*ray,axis);
vec3 center=a0+clamp(along,0.0,len)*axis;
if(along<0.0 || along>len) td=sphereHit(eye,ray,center,radius);
if(td<nearest && td>0.0) {
nearest=td; n=normalize(eye+td*ray-center); hit=true; onRim=true;
}
}
a0=b;
}
// Drops leave the rim on ballistic arcs, with a smaller satellite on selected tips.
for(int j=0;j<11;j++){
float id=float(j), phase=6.2831853*id;
float a=phase/11.0;
for(int k=0;k<3;k++) a=(phase-.83*sin(3.0*a+.6)-.32*sin(5.0*a-.7))/11.0;
float rnd=hash(vec2(id,23.0));
float release=.20+.16*rnd;
float age=e.age-release;
if(age<=0.0 || age>.55) continue;
Event launch=Event(release,1.0,.24+.48*sqrt(release),.48);
float y0=crest(a,launch);
float y=y0+.019+age*(1.85+.69*rnd)-6.5*age*age;
float dist=sheetRadius(y0,a,launch)+age*(.92+.33*rnd);
vec3 c=vec3(cos(a)*dist,y,sin(a)*dist);
float rad=(.014+.016*rnd)*smoothstep(.0,.030,age);
float td=sphereHit(eye,ray,c,rad);
if(td<nearest && td>0.0 && c.y>.025){nearest=td;n=normalize(eye+td*ray-c);hit=true;onRim=true;}
}
if(!hit) return background;
vec3 p=eye+nearest*ray;
n=faceforward(n,ray,n);
vec3 refracted=refract(ray,n,.7502);
vec3 transmitted=pool(p+.018*refracted,refracted,e);
vec3 refl=reflect(ray,n);
vec3 reflected=studio(refl);
float tallWindow=gauss((refl.x+.29*refl.z+.40)/.17)*smoothstep(-.38,.24,refl.y);
float strip=gauss((refl.x-.48*refl.z-.54)/.087)*smoothstep(-.25,.29,refl.y);
reflected+=vec3(.91,1.02,1.01)*tallWindow+vec3(1.03,.79,.51)*strip;
float f=.024+.94*pow(1.0-max(dot(-ray,n),0.0),4.0);
transmitted=mix(transmitted,background,.45);
vec3 water=mix(transmitted*vec3(.89,.98,.99),reflected,.19+.77*f);
water+=vec3(.055,.093,.098)*clamp(p.y/.55,0.0,1.0);
// The far bank and opposing wall are seen distorted through the crown.
float interior=smoothstep(.04,.36,p.y);
float band=dot(reflect(ray,n),normalize(vec3(-.58,.70,.39)));
water+=vec3(.24,.30,.29)*smoothstep(.91,.987,band)*interior;
if(onRim) {
float key=.5+.5*dot(n,normalize(vec3(-.40,.79,.46)));
water+=vec3(.38,.47,.48)*pow(key,3.0);
}
water=water/(vec3(1.0)+.20*water)*1.25;
float skirt=smoothstep(.0,.095,p.y);
return mix(background,water,smoothstep(.025,.19,e.lift)*(.18+.82*skirt));
}
void main() {
Event e=impact(); vec2 p=screen();
vec3 c=.5*(sampleCrown(p+vec2(.22,.24)*pixel(),e)+sampleCrown(p-vec2(.22,.24)*pixel(),e));
fragColor=finish(c);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Water Impact Splash Crown — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/01_impact_splash_crown.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-01-impact-splash-crown
// Three-dimensional impact crown. A thin sheet rises, sheds beads, folds and settles.
// uResolution in framebuffer pixels. Optional uTime in seconds; zero shows an intermediate stage.
float hash(vec2 v) {
vec3 p=fract(v.xyx*vec3(.1031,.1030,.0973));
p+=dot(p,p.yzx+33.33);
return fract((p.x+p.y)*p.z);
}
float noise2(vec2 p) {
vec2 i=floor(p), f=fract(p);
f=f*f*(3.0-2.0*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.0),f.x),f.y);
}
float fbm(vec2 p) {
mat2 octave=mat2(1.73,1.12,-1.12,1.73);
float value=0.0, weight=.53;
for(int i=0;i<4;i++){
value+=weight*noise2(p); p=octave*p+vec2(9.4,17.1); weight*=.50;
}
return value;
}
float sq(float v) { return v*v; }
float gauss(float v) { return exp(-v*v); }
float pixel() { return 2.0/min(uResolution.x,uResolution.y); }
vec2 screen() { return (pfx_frag_xy-.5*uResolution)*pixel(); }
vec3 studio(vec3 r) {
// Softboxes, a dark flag and a warm bounce card seen in specular reflection.
vec3 c=mix(vec3(.067,.083,.096),vec3(.44,.57,.67),smoothstep(-.5,.85,r.y));
float left=dot(r,normalize(vec3(-.64,.72,.23)));
float back=dot(r,normalize(vec3(.41,.43,-.80)));
c+=vec3(.94,1.02,1.06)*smoothstep(.82,.90,left);
c+=vec3(1.01,.79,.51)*smoothstep(.92,.975,back);
c*=1.0-.66*smoothstep(.89,.97,dot(r,normalize(vec3(.89,.24,.30))));
return c;
}
vec3 cameraRay(vec2 uv,vec3 eye,vec3 target,float scale) {
vec3 f=normalize(target-eye), right=normalize(cross(f,vec3(0,1,0)));
return normalize(f+scale*(right*uv.x+cross(right,f)*uv.y));
}
vec4 finish(vec3 color) {
return vec4(clamp(color,0.0,1.0),1.0);
}
struct Event { float age; float lift; float radius; float height; };
Event impact() {
float t=fract(.305+max(uTime,0.0)*.112);
float lift=smoothstep(.025,.23,t)*(1.0-smoothstep(.48,.91,t));
return Event(t,lift,.24+.48*sqrt(t),.020+.46*lift);
}
float crest(float a,Event e) {
float phase=11.0*a+.83*sin(3.0*a+.6)+.32*sin(5.0*a-.7);
float fingers=pow(.5+.5*cos(phase),2.35);
float uneven=.54+.27*sin(4.0*a+1.7)+.17*cos(2.0*a+.4);
return e.height*(.71+.12*sin(3.0*a)+(.38+.57*uneven)*fingers);
}
float sheetRadius(float y,float a,Event e) {
float t=clamp(y/max(e.height,.015),0.0,1.65);
return e.radius+.115*t*t+.030*exp(-t*11.0)+.018*t*cos(11.0*a+.83*sin(3.0*a+.6));
}
vec3 rimPoint(float a,Event e) {
float y=crest(a,e), r=sheetRadius(y,a,e);
return vec3(r*cos(a),y,r*sin(a));
}
float sheetField(vec3 p,Event e) {
return length(p.xz)-sheetRadius(p.y,atan(p.z,p.x),e);
}
vec3 sheetNormal(vec3 p,Event e) {
float a=atan(p.z,p.x), cap=crest(a,e);
float r=max(.01,length(p.xz));
vec2 radial=p.xz/r, tangent=vec2(-radial.y,radial.x);
float dy=(sheetRadius(p.y+.001,a,e)-sheetRadius(p.y-.001,a,e))/.002;
float da=(sheetRadius(p.y,a+.001,e)-sheetRadius(p.y,a-.001,e))/.002;
vec2 side=radial-tangent*da/r;
vec3 normal=normalize(vec3(side.x,-dy,side.y));
// Roll the sheet normal over its thickened upper edge.
float lip=exp(-abs(cap-p.y)*108.0);
float capSlope=(crest(a+.002,e)-crest(a-.002,e))/.004;
vec3 upper=normalize(vec3(-tangent.x*capSlope/r,1,-tangent.y*capSlope/r));
return normalize(normal+.97*lip*upper);
}
float poolHeight(float r,Event e) {
float x=r-e.radius;
float ring=.010*sin(32.0*x-19.0*e.age)*exp(-sq((x-.24)/.44));
float cavity=-.10*exp(-sq(r/max(.1,e.radius*.82)))*e.lift;
return ring+cavity+.045*gauss(x/.082)*e.lift;
}
vec3 pool(vec3 eye,vec3 ray,Event e) {
if(ray.y>-.012) return studio(ray)*.68;
// Evaluate the ripple normal at the mean water plane. This remains stable
// for grazing rays seen through the slender wall.
float t=max(0.0,-eye.y/ray.y);
vec3 p=eye+t*ray; float r=max(.001,length(p.xz));
float slope=(poolHeight(r+.002,e)-poolHeight(r-.002,e))/.004;
vec2 g=slope*p.xz/r;
vec3 n=normalize(vec3(-g.x,1,-g.y));
vec3 rr=refract(ray,n,.7502);
vec2 bed=p.xz+rr.xz*(.32/max(.1,-rr.y));
float sand=fbm(bed*5.0);
vec3 col=mix(vec3(.093,.230,.267),vec3(.28,.402,.37),sand);
float f=.066+.90*pow(1.0-clamp(dot(-ray,n),0.0,1.0),4.0);
col=mix(col,studio(reflect(ray,n)),f);
col+=vec3(.07,.115,.111)*clamp(slope,0.0,.65)*exp(-.75*r);
return col;
}
float sphereHit(vec3 eye,vec3 ray,vec3 center,float radius) {
vec3 q=eye-center; float b=dot(q,ray), h=b*b-dot(q,q)+radius*radius;
return h>0.0?-b-sqrt(h):100.0;
}
vec3 sampleCrown(vec2 uv,Event e) {
vec3 eye=vec3(1.64,1.52,3.34);
vec3 ray=cameraRay(uv,eye,vec3(0,.22,0),.255);
vec3 background=pool(eye,ray,e);
float groundT=(-.10-eye.y)/min(ray.y,-.01);
float start=max(0.0,length(eye)-1.38);
float end=min(groundT,length(eye)+1.25);
float t=start, previous=sheetField(eye+t*ray,e);
vec3 n=vec3(0,1,0);
bool hit=false;
// Bracket the two sides of the open sheet directly. Even a subpixel lip
// cannot be skipped because intersections are tested against the midsurface.
for(int j=1;j<=64;j++){
float next=mix(start,end,float(j)/64.0);
float current=sheetField(eye+next*ray,e);
if(previous*current<=0.0) {
float lo=t, hi=next;
for(int i=0;i<10;i++){
float mid=.5*(lo+hi);
if(sheetField(eye+mid*ray,e)*previous>0.0) lo=mid; else hi=mid;
}
float root=.5*(lo+hi);
vec3 p=eye+root*ray;
if(p.y>=-.005 && p.y<=crest(atan(p.z,p.x),e)){
t=root; n=sheetNormal(p,e); hit=true; break;
}
}
t=next; previous=current;
}
float nearest=hit?t:100.0;
// Resolve the rolled rim as short connected round segments. Their
// projections remain finite where the transparent sheet turns edge-on.
bool onRim=false;
vec3 a0=rimPoint(0.0,e);
for(int j=1;j<=208;j++){
vec3 b=rimPoint(6.2831853*float(j)/208.0,e);
vec3 axis=b-a0;
float len=length(axis);
axis/=max(.00001,len);
vec3 w=eye-a0;
vec3 v=ray-axis*dot(ray,axis), offset=w-axis*dot(w,axis);
float alongRay=dot(v,offset), v2=max(.000001,dot(v,v));
float rimY=.5*(a0.y+b.y);
float radius=.0055+.0075*smoothstep(.43,.78,rimY);
float h=alongRay*alongRay-v2*(dot(offset,offset)-radius*radius);
if(h>=0.0){
float td=(-alongRay-sqrt(h))/v2;
float along=dot(w+td*ray,axis);
vec3 center=a0+clamp(along,0.0,len)*axis;
if(along<0.0 || along>len) td=sphereHit(eye,ray,center,radius);
if(td<nearest && td>0.0) {
nearest=td; n=normalize(eye+td*ray-center); hit=true; onRim=true;
}
}
a0=b;
}
// Drops leave the rim on ballistic arcs, with a smaller satellite on selected tips.
for(int j=0;j<11;j++){
float id=float(j), phase=6.2831853*id;
float a=phase/11.0;
for(int k=0;k<3;k++) a=(phase-.83*sin(3.0*a+.6)-.32*sin(5.0*a-.7))/11.0;
float rnd=hash(vec2(id,23.0));
float release=.20+.16*rnd;
float age=e.age-release;
if(age<=0.0 || age>.55) continue;
Event launch=Event(release,1.0,.24+.48*sqrt(release),.48);
float y0=crest(a,launch);
float y=y0+.019+age*(1.85+.69*rnd)-6.5*age*age;
float dist=sheetRadius(y0,a,launch)+age*(.92+.33*rnd);
vec3 c=vec3(cos(a)*dist,y,sin(a)*dist);
float rad=(.014+.016*rnd)*smoothstep(.0,.030,age);
float td=sphereHit(eye,ray,c,rad);
if(td<nearest && td>0.0 && c.y>.025){nearest=td;n=normalize(eye+td*ray-c);hit=true;onRim=true;}
}
if(!hit) return background;
vec3 p=eye+nearest*ray;
n=faceforward(n,ray,n);
vec3 refracted=refract(ray,n,.7502);
vec3 transmitted=pool(p+.018*refracted,refracted,e);
vec3 refl=reflect(ray,n);
vec3 reflected=studio(refl);
float tallWindow=gauss((refl.x+.29*refl.z+.40)/.17)*smoothstep(-.38,.24,refl.y);
float strip=gauss((refl.x-.48*refl.z-.54)/.087)*smoothstep(-.25,.29,refl.y);
reflected+=vec3(.91,1.02,1.01)*tallWindow+vec3(1.03,.79,.51)*strip;
float f=.024+.94*pow(1.0-max(dot(-ray,n),0.0),4.0);
transmitted=mix(transmitted,background,.45);
vec3 water=mix(transmitted*vec3(.89,.98,.99),reflected,.19+.77*f);
water+=vec3(.055,.093,.098)*clamp(p.y/.55,0.0,1.0);
// The far bank and opposing wall are seen distorted through the crown.
float interior=smoothstep(.04,.36,p.y);
float band=dot(reflect(ray,n),normalize(vec3(-.58,.70,.39)));
water+=vec3(.24,.30,.29)*smoothstep(.91,.987,band)*interior;
if(onRim) {
float key=.5+.5*dot(n,normalize(vec3(-.40,.79,.46)));
water+=vec3(.38,.47,.48)*pow(key,3.0);
}
water=water/(vec3(1.0)+.20*water)*1.25;
float skirt=smoothstep(.0,.095,p.y);
return mix(background,water,smoothstep(.025,.19,e.lift)*(.18+.82*skirt));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
Event e=impact(); vec2 p=screen();
vec3 c=.5*(sampleCrown(p+vec2(.22,.24)*pixel(),e)+sampleCrown(p-vec2(.22,.24)*pixel(),e));
fragColor=finish(c);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float out_alpha = study_col.a * COLOR.a;
if (u_luma_alpha_key) {
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
out_alpha *= smoothstep(0.035, 0.22, luma);
}
COLOR = vec4(tinted, out_alpha);
}
shader_type spatial;
render_mode cull_disabled;
// Water Impact Splash Crown — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/01_impact_splash_crown.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-01-impact-splash-crown
// Three-dimensional impact crown. A thin sheet rises, sheds beads, folds and settles.
// uResolution in framebuffer pixels. Optional uTime in seconds; zero shows an intermediate stage.
float hash(vec2 v) {
vec3 p=fract(v.xyx*vec3(.1031,.1030,.0973));
p+=dot(p,p.yzx+33.33);
return fract((p.x+p.y)*p.z);
}
float noise2(vec2 p) {
vec2 i=floor(p), f=fract(p);
f=f*f*(3.0-2.0*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.0),f.x),f.y);
}
float fbm(vec2 p) {
mat2 octave=mat2(1.73,1.12,-1.12,1.73);
float value=0.0, weight=.53;
for(int i=0;i<4;i++){
value+=weight*noise2(p); p=octave*p+vec2(9.4,17.1); weight*=.50;
}
return value;
}
float sq(float v) { return v*v; }
float gauss(float v) { return exp(-v*v); }
float pixel() { return 2.0/min(uResolution.x,uResolution.y); }
vec2 screen() { return (pfx_frag_xy-.5*uResolution)*pixel(); }
vec3 studio(vec3 r) {
// Softboxes, a dark flag and a warm bounce card seen in specular reflection.
vec3 c=mix(vec3(.067,.083,.096),vec3(.44,.57,.67),smoothstep(-.5,.85,r.y));
float left=dot(r,normalize(vec3(-.64,.72,.23)));
float back=dot(r,normalize(vec3(.41,.43,-.80)));
c+=vec3(.94,1.02,1.06)*smoothstep(.82,.90,left);
c+=vec3(1.01,.79,.51)*smoothstep(.92,.975,back);
c*=1.0-.66*smoothstep(.89,.97,dot(r,normalize(vec3(.89,.24,.30))));
return c;
}
vec3 cameraRay(vec2 uv,vec3 eye,vec3 target,float scale) {
vec3 f=normalize(target-eye), right=normalize(cross(f,vec3(0,1,0)));
return normalize(f+scale*(right*uv.x+cross(right,f)*uv.y));
}
vec4 finish(vec3 color) {
return vec4(clamp(color,0.0,1.0),1.0);
}
struct Event { float age; float lift; float radius; float height; };
Event impact() {
float t=fract(.305+max(uTime,0.0)*.112);
float lift=smoothstep(.025,.23,t)*(1.0-smoothstep(.48,.91,t));
return Event(t,lift,.24+.48*sqrt(t),.020+.46*lift);
}
float crest(float a,Event e) {
float phase=11.0*a+.83*sin(3.0*a+.6)+.32*sin(5.0*a-.7);
float fingers=pow(.5+.5*cos(phase),2.35);
float uneven=.54+.27*sin(4.0*a+1.7)+.17*cos(2.0*a+.4);
return e.height*(.71+.12*sin(3.0*a)+(.38+.57*uneven)*fingers);
}
float sheetRadius(float y,float a,Event e) {
float t=clamp(y/max(e.height,.015),0.0,1.65);
return e.radius+.115*t*t+.030*exp(-t*11.0)+.018*t*cos(11.0*a+.83*sin(3.0*a+.6));
}
vec3 rimPoint(float a,Event e) {
float y=crest(a,e), r=sheetRadius(y,a,e);
return vec3(r*cos(a),y,r*sin(a));
}
float sheetField(vec3 p,Event e) {
return length(p.xz)-sheetRadius(p.y,atan(p.z,p.x),e);
}
vec3 sheetNormal(vec3 p,Event e) {
float a=atan(p.z,p.x), cap=crest(a,e);
float r=max(.01,length(p.xz));
vec2 radial=p.xz/r, tangent=vec2(-radial.y,radial.x);
float dy=(sheetRadius(p.y+.001,a,e)-sheetRadius(p.y-.001,a,e))/.002;
float da=(sheetRadius(p.y,a+.001,e)-sheetRadius(p.y,a-.001,e))/.002;
vec2 side=radial-tangent*da/r;
vec3 normal=normalize(vec3(side.x,-dy,side.y));
// Roll the sheet normal over its thickened upper edge.
float lip=exp(-abs(cap-p.y)*108.0);
float capSlope=(crest(a+.002,e)-crest(a-.002,e))/.004;
vec3 upper=normalize(vec3(-tangent.x*capSlope/r,1,-tangent.y*capSlope/r));
return normalize(normal+.97*lip*upper);
}
float poolHeight(float r,Event e) {
float x=r-e.radius;
float ring=.010*sin(32.0*x-19.0*e.age)*exp(-sq((x-.24)/.44));
float cavity=-.10*exp(-sq(r/max(.1,e.radius*.82)))*e.lift;
return ring+cavity+.045*gauss(x/.082)*e.lift;
}
vec3 pool(vec3 eye,vec3 ray,Event e) {
if(ray.y>-.012) return studio(ray)*.68;
// Evaluate the ripple normal at the mean water plane. This remains stable
// for grazing rays seen through the slender wall.
float t=max(0.0,-eye.y/ray.y);
vec3 p=eye+t*ray; float r=max(.001,length(p.xz));
float slope=(poolHeight(r+.002,e)-poolHeight(r-.002,e))/.004;
vec2 g=slope*p.xz/r;
vec3 n=normalize(vec3(-g.x,1,-g.y));
vec3 rr=refract(ray,n,.7502);
vec2 bed=p.xz+rr.xz*(.32/max(.1,-rr.y));
float sand=fbm(bed*5.0);
vec3 col=mix(vec3(.093,.230,.267),vec3(.28,.402,.37),sand);
float f=.066+.90*pow(1.0-clamp(dot(-ray,n),0.0,1.0),4.0);
col=mix(col,studio(reflect(ray,n)),f);
col+=vec3(.07,.115,.111)*clamp(slope,0.0,.65)*exp(-.75*r);
return col;
}
float sphereHit(vec3 eye,vec3 ray,vec3 center,float radius) {
vec3 q=eye-center; float b=dot(q,ray), h=b*b-dot(q,q)+radius*radius;
return h>0.0?-b-sqrt(h):100.0;
}
vec3 sampleCrown(vec2 uv,Event e) {
vec3 eye=vec3(1.64,1.52,3.34);
vec3 ray=cameraRay(uv,eye,vec3(0,.22,0),.255);
vec3 background=pool(eye,ray,e);
float groundT=(-.10-eye.y)/min(ray.y,-.01);
float start=max(0.0,length(eye)-1.38);
float end=min(groundT,length(eye)+1.25);
float t=start, previous=sheetField(eye+t*ray,e);
vec3 n=vec3(0,1,0);
bool hit=false;
// Bracket the two sides of the open sheet directly. Even a subpixel lip
// cannot be skipped because intersections are tested against the midsurface.
for(int j=1;j<=64;j++){
float next=mix(start,end,float(j)/64.0);
float current=sheetField(eye+next*ray,e);
if(previous*current<=0.0) {
float lo=t, hi=next;
for(int i=0;i<10;i++){
float mid=.5*(lo+hi);
if(sheetField(eye+mid*ray,e)*previous>0.0) lo=mid; else hi=mid;
}
float root=.5*(lo+hi);
vec3 p=eye+root*ray;
if(p.y>=-.005 && p.y<=crest(atan(p.z,p.x),e)){
t=root; n=sheetNormal(p,e); hit=true; break;
}
}
t=next; previous=current;
}
float nearest=hit?t:100.0;
// Resolve the rolled rim as short connected round segments. Their
// projections remain finite where the transparent sheet turns edge-on.
bool onRim=false;
vec3 a0=rimPoint(0.0,e);
for(int j=1;j<=208;j++){
vec3 b=rimPoint(6.2831853*float(j)/208.0,e);
vec3 axis=b-a0;
float len=length(axis);
axis/=max(.00001,len);
vec3 w=eye-a0;
vec3 v=ray-axis*dot(ray,axis), offset=w-axis*dot(w,axis);
float alongRay=dot(v,offset), v2=max(.000001,dot(v,v));
float rimY=.5*(a0.y+b.y);
float radius=.0055+.0075*smoothstep(.43,.78,rimY);
float h=alongRay*alongRay-v2*(dot(offset,offset)-radius*radius);
if(h>=0.0){
float td=(-alongRay-sqrt(h))/v2;
float along=dot(w+td*ray,axis);
vec3 center=a0+clamp(along,0.0,len)*axis;
if(along<0.0 || along>len) td=sphereHit(eye,ray,center,radius);
if(td<nearest && td>0.0) {
nearest=td; n=normalize(eye+td*ray-center); hit=true; onRim=true;
}
}
a0=b;
}
// Drops leave the rim on ballistic arcs, with a smaller satellite on selected tips.
for(int j=0;j<11;j++){
float id=float(j), phase=6.2831853*id;
float a=phase/11.0;
for(int k=0;k<3;k++) a=(phase-.83*sin(3.0*a+.6)-.32*sin(5.0*a-.7))/11.0;
float rnd=hash(vec2(id,23.0));
float release=.20+.16*rnd;
float age=e.age-release;
if(age<=0.0 || age>.55) continue;
Event launch=Event(release,1.0,.24+.48*sqrt(release),.48);
float y0=crest(a,launch);
float y=y0+.019+age*(1.85+.69*rnd)-6.5*age*age;
float dist=sheetRadius(y0,a,launch)+age*(.92+.33*rnd);
vec3 c=vec3(cos(a)*dist,y,sin(a)*dist);
float rad=(.014+.016*rnd)*smoothstep(.0,.030,age);
float td=sphereHit(eye,ray,c,rad);
if(td<nearest && td>0.0 && c.y>.025){nearest=td;n=normalize(eye+td*ray-c);hit=true;onRim=true;}
}
if(!hit) return background;
vec3 p=eye+nearest*ray;
n=faceforward(n,ray,n);
vec3 refracted=refract(ray,n,.7502);
vec3 transmitted=pool(p+.018*refracted,refracted,e);
vec3 refl=reflect(ray,n);
vec3 reflected=studio(refl);
float tallWindow=gauss((refl.x+.29*refl.z+.40)/.17)*smoothstep(-.38,.24,refl.y);
float strip=gauss((refl.x-.48*refl.z-.54)/.087)*smoothstep(-.25,.29,refl.y);
reflected+=vec3(.91,1.02,1.01)*tallWindow+vec3(1.03,.79,.51)*strip;
float f=.024+.94*pow(1.0-max(dot(-ray,n),0.0),4.0);
transmitted=mix(transmitted,background,.45);
vec3 water=mix(transmitted*vec3(.89,.98,.99),reflected,.19+.77*f);
water+=vec3(.055,.093,.098)*clamp(p.y/.55,0.0,1.0);
// The far bank and opposing wall are seen distorted through the crown.
float interior=smoothstep(.04,.36,p.y);
float band=dot(reflect(ray,n),normalize(vec3(-.58,.70,.39)));
water+=vec3(.24,.30,.29)*smoothstep(.91,.987,band)*interior;
if(onRim) {
float key=.5+.5*dot(n,normalize(vec3(-.40,.79,.46)));
water+=vec3(.38,.47,.48)*pow(key,3.0);
}
water=water/(vec3(1.0)+.20*water)*1.25;
float skirt=smoothstep(.0,.095,p.y);
return mix(background,water,smoothstep(.025,.19,e.lift)*(.18+.82*skirt));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
Event e=impact(); vec2 p=screen();
vec3 c=.5*(sampleCrown(p+vec2(.22,.24)*pixel(),e)+sampleCrown(p-vec2(.22,.24)*pixel(),e));
fragColor=finish(c);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
ALBEDO = tinted;
ROUGHNESS = clamp(0.85 - luma * 0.45, 0.08, 0.96);
METALLIC = 0.04;
EMISSION = tinted * 0.0;
}
// Water Impact Splash Crown — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/01_impact_splash_crown.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
// Hash adapted from David Hoskins, Hash without Sine. See THIRD_PARTY_NOTICES.md.
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-liquids-lib-01-impact-splash-crown
// Three-dimensional impact crown. A thin sheet rises, sheds beads, folds and settles.
// uResolution in framebuffer pixels. Optional uTime in seconds; zero shows an intermediate stage.
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;
float hash(vec2 v) {
vec3 p=fract(v.xyx*vec3(.1031,.1030,.0973));
p+=dot(p,p.yzx+33.33);
return fract((p.x+p.y)*p.z);
}
float noise2(vec2 p) {
vec2 i=floor(p), f=fract(p);
f=f*f*(3.0-2.0*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.0),f.x),f.y);
}
float fbm(vec2 p) {
mat2 octave=mat2(1.73,1.12,-1.12,1.73);
float value=0.0, weight=.53;
for(int i=0;i<4;i++){
value+=weight*noise2(p); p=octave*p+vec2(9.4,17.1); weight*=.50;
}
return value;
}
float sq(float v) { return v*v; }
float gauss(float v) { return exp(-v*v); }
float pixel() { return 2.0/min(uResolution.x,uResolution.y); }
vec2 screen() { return (gl_FragCoord.xy-.5*uResolution)*pixel(); }
vec3 studio(vec3 r) {
// Softboxes, a dark flag and a warm bounce card seen in specular reflection.
vec3 c=mix(vec3(.067,.083,.096),vec3(.44,.57,.67),smoothstep(-.5,.85,r.y));
float left=dot(r,normalize(vec3(-.64,.72,.23)));
float back=dot(r,normalize(vec3(.41,.43,-.80)));
c+=vec3(.94,1.02,1.06)*smoothstep(.82,.90,left);
c+=vec3(1.01,.79,.51)*smoothstep(.92,.975,back);
c*=1.0-.66*smoothstep(.89,.97,dot(r,normalize(vec3(.89,.24,.30))));
return c;
}
vec3 cameraRay(vec2 uv,vec3 eye,vec3 target,float scale) {
vec3 f=normalize(target-eye), right=normalize(cross(f,vec3(0,1,0)));
return normalize(f+scale*(right*uv.x+cross(right,f)*uv.y));
}
vec4 finish(vec3 color) {
return vec4(clamp(color,0.0,1.0),1.0);
}
struct Event { float age; float lift; float radius; float height; };
Event impact() {
float t=fract(.305+max(uTime,0.0)*.112);
float lift=smoothstep(.025,.23,t)*(1.0-smoothstep(.48,.91,t));
return Event(t,lift,.24+.48*sqrt(t),.020+.46*lift);
}
float crest(float a,Event e) {
float phase=11.0*a+.83*sin(3.0*a+.6)+.32*sin(5.0*a-.7);
float fingers=pow(.5+.5*cos(phase),2.35);
float uneven=.54+.27*sin(4.0*a+1.7)+.17*cos(2.0*a+.4);
return e.height*(.71+.12*sin(3.0*a)+(.38+.57*uneven)*fingers);
}
float sheetRadius(float y,float a,Event e) {
float t=clamp(y/max(e.height,.015),0.0,1.65);
return e.radius+.115*t*t+.030*exp(-t*11.0)+.018*t*cos(11.0*a+.83*sin(3.0*a+.6));
}
vec3 rimPoint(float a,Event e) {
float y=crest(a,e), r=sheetRadius(y,a,e);
return vec3(r*cos(a),y,r*sin(a));
}
float sheetField(vec3 p,Event e) {
return length(p.xz)-sheetRadius(p.y,atan(p.z,p.x),e);
}
vec3 sheetNormal(vec3 p,Event e) {
float a=atan(p.z,p.x), cap=crest(a,e);
float r=max(.01,length(p.xz));
vec2 radial=p.xz/r, tangent=vec2(-radial.y,radial.x);
float dy=(sheetRadius(p.y+.001,a,e)-sheetRadius(p.y-.001,a,e))/.002;
float da=(sheetRadius(p.y,a+.001,e)-sheetRadius(p.y,a-.001,e))/.002;
vec2 side=radial-tangent*da/r;
vec3 normal=normalize(vec3(side.x,-dy,side.y));
// Roll the sheet normal over its thickened upper edge.
float lip=exp(-abs(cap-p.y)*108.0);
float capSlope=(crest(a+.002,e)-crest(a-.002,e))/.004;
vec3 upper=normalize(vec3(-tangent.x*capSlope/r,1,-tangent.y*capSlope/r));
return normalize(normal+.97*lip*upper);
}
float poolHeight(float r,Event e) {
float x=r-e.radius;
float ring=.010*sin(32.0*x-19.0*e.age)*exp(-sq((x-.24)/.44));
float cavity=-.10*exp(-sq(r/max(.1,e.radius*.82)))*e.lift;
return ring+cavity+.045*gauss(x/.082)*e.lift;
}
vec3 pool(vec3 eye,vec3 ray,Event e) {
if(ray.y>-.012) return studio(ray)*.68;
// Evaluate the ripple normal at the mean water plane. This remains stable
// for grazing rays seen through the slender wall.
float t=max(0.0,-eye.y/ray.y);
vec3 p=eye+t*ray; float r=max(.001,length(p.xz));
float slope=(poolHeight(r+.002,e)-poolHeight(r-.002,e))/.004;
vec2 g=slope*p.xz/r;
vec3 n=normalize(vec3(-g.x,1,-g.y));
vec3 rr=refract(ray,n,.7502);
vec2 bed=p.xz+rr.xz*(.32/max(.1,-rr.y));
float sand=fbm(bed*5.0);
vec3 col=mix(vec3(.093,.230,.267),vec3(.28,.402,.37),sand);
float f=.066+.90*pow(1.0-clamp(dot(-ray,n),0.0,1.0),4.0);
col=mix(col,studio(reflect(ray,n)),f);
col+=vec3(.07,.115,.111)*clamp(slope,0.0,.65)*exp(-.75*r);
return col;
}
float sphereHit(vec3 eye,vec3 ray,vec3 center,float radius) {
vec3 q=eye-center; float b=dot(q,ray), h=b*b-dot(q,q)+radius*radius;
return h>0.0?-b-sqrt(h):100.0;
}
vec3 sampleCrown(vec2 uv,Event e) {
vec3 eye=vec3(1.64,1.52,3.34);
vec3 ray=cameraRay(uv,eye,vec3(0,.22,0),.255);
vec3 background=pool(eye,ray,e);
float groundT=(-.10-eye.y)/min(ray.y,-.01);
float start=max(0.0,length(eye)-1.38);
float end=min(groundT,length(eye)+1.25);
float t=start, previous=sheetField(eye+t*ray,e);
vec3 n=vec3(0,1,0);
bool hit=false;
// Bracket the two sides of the open sheet directly. Even a subpixel lip
// cannot be skipped because intersections are tested against the midsurface.
for(int j=1;j<=64;j++){
float next=mix(start,end,float(j)/64.0);
float current=sheetField(eye+next*ray,e);
if(previous*current<=0.0) {
float lo=t, hi=next;
for(int i=0;i<10;i++){
float mid=.5*(lo+hi);
if(sheetField(eye+mid*ray,e)*previous>0.0) lo=mid; else hi=mid;
}
float root=.5*(lo+hi);
vec3 p=eye+root*ray;
if(p.y>=-.005 && p.y<=crest(atan(p.z,p.x),e)){
t=root; n=sheetNormal(p,e); hit=true; break;
}
}
t=next; previous=current;
}
float nearest=hit?t:100.0;
// Resolve the rolled rim as short connected round segments. Their
// projections remain finite where the transparent sheet turns edge-on.
bool onRim=false;
vec3 a0=rimPoint(0.0,e);
for(int j=1;j<=208;j++){
vec3 b=rimPoint(6.2831853*float(j)/208.0,e);
vec3 axis=b-a0;
float len=length(axis);
axis/=max(.00001,len);
vec3 w=eye-a0;
vec3 v=ray-axis*dot(ray,axis), offset=w-axis*dot(w,axis);
float alongRay=dot(v,offset), v2=max(.000001,dot(v,v));
float rimY=.5*(a0.y+b.y);
float radius=.0055+.0075*smoothstep(.43,.78,rimY);
float h=alongRay*alongRay-v2*(dot(offset,offset)-radius*radius);
if(h>=0.0){
float td=(-alongRay-sqrt(h))/v2;
float along=dot(w+td*ray,axis);
vec3 center=a0+clamp(along,0.0,len)*axis;
if(along<0.0 || along>len) td=sphereHit(eye,ray,center,radius);
if(td<nearest && td>0.0) {
nearest=td; n=normalize(eye+td*ray-center); hit=true; onRim=true;
}
}
a0=b;
}
// Drops leave the rim on ballistic arcs, with a smaller satellite on selected tips.
for(int j=0;j<11;j++){
float id=float(j), phase=6.2831853*id;
float a=phase/11.0;
for(int k=0;k<3;k++) a=(phase-.83*sin(3.0*a+.6)-.32*sin(5.0*a-.7))/11.0;
float rnd=hash(vec2(id,23.0));
float release=.20+.16*rnd;
float age=e.age-release;
if(age<=0.0 || age>.55) continue;
Event launch=Event(release,1.0,.24+.48*sqrt(release),.48);
float y0=crest(a,launch);
float y=y0+.019+age*(1.85+.69*rnd)-6.5*age*age;
float dist=sheetRadius(y0,a,launch)+age*(.92+.33*rnd);
vec3 c=vec3(cos(a)*dist,y,sin(a)*dist);
float rad=(.014+.016*rnd)*smoothstep(.0,.030,age);
float td=sphereHit(eye,ray,c,rad);
if(td<nearest && td>0.0 && c.y>.025){nearest=td;n=normalize(eye+td*ray-c);hit=true;onRim=true;}
}
if(!hit) return background;
vec3 p=eye+nearest*ray;
n=faceforward(n,ray,n);
vec3 refracted=refract(ray,n,.7502);
vec3 transmitted=pool(p+.018*refracted,refracted,e);
vec3 refl=reflect(ray,n);
vec3 reflected=studio(refl);
float tallWindow=gauss((refl.x+.29*refl.z+.40)/.17)*smoothstep(-.38,.24,refl.y);
float strip=gauss((refl.x-.48*refl.z-.54)/.087)*smoothstep(-.25,.29,refl.y);
reflected+=vec3(.91,1.02,1.01)*tallWindow+vec3(1.03,.79,.51)*strip;
float f=.024+.94*pow(1.0-max(dot(-ray,n),0.0),4.0);
transmitted=mix(transmitted,background,.45);
vec3 water=mix(transmitted*vec3(.89,.98,.99),reflected,.19+.77*f);
water+=vec3(.055,.093,.098)*clamp(p.y/.55,0.0,1.0);
// The far bank and opposing wall are seen distorted through the crown.
float interior=smoothstep(.04,.36,p.y);
float band=dot(reflect(ray,n),normalize(vec3(-.58,.70,.39)));
water+=vec3(.24,.30,.29)*smoothstep(.91,.987,band)*interior;
if(onRim) {
float key=.5+.5*dot(n,normalize(vec3(-.40,.79,.46)));
water+=vec3(.38,.47,.48)*pow(key,3.0);
}
water=water/(vec3(1.0)+.20*water)*1.25;
float skirt=smoothstep(.0,.095,p.y);
return mix(background,water,smoothstep(.025,.19,e.lift)*(.18+.82*skirt));
}
void main() {
Event e=impact(); vec2 p=screen();
vec3 c=.5*(sampleCrown(p+vec2(.22,.24)*pixel(),e)+sampleCrown(p-vec2(.22,.24)*pixel(),e));
fragColor=finish(c);
}
`;
export function createWaterImpactSplashCrownMaterial(width = 1024, height = 1024) {
const material = new THREE.ShaderMaterial({
glslVersion: THREE.GLSL3,
vertexShader,
fragmentShader,
uniforms: {
uResolution: { value: new THREE.Vector2(width, height) },
uTime: { value: 1.2 },
uOpen: { value: 0.0 },
uLightMode: { value: 0 },
uCamMode: { value: 1 },
},
});
return {
material,
update(elapsedSeconds) {
material.uniforms.uTime.value = elapsedSeconds * 1.0;
},
resize(nextW, nextH) {
material.uniforms.uResolution.value.set(nextW, nextH);
},
};
}
| Identifier | water-impact-splash-crown |
|---|---|
| Category | Water & Ice Shaders · Dynamic Liquids |
| Upstream study | liquids/lib/01_impact_splash_crown.glsl (commit c3a6f6c) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime |
| Source size | 231 lines · 9.2 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT water sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
David Hoskins, hash
Animated19.47-degree Kelvin V-wake interference wave train trailing a moving watercraft.
AnimatedAdvancing and retreating beach wave sheet leaving wet darkened sand and lacy foam.
AnimatedFree-surface Rankine whirlpool depression with spiral capillary ridges and Fresnel sky reflection.
AnimatedMulti-directional Gerstner ocean wave spectrum with subsurface teal scatter and sun glitter.
AnimatedOverlapping circular capillary wave rings from stochastic raindrops hitting calm dark water.
AnimatedClear shallow stream refracting submerged riverbed stones with stationary standing wave crests.