PBR StudyFeathery granular rime ice feathers accreting into freezing alpine wind.
Water & Ice
ribbed-icicle-formation.glsl · 114 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Ribbed Icicle Formation — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/01_ribbed_icicle_growth.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// 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.
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*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
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);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float out_alpha = study_col.a * COLOR.a;
if (u_luma_alpha_key) {
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
out_alpha *= smoothstep(0.035, 0.22, luma);
}
COLOR = vec4(tinted, out_alpha);
}
shader_type spatial;
render_mode cull_disabled;
// Ribbed Icicle Formation — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/01_ribbed_icicle_growth.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 1;
uniform bool u_luma_alpha_key = false;
// 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.
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*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
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);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
ALBEDO = tinted;
ROUGHNESS = clamp(0.85 - luma * 0.45, 0.08, 0.96);
METALLIC = 0.04;
EMISSION = tinted * 0.0;
}
// Ribbed Icicle Formation — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/01_ribbed_icicle_growth.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
// 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);
}
`;
export function createRibbedIcicleFormationMaterial(width = 1024, height = 1024) {
const material = new THREE.ShaderMaterial({
glslVersion: THREE.GLSL3,
vertexShader,
fragmentShader,
uniforms: {
uResolution: { value: new THREE.Vector2(width, height) },
uTime: { value: 1.2 },
uOpen: { value: 0.0 },
uLightMode: { value: 0 },
uCamMode: { value: 1 },
},
});
return {
material,
update(elapsedSeconds) {
material.uniforms.uTime.value = elapsedSeconds * 1.0;
},
resize(nextW, nextH) {
material.uniforms.uResolution.value.set(nextW, nextH);
},
};
}
| Identifier | ribbed-icicle-formation |
|---|---|
| Category | Water & Ice Shaders · Snow & Glacial Ice |
| Upstream study | ice/lib/01_ribbed_icicle_growth.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 114 lines · 4.9 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT ice sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
David Hoskins, hash
PBR StudyFeathery granular rime ice feathers accreting into freezing alpine wind.
PBR StudyRounded polar ice plates with collision-raised slush rims floating on dark frigid water.
PBR StudySun-ablated high-altitude snow blades with subsurface cyan scattering in deep hollows.
PBR StudySinuous turquoise supraglacial streams carved deep into translucent glacier ice.
AnimatedAnimated Rayleigh-instability liquid crown rim ejecting droplets over concentric pond ripples.
Animated19.47-degree Kelvin V-wake interference wave train trailing a moving watercraft.