Glacial Penitente Spikes shader

glacial-penitente-spikes.glsl · 160 lines · GLSL ES 3.00 · MIT

Glacial Penitente SpikesWater & Ice
Glacial Penitente Spikes WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 160 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
glacial-penitente-spikes.glsl (160 lines)
#version 300 es
// Glacial Penitente Spikes (glacial-penitente-spikes.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/08_penitente_spikes.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-08-penitente-spikes
// High-altitude penitente field, looking obliquely across eroded ice blades.
// 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;
}
mat2 rotate2(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

const vec3 sunlight = vec3(-.75,-.24,.616);
struct Hit { float t; vec3 normal; vec3 local; float seed; };
void clipFace(vec3 ro,vec3 rd,vec3 norm,float limit,inout float nearT,inout float farT,inout vec3 face) {
    float denom = dot(rd,norm);
    float dist = limit-dot(ro,norm);
    if(abs(denom)<.00001) {
        if(dist<0.0) farT = -100.0;
        return;
    }
    float t = dist/denom;
    if(denom<0.0 && t>nearT) { nearT=t; face=norm; }
    if(denom>0.0) farT=min(farT,t);
}
// Inside the convex envelope, carve an irregular, concave-sided spire.
float carved(vec3 local,vec2 axes,float height,float seed) {
    float t = clamp(local.z/height,0.0,1.25);
    vec2 q = local.xy/axes;
    q.x += .17*sin(4.3*t+5.0*seed)*t;
    float breadth = max(.04,1.0-.90*t);
    float twisted = q.x+.12*sin(q.y*6.8+3.1*t+seed);
    float profile = sqrt(twisted*twisted+.74*q.y*q.y);
    float flute = .068*sin(q.y*12.0+3.1*t+seed)+.037*sin(15.0*q.x-2.9*t);
    return profile+pow(t,.75)-1.0+flute*breadth;
}
void blade(inout Hit hit,vec3 ro,vec3 rd,vec2 id) {
    float seed = hash(id+8.3);
    vec2 center = id+.5+.81*(vec2(hash(id+1.9),hash(id+3.8))-.5);
    center.x += .29*sin(id.y*1.17+id.x*.43);
    float spin = -.32+.82*(seed-.5);
    mat2 rotation = rotate2(spin);
    vec3 org = vec3(rotation*(ro.xy-center),ro.z);
    vec3 ray = vec3(rotation*rd.xy,rd.z);
    float height = .35+1.68*seed+.35*sin(id.x*.84+id.y*.49);
    float wide = .23+.25*hash(id+.91), longSide = .47+.23*hash(id+4.2);
    // The sun-facing lean shears every clipping plane consistently.
    vec2 lean = vec2(.17+.34*seed,-.04-.10*seed);
    org.xy -= lean*org.z;
    ray.xy -= lean*ray.z;
    float nearT = .0001, farT = hit.t;
    vec3 face = vec3(0,0,1);
    for(int i=0;i<7;i++) {
        float a = 6.283185*(float(i)+.12*seed)/7.0;
        vec2 direction = vec2(cos(a)/wide,sin(a)/longSide);
        vec3 plane = vec3(direction,(.82+.25*hash(id+float(i)*2.6))/height);
        clipFace(org,ray,plane,1.0,nearT,farT,face);
    }
    clipFace(org,ray,vec3(.45,-.28,1),height*(.85+.14*seed),nearT,farT,face);
    // A secondary scalloped facet truncates one side of the ridge.
    clipFace(org,ray,vec3(-1.28,-.45,.65),height*.60,nearT,farT,face);
    if(nearT>=farT || nearT>=hit.t) return;
    vec2 axes = vec2(wide,longSide);
    float t = nearT;
    vec3 local = org+t*ray;
    float distanceToSurface = carved(local,axes,height,seed);
    for(int j=0;j<16;j++) {
        if(distanceToSurface<.006 || t>=farT) break;
        t += max(.002,distanceToSurface*wide*.65);
        local = org+t*ray;
        distanceToSurface = carved(local,axes,height,seed);
    }
    if(t>=farT || distanceToSurface>.02 || local.z<-.02) return;
    nearT=t;
    if(t>.0011 && distanceToSurface>-.035) {
        float e=.003;
        face=vec3(carved(local+vec3(e,0,0),axes,height,seed)-carved(local-vec3(e,0,0),axes,height,seed),
                  carved(local+vec3(0,e,0),axes,height,seed)-carved(local-vec3(0,e,0),axes,height,seed),
                  carved(local+vec3(0,0,e),axes,height,seed)-carved(local-vec3(0,0,e),axes,height,seed));
    }
    face.z -= dot(face.xy,lean);
    hit = Hit(nearT,normalize(vec3(transpose(rotation)*face.xy,face.z)),local,seed);
}
Hit traceField(vec3 ro,vec3 rd,float maximum,int steps) {
    Hit hit = Hit(maximum,vec3(0,0,1),vec3(0),-1.0);
    // Intersect bounded convex solids in consecutive depth bands.
    float row = floor(ro.y);
    for(int j=0;j<42;j++) {
        if(j>=steps) break;
        float idY = row+float(j);
        float t = (idY+.5-ro.y)/rd.y;
        if(t>hit.t+2.5 || ro.z+t*rd.z>4.1) break;
        float x = floor(ro.x+rd.x*t);
        for(int i=-1;i<=1;i++) blade(hit,ro,rd,vec2(x+float(i),idY));
    }
    return hit;
}
vec3 horizon(vec3 rd) {
    vec2 uv = vec2(rd.x/rd.y,rd.z/rd.y);
    float profile = .087+.075*sin(6.2*uv.x+.6)+.073*fbm(vec2(uv.x*14.0,2));
    float above = uv.y-profile;
    vec3 sky = mix(vec3(.67,.78,.83),vec3(.16,.37,.59),smoothstep(.04,.53,uv.y));
    float rock = fbm(vec2(uv.x*23.0+uv.y*9.0,uv.y*44.0));
    float ravine = sin(33.0*uv.x+11.0*uv.y+3.6*noise2(uv*12.0));
    vec3 mountain = mix(vec3(.37,.41,.45),vec3(.62,.56,.49),rock*.58+.28+.14*ravine);
    mountain = mix(mountain,vec3(.80,.83,.83),smoothstep(.64,.80,rock+.1*ravine+above*.66));
    return mix(mountain,sky,smoothstep(-.0015,.0015,above));
}
void main() {
    vec2 uv = sceneCoord();
    vec3 ro = vec3(.41,-2.53,1.97);
    vec3 rd = normalize(vec3(uv.x*.67,1.0,-.215+.49*uv.y));
    float ground = rd.z<-.001 ? -ro.z/rd.z : 90.0;
    Hit h = traceField(ro,rd,min(ground,45.0),42);
    if(h.seed<0.0 && ground>44.0) {fragColor=vec4(horizon(rd),1);return;}
    vec3 p = ro+h.t*rd;
    vec3 n = h.normal;
    float grains = fbm(p.xy*17.0+p.z*3.8);
    float channels = fbm(vec2((p.x+.27*p.y-.21*p.z)*19.0,p.z*2.9));
    n = normalize(n+vec3(.16*(channels-.5),.15*(grains-.5),0));
    float sun = max(dot(n,sunlight),0.0);
    // Nearby blades occlude direct light in the channels between them.
    Hit blocker = Hit(4.5,vec3(0),vec3(0),-1.0);
    for(int j=-1;j<=1;j++) for(int i=-3;i<=0;i++)
        blade(blocker,p+.019*n,sunlight,floor(p.xy)+vec2(i,j));
    float lit = blocker.seed<0.0 ? 1.0 : .16;
    float cavity = .71+.29*smoothstep(.0,.90,p.z);
    vec3 c = vec3(.48,.61,.69)*cavity+vec3(.49,.39,.27)*sun*lit;
    if(h.seed<0.0) c = mix(c,vec3(.53,.54,.51),.36*fbm(p.xy*2.5));
    c += (.092*channels+.046*grains-.066)*cavity;
    c = mix(c,vec3(.72,.77,.78),smoothstep(8.0,46.0,h.t)*.56);
    fragColor = vec4(c,1);
}

Mathematical models & shader specifications

Identifierglacial-penitente-spikes
CategoryWater & Ice Shaders · Snow & Glacial Ice
Upstream studyice/lib/08_penitente_spikes.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size160 lines · 6.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