Ribbed Icicle Formation shader

ribbed-icicle-formation.glsl · 114 lines · GLSL ES 3.00 · MIT

Ribbed Icicle FormationWater & Ice
Ribbed Icicle Formation WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 114 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

Snow & Glacial Ice
ribbed-icicle-formation.glsl (114 lines)
#version 300 es
// Ribbed Icicle Formation (ribbed-icicle-formation.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/01_ribbed_icicle_growth.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-ice-lib-01-ribbed-icicle-growth
// Ribbed icicles beneath a snow-covered rock overhang.
// uResolution is the viewport size in pixels. No optional uniforms.
precision highp float;
uniform vec2 uResolution;
out vec4 fragColor;

float hash(vec2 p) {
    vec3 q = fract(p.xyx * vec3(.1031,.11369,.13787));
    q += dot(q,q.yzx+19.19);
    return fract((q.x+q.y)*q.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);
}
vec2 sceneCoord() {
    return (2.0*gl_FragCoord.xy-uResolution)/max(1.0,min(uResolution.x,uResolution.y));
}

float fbm(vec2 p) {
    mat2 twist = mat2(1.68,1.20,-1.20,1.68);
    float sum = 0.0, amplitude = .53;
    for(int i=0;i<4;i++) {
        sum += amplitude*noise2(p);
        p = twist*p+vec2(3.2,7.1);
        amplitude *= .5;
    }
    return sum;
}
float sq(float x) { return x*x; }
float edgeMask(float d,float pixel) {
    return 1.0-smoothstep(-pixel,pixel,d);
}
// Defocused winter woodland behind the focal plane. The same scene is
// sampled through the curved ice, so refraction moves recognizable features.
vec3 woods(vec2 p) {
    vec3 sky = mix(vec3(.78,.83,.79),vec3(.51,.65,.72),smoothstep(-.3,1.35,p.y));
    float thicket = fbm(p*2.5+4.1)-.17*p.y;
    vec3 c = mix(sky,vec3(.215,.262,.209),smoothstep(.32,.68,thicket));
    for(int i=0;i<6;i++) {
        float k = float(i);
        float axis = (k-2.6)*.61+.25*sin(5.3*k)+(.15*sin(8.1*k)+.09)*p.y;
        float width = .024+.05*hash(vec2(k,6));
        float d = abs(p.x-axis)-width;
        c = mix(c,vec3(.20,.205,.175)+.04*k/6.0,.66*edgeMask(d,.068));
    }
    float sun = exp(-dot(p-vec2(-.58,.72),p-vec2(-.58,.72))*2.7);
    return c+vec3(.22,.13,.055)*sun;
}

float profile(float y,float top,float len,float radius,float phase) {
    float t = clamp((top-y)/len,0.0,1.0);
    float wave = y*53.0+phase+.85*sin(7.3*y+phase);
    float ribs = .045*cos(wave)+.010*cos(2.0*wave+.8);
    return radius*(pow(1.0-t,.76)+.30*exp(-12.0*t))*(1.0+ribs*smoothstep(.03,.25,t));
}
vec3 icicle(vec3 bg,vec2 p,float x,float top,float len,float radius,float phase,float blur) {
    float t = clamp((top-p.y)/len,0.0,1.0);
    float axis = x+.047*t*sin(t*3.3+phase);
    float nominal = max(.003,profile(p.y,top,len,radius,phase));
    float crossSection = clamp((p.x-axis)/nominal,-1.0,1.0);
    float frontY = p.y+.078*nominal*sqrt(max(0.0,1.0-crossSection*crossSection))
                     +.014*crossSection*sin(phase+5.0*p.y);
    float width = profile(frontY,top,len,radius,phase);
    float dist = max(abs(p.x-axis)-width,max(p.y-top,top-len-p.y));
    float coverage = edgeMask(dist,blur);
    if(coverage<.001) return bg;
    float u = clamp((p.x-axis)/max(.001,width),-.999,.999);
    float z = sqrt(1.0-u*u);
    float dr = (profile(frontY+.002,top,len,radius,phase)-profile(frontY-.002,top,len,radius,phase))/.004;
    float flute = sin(14.0*asin(u)+1.4*sin(7.0*t+phase));
    vec3 n = normalize(vec3(u+.052*flute,-dr+.039*flute,z));
    vec3 bend = refract(vec3(0,0,-1),n,.763);
    vec3 reflected = reflect(vec3(0,0,-1),n);
    vec3 behind = woods(p+2.0*bend.xy+vec2(.18*sin(phase),0));
    vec3 ice = behind*vec3(.82,.95,1.0)+vec3(.016,.047,.054)*z;
    // Air inclusions follow the interior growth axis in discontinuous trains.
    vec2 grains = vec2(u*19.0,t*141.0)+phase;
    vec2 cell = floor(grains);
    vec2 q = fract(grains)-.22-.55*vec2(hash(cell),hash(cell+2.4));
    float bubble = exp(-13.0*dot(q,q))*step(.86,hash(cell+5.7));
    ice += bubble*.14*z+.035*(fbm(vec2(u*12.0,t*4.0))-.5);
    float rim = .025+.78*pow(1.0-z,3.0);
    vec3 sky = woods(reflected.xy*1.9+vec2(0,.71))+.14;
    ice = mix(ice,sky,rim);
    float strip = exp(-sq((reflected.x+.64)/.16))*smoothstep(-.33,.72,reflected.y+.54);
    ice += vec3(.48,.55,.56)*strip+.18*pow(max(dot(reflected,normalize(vec3(-.5,.64,.58))),0.0),29.0);
    return mix(bg,ice,coverage);
}
void main() {
    vec2 p = sceneCoord();
    float aa = fwidth(p.x);
    vec3 c = woods(p);
    c = icicle(c,p,-.90,1.08,1.10,.12,1.4,.010);
    c = icicle(c,p,.74,1.13,1.30,.13,5.0,.011);
    c = icicle(c,p,-.34,.86,1.72,.24,2.6,aa);
    c = icicle(c,p,-.009,.92,.96,.13,5.6,aa);
    c = icicle(c,p,.46,.99,1.49,.15,4.9,aa);
    c = icicle(c,p,-1.15,.91,.99,.12,6.4,aa);
    c = icicle(c,p,1.17,1.03,1.56,.18,3.5,aa);
    float underside = .78+.085*sin(2.7*p.x)+.17*(fbm(vec2(p.x*8.0,2.3))-.5);
    float snowline = underside+.074+.05*noise2(vec2(p.x*12.0,3));
    vec3 rock = mix(vec3(.20,.22,.19),vec3(.46,.44,.34),fbm(p*37.0));
    c = mix(c,rock,1.0-edgeMask(p.y-underside,aa));
    vec3 snow = mix(vec3(.46,.59,.60),vec3(.90,.92,.87),smoothstep(-.006,.075,p.y-snowline));
    c = mix(c,snow+.035*(noise2(p*118.0)-.5),1.0-edgeMask(p.y-snowline,aa));
    fragColor = vec4(c,1);
}

Mathematical models & shader specifications

Identifierribbed-icicle-formation
CategoryWater & Ice Shaders · Snow & Glacial Ice
Upstream studyice/lib/01_ribbed_icicle_growth.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size114 lines · 4.9 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT ice 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