Glacial Meltwater Channels shader

glacial-meltwater-channels.glsl · 98 lines · GLSL ES 3.00 · MIT

Glacial Meltwater ChannelsWater & Ice
Glacial Meltwater Channels WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 98 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-meltwater-channels.glsl (98 lines)
#version 300 es
// Glacial Meltwater Channels (glacial-meltwater-channels.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/11_meltwater_channels_incised_into_ice.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-11-meltwater-channels-incised-into-ice
// Supraglacial stream | near-vertical ice banks enclosing a lower water surface.
// uResolution: viewport in pixels. No optional uniforms.
precision highp float;
uniform vec2 uResolution;
out vec4 fragColor;

const float PI=3.14159265;
const float TAU=6.28318531;
float hash(vec2 p){
    vec3 q=fract(vec3(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 fbm(vec2 p){
    mat2 turn=mat2(.8,.6,-.6,.8);
    return .55*noise2(p)+.27*noise2(turn*p*2.13+5.)
         +.13*noise2(p*4.57-9.)+.05*noise2(turn*p*9.12);
}
float gauss(float x){return exp(-x*x);}
float pixel(){return 2./min(uResolution.x,uResolution.y);}
vec2 viewport(){return (2.*gl_FragCoord.xy-uResolution)*(.5*pixel());}

float center(float y){return .29*sin(2.8*y+.46)+.11*sin(5.4*y-.35)-.12*y;}
float channel(vec2 p){
    float x=p.x-center(p.y);
    float width=.249+.068*sin(2.1*p.y+.3)+.048*gauss(2.*(p.y+.3));
    float mainCut=abs(x)-width;
    float tributary=abs(p.y-.35-.80*x-.071*sin(6.*x))-.113;
    return min(mainCut,max(tributary,-x))+.014*(noise2(p*16.)-.5);
}
float top(vec2 p){return .142+.060*fbm(p*3.2)+.007*noise2(p*23.);}
float solid(vec2 p){
    float d=channel(p);
    float erosion=smoothstep(-.061,.050,d);
    return mix(-.28+.037*noise2(p*11.),top(p),erosion);
}
vec3 shade(vec2 screen){
    vec2 uv=screen*1.04;
    // Camera looks across and down the stream. One bank occludes parts of
    // the water and the steep opposite face remains visible above its waterline.
    vec2 drift=vec2(.47,.62);
    const float waterLevel=-.063;
    float hi=.36,lo=hi;
    for(int i=0;i<48;i++){
        lo=hi-.016;
        if(lo<=max(waterLevel,solid(uv-lo*drift)))break;
        hi=lo;
    }
    for(int i=0;i<6;i++){
        float m=(hi+lo)*.5;
        if(m>max(waterLevel,solid(uv-m*drift)))hi=m;else lo=m;
    }
    float h=(lo+hi)*.5; vec2 p=uv-h*drift;
    float d=channel(p),crest=top(p),bank=1.-smoothstep(.012,.086,h-crest+.087);
    float water=1.-smoothstep(.0004,.0025,h-waterLevel);
    vec2 q=vec2(p.x+.074*sin(p.y*3.)+.04*noise2(p*7.),p.y);
    float bubbles=fbm(q*vec2(21.,55.));
    vec2 flow=vec2(p.x-center(p.y),p.y);
    float wave=fbm(flow*vec2(22.,55.)+1.1*noise2(flow*12.));
    float ripple=sin(93.*p.y+11.*sin(12.*p.x+4.*p.y)+7.*noise2(p*16.));
    vec3 pos=vec3(p,h+.0021*bubbles+.0015*ripple*water);
    vec3 n=normalize(cross(dFdx(pos),dFdy(pos)));
    vec3 sun=normalize(vec3(-.66,.43,.71));
    float diffuse=max(dot(n,sun),0.);
    float seam=gauss((h-.075-.034*sin(p.y*3.1)-.022*noise2(p*7.))/.011);
    float chip=noise2(p*136.);
    float layers=fbm(q*vec2(36.,4.)+.53*fbm(p*8.));
    float hairline=gauss((p.x+.54+.16*p.y+.071*sin(5.*p.y)+.014*noise2(p*26.))/.006);
    vec3 ice=mix(vec3(.51,.72,.80),vec3(.94,.97,.97),.58*bubbles+.42*layers);
    ice*=1.-.17*hairline;
    float wallGrain=fbm(vec2(p.y*19.+p.x*9.,h*21.));
    float inclusions=smoothstep(.56,.71,fbm(vec2(p.y*130.,h*145.)));
    vec3 wall=mix(vec3(.25,.55,.65),vec3(.63,.83,.85),wallGrain)+.09*seam+.09*inclusions;
    vec3 c=mix(ice,wall,bank)*(.78+.32*diffuse)+.019*(chip-.5);
    float depth=waterLevel-solid(p+vec2(.018,.012));
    vec3 liquid=mix(vec3(.28,.67,.66),vec3(.025,.36,.47),smoothstep(0.,.22,depth));
    float shoreShadow=exp(-abs(d+.064)*7.)*(.5+.5*sin(p.y*4.));
    liquid*=.92-.32*shoreShadow;
    float sky=wave*.64+.36*noise2(flow*vec2(8.,17.));
    liquid+=vec3(.15,.21,.20)*smoothstep(.31,.72,sky);
    liquid+=vec3(.13,.18,.16)*smoothstep(.54,.74,wave)*smoothstep(.25,.97,ripple);
    c=mix(c,liquid,water);
    return c;
}
void main(){
    vec2 p=viewport(), offset=pixel()*vec2(.24,.17);
    fragColor=vec4(.5*(shade(p-offset)+shade(p+offset)),1.);
}

Mathematical models & shader specifications

Identifierglacial-meltwater-channels
CategoryWater & Ice Shaders · Snow & Glacial Ice
Upstream studyice/lib/11_meltwater_channels_incised_into_ice.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size98 lines · 4.0 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