Windward Rime Frost shader

windward-rime-frost.glsl · 110 lines · GLSL ES 3.00 · MIT

Windward Rime FrostWater & Ice
Windward Rime Frost WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 110 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
windward-rime-frost.glsl (110 lines)
#version 300 es
// Windward Rime Frost (windward-rime-frost.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/02_windward_rime_accretion.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-02-windward-rime-accretion
// Wind-built rime flags on a forked mountain shrub.
// 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 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;
}

void branch(inout vec3 color,vec2 p,vec2 a,vec2 b,float radius,float seed,float softness) {
    vec2 axis = normalize(b-a);
    vec2 side = vec2(-axis.y,axis.x);
    vec2 st = vec2(dot(p-a,axis),dot(p-a,side));
    float len = distance(a,b);
    float t = clamp(st.x/len,0.0,1.0);
    float width = radius*mix(1.0,.24,t);
    float barkD = distance(p,mix(a,b,t))-width;
    float barkN = .5+.45*clamp(st.y/width,-1.0,1.0);
    vec3 bark = mix(vec3(.117,.087,.066),vec3(.48,.345,.23),barkN*fbm(vec2(st.x*16.0,st.y*101.0)));
    color = mix(color,bark,edgeMask(barkD,softness));
    // Packed lobes have a cellular, granular fracture along the windward face.
    // All three branches intercept droplets from the same compass direction.
    vec2 wind = normalize(vec2(-.70,.72));
    vec2 crosswind = vec2(wind.y,-wind.x);
    float projected = dot(p-a,crosswind)/max(.11,dot(axis,crosswind));
    float pitch = radius*1.19;
    for(int j=-4;j<=4;j++) {
        float id = floor(projected/pitch)+float(j);
        float s = hash(vec2(id,seed));
        float root = (id+.85*s)*pitch;
        if(root<0.0 || root>len) continue;
        vec2 base = a+axis*root;
        float strength = .36+.75*noise2(vec2(root*3.8,seed));
        float growth = radius*(1.1+8.8*s)*strength;
        vec2 off = p-base;
        float h = dot(off,wind)/growth;
        float k = clamp(h,0.0,1.0);
        float v = dot(off,crosswind)-radius*(s-.38)*k*k*2.6;
        float grain = fbm(p*65.0+id);
        float scale = radius*(.52+.69*s)*(1.12+.32*sin(4.2*k)-.61*k);
        // Stacked lobes sometimes terminate in two blunt, offset feathers.
        float cleft = exp(-pow(abs(v/scale-.16)*4.0,2.0));
        float cap = (h-1.0)*growth+.90*abs(v)-.43*v
                  +radius*cleft*(.45+.72*s)*smoothstep(.51,.82,s);
        float d = max(max(abs(v)-scale,cap),-h*growth-radius*.52);
        d += radius*(.46*(grain-.48)+.19*(noise2(p*153.0)-.5));
        float facet = clamp(v/max(.001,scale),-1.0,1.0);
        float folded = abs(fract(3.4*facet+1.6*k+grain*.8)-.5);
        float light = clamp(.41-.42*facet+.35*k+.47*(grain-.5)+.24*folded,0.0,1.0);
        vec3 frost = mix(vec3(.30,.42,.45),vec3(.96,.97,.91),light);
        frost *= .86+.14*smoothstep(-.12,.23,h);
        color = mix(color,frost,edgeMask(d,softness));
    }
}
void main() {
    vec2 p = sceneCoord();
    float aa = fwidth(p.x)*1.15;
    vec3 c = mix(woods(p*.87+vec2(.5,-.52)),vec3(.53,.61,.63),.25);
    branch(c,p,vec2(-1.44,-1.31),vec2(.14,1.20),.032,24.3,.009);
    branch(c,p,vec2(-.06,-.15),vec2(1.28,.48),.037,13.4,aa);
    branch(c,p,vec2(-.43,-.66),vec2(-.44,.47),.032,8.2,aa);
    branch(c,p,vec2(-.85,-1.35),vec2(.92,1.34),.073,5.8,aa);
    fragColor = vec4(c,1);
}

Mathematical models & shader specifications

Identifierwindward-rime-frost
CategoryWater & Ice Shaders · Snow & Glacial Ice
Upstream studyice/lib/02_windward_rime_accretion.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size110 lines · 4.6 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