Pancake Sea Ice Floes shader

pancake-sea-ice-floes.glsl · 110 lines · GLSL ES 3.00 · MIT

Pancake Sea Ice FloesWater & Ice
Pancake Sea Ice Floes 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
pancake-sea-ice-floes.glsl (110 lines)
#version 300 es
// Pancake Sea Ice Floes (pancake-sea-ice-floes.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/06_pancake_ice_with_raised_rims.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-06-pancake-ice-with-raised-rims
// Pancake ice under a low polar sun. Rafted floes ride above a grease-ice matrix.
// 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; }
mat2 rotate2(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

struct Floe { float h; float salt; float rim; float surface; float shadow; };
void deposit(inout Floe hit,float radius,vec2 d,float seed,float jag,float slush) {
    float shape = length(d)+.06*radius*sin(3.0*atan(d.y,d.x)+seed*8.0)
                  +(.15*jag-.072)*radius;
    float margin = radius-shape;
    float ridgeWidth = radius*(.061+.075*seed)*(.83+.41*slush);
    float ridge = exp(-sq((margin-.86*ridgeWidth)/ridgeWidth));
    ridge *= .56+.44*smoothstep(.28,.65,slush+.16*sin(7.4*d.x+seed*13.0));
    float lift = .034+.065*seed;
    float fractured = smoothstep(.06,.84,slush+.24*sin(15.0*d.x+seed));
    float top = lift+(.057+.065*fractured)*ridge+.016*slush+.011*d.x;
    // An inclined perimeter exposes the darker saturated edge at the waterline.
    float wall = smoothstep(-.014,.017,margin);
    float h = top*wall;
    float contact = exp(-sq((margin+.034)/.047));
    hit.shadow = max(hit.shadow,contact);
    if(h>.001 && (hit.h<.001 || seed>hit.salt)) hit = Floe(h,seed,ridge,smoothstep(.005,.031,margin),hit.shadow);
}
Floe field(vec2 p) {
    Floe h = Floe(0.0,0.0,0.0,0.0,0.0);
    float jag = fbm(p*11.0);
    float slush = fbm(p*14.0);
    for(int level=0;level<2;level++) {
        float spacing = level==0 ? 1.12 : .40;
        vec2 grid = p/spacing+float(level)*3.4;
        for(int j=-1;j<=1;j++) for(int i=-1;i<=1;i++) {
            vec2 id = floor(grid)+vec2(i,j);
            float s = hash(id+5.2);
            if(level==1 && s<.58) continue;
            vec2 center = id+.5+.76*(vec2(hash(id+2.8),hash(id+4.1))-.5);
            vec2 d = (grid-center)*spacing;
            d = rotate2(s*6.28)*d;
            d.y *= .90+.27*hash(id+7.3);
            float r = spacing*(.28+.40*s);
            deposit(h,r,d,level==0?s:.24*s,jag,slush);
        }
    }
    return h;
}
void main() {
    vec2 uv = sceneCoord();
    vec3 rd = normalize(vec3(uv.x*.77,1.0,-.73+uv.y*.38));
    vec3 ro = vec3(.31,-2.05,1.32);
    vec2 p = (ro-rd*ro.z/rd.z).xy;
    Floe base = field(p);
    // The exposed near sidewall connects the top surface to its waterline.
    p += rd.xy/rd.z*.012;
    Floe f = field(p);
    vec2 dx = dFdx(p), dy = dFdy(p);
    float det = dx.x*dy.y-dx.y*dy.x;
    vec2 grad = (dFdx(f.h)*vec2(dy.y,-dy.x)+dFdy(f.h)*vec2(-dx.y,dx.x))/max(.000001,det);
    vec3 n = normalize(vec3(-clamp(grad,vec2(-4),vec2(4))*.66,1));
    vec3 light = normalize(vec3(-.75,.43,.55));
    float direct = max(dot(n,light),0.0);
    float snow = fbm(p*11.0+f.salt);
    float grit = noise2(p*123.0);
    vec3 centerIce = mix(vec3(.40,.49,.50),vec3(.77,.80,.77),.26+.53*snow+.21*f.salt);
    vec3 ridgeIce = mix(vec3(.63,.70,.69),vec3(.96,.95,.86),.35+.6*snow);
    vec3 ice = mix(centerIce,ridgeIce,f.rim)*(.68+.48*direct);
    ice *= .93+.095*grit;
    ice = mix(vec3(.23,.34,.37),ice,f.surface);
    vec2 w = vec2(7.0*p.x+3.0*p.y,24.0*p.y);
    float chop = fbm(w);
    float frazil = smoothstep(.49,.68,fbm(p*vec2(3.5,8.5))+.07*chop);
    vec3 water = mix(vec3(.092,.169,.204),vec3(.46,.55,.56),.57*chop+.31*frazil);
    water += vec3(.20,.18,.13)*smoothstep(.63,.80,chop)*smoothstep(.0,2.7,p.y);
    water *= 1.0-.23*base.shadow;
    water = mix(water,vec3(.37,.48,.49)*(.83+.18*snow),smoothstep(.003,.04,base.h));
    fragColor = vec4(mix(water,ice,smoothstep(.003,.032,f.h)),1);
}

Mathematical models & shader specifications

Identifierpancake-sea-ice-floes
CategoryWater & Ice Shaders · Snow & Glacial Ice
Upstream studyice/lib/06_pancake_ice_with_raised_rims.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size110 lines · 4.5 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