Whirlpool Vortex Funnel shader

whirlpool-vortex-funnel.glsl · 143 lines · GLSL ES 3.00 · MIT

Whirlpool Vortex FunnelWater & Ice
Whirlpool Vortex Funnel WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 143 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
whirlpool-vortex-funnel.glsl (143 lines)
#version 300 es
// Whirlpool Vortex Funnel (whirlpool-vortex-funnel.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/liquids/lib/11_draining_vortex_funnel.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-11-draining-vortex-funnel
// Side view through a draining tank. An air core narrows into the outlet.
// uResolution: framebuffer dimensions in pixels. Optional uTime: seconds (default 0).
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
out vec4 fragColor;
const float PI=3.14159265;
vec2 frame() {
    return (2.*gl_FragCoord.xy-uResolution)/min(uResolution.x,uResolution.y);
}

float hash(vec2 p) {
    vec3 q=fract(p.xyx*vec3(.1031,.1030,.0973));
    q+=dot(q,q.yzx+33.33);
    return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p) {
    vec2 i=floor(p),f=fract(p);
    f=f*f*(3.-2.*f);
    return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
               mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float terrain(vec2 p) {
    mat2 m=mat2(1.62,1.19,-1.19,1.62);
    return .54*noise2(p)+.27*noise2(m*p+7.1)+.13*noise2(m*m*p+19.)+
           .06*noise2(m*m*m*p-8.3);
}

vec3 studio(vec3 d) {
    vec3 c=mix(vec3(.055,.093,.102),vec3(.48,.61,.62),smoothstep(-.76,.87,d.y));
    float panel=smoothstep(-.8,-.76,d.x)*(1.-smoothstep(-.33,-.28,d.x))
               *smoothstep(-.1,-.04,d.y)*(1.-smoothstep(.88,.93,d.y));
    float strip=exp(-20.*abs(d.x-.68-.13*d.y))*smoothstep(-.55,.20,d.y);
    return c+vec3(1.,.94,.79)*panel+vec3(.65,.81,.91)*strip;
}

const float waterline=.47;
float center(float y,float t) {
    return .026*sin(3.4*y+.86*t)+.034*sin(1.72*t+2.8*y)*smoothstep(0.,1.,waterline-y);
}
float surface(vec2 p,float t) {
    float r=length(p);
    float depression=pow(.123/(r+.098),2.);
    float a=atan(p.y,p.x+.00001);
    return waterline-depression+.010*sin(3.*a+13.*r-1.8*t)*exp(-1.9*r)
           +.003*sin(16.*p.x-10.*p.y-t);
}
float field(vec3 p,float t) {
    return p.y-surface(vec2(p.x-center(p.y,t),p.z),t);
}
vec3 back(vec2 p) {
    float window=exp(-3.8*abs(p.x+.40-.11*p.y));
    float second=exp(-5.4*abs(p.x-.88+.20*p.y));
    float frameLight=exp(-16.*abs(p.x+.68+.08*p.y));
    return mix(vec3(.22,.30,.31),vec3(.87,.82,.65),.40+.34*window+.16*second+.07*p.y)
          +vec3(.15,.16,.14)*frameLight;
}
vec3 tank(vec2 p,float t) {
    float depth=waterline-p.y;
    vec2 q=p+vec2(.018*sin(5.*p.y+t),.012*sin(4.*p.x-.6*t));
    vec3 water=back(q)*exp(-vec3(.39,.15,.075)*clamp(depth+.36,.0,2.));
    water+=vec3(.012,.057,.060);
    // An etched column of graduations on the far wall supplies scale through the core.
    float ruled=abs(fract((q.y+.038)*12.)-.5);
    float tick=(1.-smoothstep(.013,.033,ruled))*smoothstep(-.94,-.93,q.x)
              *(1.-smoothstep(-.88,-.87,q.x));
    water*=1.-.48*tick;
    float floorY=-.75+.033*p.x;
    float bottom=(1.-smoothstep(floorY-.025,floorY+.025,p.y));
    float metal=.50+.13*noise2(vec2(14.*p.x,165.*p.y))+.15*exp(-8.*abs(p.x+.33));
    float hole=length(vec2((p.x-center(-.74,t))/.14,(p.y-floorY)/.027));
    vec3 floorCol=mix(vec3(.70,.76,.70)*metal,vec3(.066,.096,.09),1.-smoothstep(.68,1.,hole));
    water=mix(water,floorCol,bottom);
    water=mix(water,vec3(.20,.29,.27),.5*(1.-smoothstep(.002,.015,abs(p.y-floorY))));
    return water;
}
void main() {
    vec2 p=frame(); float t=uTime+6.48;
    float worldY=p.y,viewSlope=.20;
    // Ray from the rear of the lens into the tank, sampled along the viewing axis.
    // For each sample the rotational free surface partitions air from water.
    float entry=10.,exitPoint=10.; bool previous=false;
    for(int i=0;i<=98;i++) {
        float z=1.22-.025*float(i);
        vec3 pos=vec3(p.x,worldY+viewSlope*z,z);
        bool air=field(pos,t)>0.;
        if(i>0 && air!=previous) {
            float left=z,right=z+.025;
            for(int j=0;j<6;j++) {
                float m=.5*(left+right);
                bool mid=field(vec3(p.x,worldY+viewSlope*m,m),t)>0.;
                if(mid==air) left=m; else right=m;
            }
            float crossing=.5*(left+right);
            if(entry>5.) entry=crossing; else exitPoint=crossing;
            // For a ray descending from above, the first crossing can be the
            // nearly flat surface in front of the funnel. Prefer its curved wall.
            if(exitPoint<5. && abs(crossing)<.68) break;
        }
        previous=air;
    }
    float frontLine=waterline-.21+.007*sin(5.*p.x+.58*t);
    float backLine=waterline+.22+.005*sin(7.*p.x-.64*t);
    vec3 col=mix(tank(p,t),back(p),smoothstep(backLine-.004,backLine+.004,p.y));
    if(p.y>frontLine && p.y<backLine) {
        float zz=clamp((waterline-p.y)/viewSlope,-1.2,1.2);
        float rr=length(vec2(p.x,zz));
        float ripple=sin(26.*rr+1.5*sin(2.2*p.x)-1.6*t);
        col=mix(col,vec3(.65,.74,.70),.18+.095*ripple*exp(-.9*rr));
    }
    if(entry<5. && p.y>-.76) {
        float z=entry;
        if(exitPoint<5. && abs(entry)>.49) z=exitPoint;
        vec3 point=vec3(p.x,worldY+viewSlope*z,z);
        vec3 ray=normalize(vec3(0.,-.20,-1.));
        vec2 e=vec2(.002,0.);
        vec3 n=normalize(vec3(field(point+e.xyy,t)-field(point-e.xyy,t),
                              field(point+e.yxy,t)-field(point-e.yxy,t),
                              field(point+e.yyx,t)-field(point-e.yyx,t)));
        if(dot(n,ray)>0.) n=-n;
        vec3 ref=reflect(ray,n);
        float fres=.04+.85*pow(1.-abs(dot(n,-ray)),3.);
        vec2 xz=vec2(point.x-center(point.y,t),z);
        float depth=clamp(waterline-point.y,0.,1.25);
        vec3 lens=tank(p+.32*n.xy,t);
        vec3 core=mix(lens*vec3(.81,.92,.95),studio(ref),.18+.64*fres);
        float strip=exp(-10.*abs(ref.x-.52*ref.y+.37));
        core+=vec3(.34,.38,.34)*strip;
        float angle=atan(xz.y,xz.x+.00001);
        float dyePhase=angle+5.*log(depth+.046)-1.06*t;
        float ribbon=.5+.5*cos(dyePhase);
        float dye=smoothstep(.962,.989,ribbon)*smoothstep(.02,.15,depth);
        core=mix(core,vec3(.56,.17,.075),.65*dye);
        float surfaceWeight=.32+.68*smoothstep(.009,.065,depth);
        col=mix(col,core,surfaceWeight*smoothstep(-.76,-.73,point.y));
    }
    col+=vec3(.16,.20,.16)*exp(-abs(p.y-frontLine)/.006);
    fragColor=vec4(col,1.);
}

Mathematical models & shader specifications

Identifierwhirlpool-vortex-funnel
CategoryWater & Ice Shaders · Dynamic Liquids
Upstream studyliquids/lib/11_draining_vortex_funnel.glsl (commit c3a6f6c)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime
Source size143 lines · 6.1 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