PBR StudyRounded polar ice plates with collision-raised slush rims floating on dark frigid water.
Water & Ice
windward-rime-frost.glsl · 110 lines · GLSL ES 3.00 · MIT
#version 300 es
// Windward Rime Frost (windward-rime-frost.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/02_windward_rime_accretion.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-02-windward-rime-accretion
// Wind-built rime flags on a forked mountain shrub.
// 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 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;
}
void branch(inout vec3 color,vec2 p,vec2 a,vec2 b,float radius,float seed,float softness) {
vec2 axis = normalize(b-a);
vec2 side = vec2(-axis.y,axis.x);
vec2 st = vec2(dot(p-a,axis),dot(p-a,side));
float len = distance(a,b);
float t = clamp(st.x/len,0.0,1.0);
float width = radius*mix(1.0,.24,t);
float barkD = distance(p,mix(a,b,t))-width;
float barkN = .5+.45*clamp(st.y/width,-1.0,1.0);
vec3 bark = mix(vec3(.117,.087,.066),vec3(.48,.345,.23),barkN*fbm(vec2(st.x*16.0,st.y*101.0)));
color = mix(color,bark,edgeMask(barkD,softness));
// Packed lobes have a cellular, granular fracture along the windward face.
// All three branches intercept droplets from the same compass direction.
vec2 wind = normalize(vec2(-.70,.72));
vec2 crosswind = vec2(wind.y,-wind.x);
float projected = dot(p-a,crosswind)/max(.11,dot(axis,crosswind));
float pitch = radius*1.19;
for(int j=-4;j<=4;j++) {
float id = floor(projected/pitch)+float(j);
float s = hash(vec2(id,seed));
float root = (id+.85*s)*pitch;
if(root<0.0 || root>len) continue;
vec2 base = a+axis*root;
float strength = .36+.75*noise2(vec2(root*3.8,seed));
float growth = radius*(1.1+8.8*s)*strength;
vec2 off = p-base;
float h = dot(off,wind)/growth;
float k = clamp(h,0.0,1.0);
float v = dot(off,crosswind)-radius*(s-.38)*k*k*2.6;
float grain = fbm(p*65.0+id);
float scale = radius*(.52+.69*s)*(1.12+.32*sin(4.2*k)-.61*k);
// Stacked lobes sometimes terminate in two blunt, offset feathers.
float cleft = exp(-pow(abs(v/scale-.16)*4.0,2.0));
float cap = (h-1.0)*growth+.90*abs(v)-.43*v
+radius*cleft*(.45+.72*s)*smoothstep(.51,.82,s);
float d = max(max(abs(v)-scale,cap),-h*growth-radius*.52);
d += radius*(.46*(grain-.48)+.19*(noise2(p*153.0)-.5));
float facet = clamp(v/max(.001,scale),-1.0,1.0);
float folded = abs(fract(3.4*facet+1.6*k+grain*.8)-.5);
float light = clamp(.41-.42*facet+.35*k+.47*(grain-.5)+.24*folded,0.0,1.0);
vec3 frost = mix(vec3(.30,.42,.45),vec3(.96,.97,.91),light);
frost *= .86+.14*smoothstep(-.12,.23,h);
color = mix(color,frost,edgeMask(d,softness));
}
}
void main() {
vec2 p = sceneCoord();
float aa = fwidth(p.x)*1.15;
vec3 c = mix(woods(p*.87+vec2(.5,-.52)),vec3(.53,.61,.63),.25);
branch(c,p,vec2(-1.44,-1.31),vec2(.14,1.20),.032,24.3,.009);
branch(c,p,vec2(-.06,-.15),vec2(1.28,.48),.037,13.4,aa);
branch(c,p,vec2(-.43,-.66),vec2(-.44,.47),.032,8.2,aa);
branch(c,p,vec2(-.85,-1.35),vec2(.92,1.34),.073,5.8,aa);
fragColor = vec4(c,1);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Windward Rime Frost — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/02_windward_rime_accretion.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-02-windward-rime-accretion
// Wind-built rime flags on a forked mountain shrub.
// 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 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;
}
void branch(inout vec3 color,vec2 p,vec2 a,vec2 b,float radius,float seed,float softness) {
vec2 axis = normalize(b-a);
vec2 side = vec2(-axis.y,axis.x);
vec2 st = vec2(dot(p-a,axis),dot(p-a,side));
float len = distance(a,b);
float t = clamp(st.x/len,0.0,1.0);
float width = radius*mix(1.0,.24,t);
float barkD = distance(p,mix(a,b,t))-width;
float barkN = .5+.45*clamp(st.y/width,-1.0,1.0);
vec3 bark = mix(vec3(.117,.087,.066),vec3(.48,.345,.23),barkN*fbm(vec2(st.x*16.0,st.y*101.0)));
color = mix(color,bark,edgeMask(barkD,softness));
// Packed lobes have a cellular, granular fracture along the windward face.
// All three branches intercept droplets from the same compass direction.
vec2 wind = normalize(vec2(-.70,.72));
vec2 crosswind = vec2(wind.y,-wind.x);
float projected = dot(p-a,crosswind)/max(.11,dot(axis,crosswind));
float pitch = radius*1.19;
for(int j=-4;j<=4;j++) {
float id = floor(projected/pitch)+float(j);
float s = hash(vec2(id,seed));
float root = (id+.85*s)*pitch;
if(root<0.0 || root>len) continue;
vec2 base = a+axis*root;
float strength = .36+.75*noise2(vec2(root*3.8,seed));
float growth = radius*(1.1+8.8*s)*strength;
vec2 off = p-base;
float h = dot(off,wind)/growth;
float k = clamp(h,0.0,1.0);
float v = dot(off,crosswind)-radius*(s-.38)*k*k*2.6;
float grain = fbm(p*65.0+id);
float scale = radius*(.52+.69*s)*(1.12+.32*sin(4.2*k)-.61*k);
// Stacked lobes sometimes terminate in two blunt, offset feathers.
float cleft = exp(-pow(abs(v/scale-.16)*4.0,2.0));
float cap = (h-1.0)*growth+.90*abs(v)-.43*v
+radius*cleft*(.45+.72*s)*smoothstep(.51,.82,s);
float d = max(max(abs(v)-scale,cap),-h*growth-radius*.52);
d += radius*(.46*(grain-.48)+.19*(noise2(p*153.0)-.5));
float facet = clamp(v/max(.001,scale),-1.0,1.0);
float folded = abs(fract(3.4*facet+1.6*k+grain*.8)-.5);
float light = clamp(.41-.42*facet+.35*k+.47*(grain-.5)+.24*folded,0.0,1.0);
vec3 frost = mix(vec3(.30,.42,.45),vec3(.96,.97,.91),light);
frost *= .86+.14*smoothstep(-.12,.23,h);
color = mix(color,frost,edgeMask(d,softness));
}
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 p = sceneCoord();
float aa = fwidth(p.x)*1.15;
vec3 c = mix(woods(p*.87+vec2(.5,-.52)),vec3(.53,.61,.63),.25);
branch(c,p,vec2(-1.44,-1.31),vec2(.14,1.20),.032,24.3,.009);
branch(c,p,vec2(-.06,-.15),vec2(1.28,.48),.037,13.4,aa);
branch(c,p,vec2(-.43,-.66),vec2(-.44,.47),.032,8.2,aa);
branch(c,p,vec2(-.85,-1.35),vec2(.92,1.34),.073,5.8,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;
// Windward Rime Frost — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/02_windward_rime_accretion.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-02-windward-rime-accretion
// Wind-built rime flags on a forked mountain shrub.
// 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 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;
}
void branch(inout vec3 color,vec2 p,vec2 a,vec2 b,float radius,float seed,float softness) {
vec2 axis = normalize(b-a);
vec2 side = vec2(-axis.y,axis.x);
vec2 st = vec2(dot(p-a,axis),dot(p-a,side));
float len = distance(a,b);
float t = clamp(st.x/len,0.0,1.0);
float width = radius*mix(1.0,.24,t);
float barkD = distance(p,mix(a,b,t))-width;
float barkN = .5+.45*clamp(st.y/width,-1.0,1.0);
vec3 bark = mix(vec3(.117,.087,.066),vec3(.48,.345,.23),barkN*fbm(vec2(st.x*16.0,st.y*101.0)));
color = mix(color,bark,edgeMask(barkD,softness));
// Packed lobes have a cellular, granular fracture along the windward face.
// All three branches intercept droplets from the same compass direction.
vec2 wind = normalize(vec2(-.70,.72));
vec2 crosswind = vec2(wind.y,-wind.x);
float projected = dot(p-a,crosswind)/max(.11,dot(axis,crosswind));
float pitch = radius*1.19;
for(int j=-4;j<=4;j++) {
float id = floor(projected/pitch)+float(j);
float s = hash(vec2(id,seed));
float root = (id+.85*s)*pitch;
if(root<0.0 || root>len) continue;
vec2 base = a+axis*root;
float strength = .36+.75*noise2(vec2(root*3.8,seed));
float growth = radius*(1.1+8.8*s)*strength;
vec2 off = p-base;
float h = dot(off,wind)/growth;
float k = clamp(h,0.0,1.0);
float v = dot(off,crosswind)-radius*(s-.38)*k*k*2.6;
float grain = fbm(p*65.0+id);
float scale = radius*(.52+.69*s)*(1.12+.32*sin(4.2*k)-.61*k);
// Stacked lobes sometimes terminate in two blunt, offset feathers.
float cleft = exp(-pow(abs(v/scale-.16)*4.0,2.0));
float cap = (h-1.0)*growth+.90*abs(v)-.43*v
+radius*cleft*(.45+.72*s)*smoothstep(.51,.82,s);
float d = max(max(abs(v)-scale,cap),-h*growth-radius*.52);
d += radius*(.46*(grain-.48)+.19*(noise2(p*153.0)-.5));
float facet = clamp(v/max(.001,scale),-1.0,1.0);
float folded = abs(fract(3.4*facet+1.6*k+grain*.8)-.5);
float light = clamp(.41-.42*facet+.35*k+.47*(grain-.5)+.24*folded,0.0,1.0);
vec3 frost = mix(vec3(.30,.42,.45),vec3(.96,.97,.91),light);
frost *= .86+.14*smoothstep(-.12,.23,h);
color = mix(color,frost,edgeMask(d,softness));
}
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 p = sceneCoord();
float aa = fwidth(p.x)*1.15;
vec3 c = mix(woods(p*.87+vec2(.5,-.52)),vec3(.53,.61,.63),.25);
branch(c,p,vec2(-1.44,-1.31),vec2(.14,1.20),.032,24.3,.009);
branch(c,p,vec2(-.06,-.15),vec2(1.28,.48),.037,13.4,aa);
branch(c,p,vec2(-.43,-.66),vec2(-.44,.47),.032,8.2,aa);
branch(c,p,vec2(-.85,-1.35),vec2(.92,1.34),.073,5.8,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;
}
// Windward Rime Frost — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/02_windward_rime_accretion.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-02-windward-rime-accretion
// Wind-built rime flags on a forked mountain shrub.
// 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 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;
}
void branch(inout vec3 color,vec2 p,vec2 a,vec2 b,float radius,float seed,float softness) {
vec2 axis = normalize(b-a);
vec2 side = vec2(-axis.y,axis.x);
vec2 st = vec2(dot(p-a,axis),dot(p-a,side));
float len = distance(a,b);
float t = clamp(st.x/len,0.0,1.0);
float width = radius*mix(1.0,.24,t);
float barkD = distance(p,mix(a,b,t))-width;
float barkN = .5+.45*clamp(st.y/width,-1.0,1.0);
vec3 bark = mix(vec3(.117,.087,.066),vec3(.48,.345,.23),barkN*fbm(vec2(st.x*16.0,st.y*101.0)));
color = mix(color,bark,edgeMask(barkD,softness));
// Packed lobes have a cellular, granular fracture along the windward face.
// All three branches intercept droplets from the same compass direction.
vec2 wind = normalize(vec2(-.70,.72));
vec2 crosswind = vec2(wind.y,-wind.x);
float projected = dot(p-a,crosswind)/max(.11,dot(axis,crosswind));
float pitch = radius*1.19;
for(int j=-4;j<=4;j++) {
float id = floor(projected/pitch)+float(j);
float s = hash(vec2(id,seed));
float root = (id+.85*s)*pitch;
if(root<0.0 || root>len) continue;
vec2 base = a+axis*root;
float strength = .36+.75*noise2(vec2(root*3.8,seed));
float growth = radius*(1.1+8.8*s)*strength;
vec2 off = p-base;
float h = dot(off,wind)/growth;
float k = clamp(h,0.0,1.0);
float v = dot(off,crosswind)-radius*(s-.38)*k*k*2.6;
float grain = fbm(p*65.0+id);
float scale = radius*(.52+.69*s)*(1.12+.32*sin(4.2*k)-.61*k);
// Stacked lobes sometimes terminate in two blunt, offset feathers.
float cleft = exp(-pow(abs(v/scale-.16)*4.0,2.0));
float cap = (h-1.0)*growth+.90*abs(v)-.43*v
+radius*cleft*(.45+.72*s)*smoothstep(.51,.82,s);
float d = max(max(abs(v)-scale,cap),-h*growth-radius*.52);
d += radius*(.46*(grain-.48)+.19*(noise2(p*153.0)-.5));
float facet = clamp(v/max(.001,scale),-1.0,1.0);
float folded = abs(fract(3.4*facet+1.6*k+grain*.8)-.5);
float light = clamp(.41-.42*facet+.35*k+.47*(grain-.5)+.24*folded,0.0,1.0);
vec3 frost = mix(vec3(.30,.42,.45),vec3(.96,.97,.91),light);
frost *= .86+.14*smoothstep(-.12,.23,h);
color = mix(color,frost,edgeMask(d,softness));
}
}
void main() {
vec2 p = sceneCoord();
float aa = fwidth(p.x)*1.15;
vec3 c = mix(woods(p*.87+vec2(.5,-.52)),vec3(.53,.61,.63),.25);
branch(c,p,vec2(-1.44,-1.31),vec2(.14,1.20),.032,24.3,.009);
branch(c,p,vec2(-.06,-.15),vec2(1.28,.48),.037,13.4,aa);
branch(c,p,vec2(-.43,-.66),vec2(-.44,.47),.032,8.2,aa);
branch(c,p,vec2(-.85,-1.35),vec2(.92,1.34),.073,5.8,aa);
fragColor = vec4(c,1);
}
`;
export function createWindwardRimeFrostMaterial(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 | windward-rime-frost |
|---|---|
| Category | Water & Ice Shaders · Snow & Glacial Ice |
| Upstream study | ice/lib/02_windward_rime_accretion.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 110 lines · 4.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 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.
AnimatedAdvancing and retreating beach wave sheet leaving wet darkened sand and lacy foam.