PBR StudySinuous turquoise supraglacial streams carved deep into translucent glacier ice.
Water & Ice
glacial-penitente-spikes.glsl · 160 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Glacial Penitente Spikes — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/08_penitente_spikes.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-08-penitente-spikes
// High-altitude penitente field, looking obliquely across eroded ice blades.
// 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;
}
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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
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);
}
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;
// Glacial Penitente Spikes — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/08_penitente_spikes.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-08-penitente-spikes
// High-altitude penitente field, looking obliquely across eroded ice blades.
// 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;
}
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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
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);
}
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;
}
// Glacial Penitente Spikes — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/08_penitente_spikes.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-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);
}
`;
export function createGlacialPenitenteSpikesMaterial(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 | glacial-penitente-spikes |
|---|---|
| Category | Water & Ice Shaders · Snow & Glacial Ice |
| Upstream study | ice/lib/08_penitente_spikes.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 160 lines · 6.6 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 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.
AnimatedAdvancing and retreating beach wave sheet leaving wet darkened sand and lacy foam.
AnimatedFree-surface Rankine whirlpool depression with spiral capillary ridges and Fresnel sky reflection.
AnimatedMulti-directional Gerstner ocean wave spectrum with subsurface teal scatter and sun glitter.