Water Impact Splash Crown shader

water-impact-splash-crown.glsl · 231 lines · GLSL ES 3.00 · MIT

Water Impact Splash CrownWater & Ice
Water Impact Splash Crown WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 231 linesSPEC GLSL ES 3.00

Seamless PNG Texture Baker
1-Click Engine Shader Export
WebGL2 .glsl
.glsl
Godot 4 .gdshader
Three.js GLSL3

Engine shader code & wrappers

Dynamic Liquids
water-impact-splash-crown.glsl (231 lines)
#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);
}

Mathematical models & shader specifications

Identifierwater-impact-splash-crown
CategoryWater & Ice Shaders · Dynamic Liquids
Upstream studyliquids/lib/01_impact_splash_crown.glsl (commit c3a6f6c)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime
Source size231 lines · 9.2 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT water sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Procedural signed-distance and analytic surface shading

Adapted upstream mathematical helpers

David Hoskins, hash

All water & ice shaders