PBR StudySun-ablated high-altitude snow blades with subsurface cyan scattering in deep hollows.
Water & Ice
pancake-sea-ice-floes.glsl · 110 lines · GLSL ES 3.00 · MIT
#version 300 es
// Pancake Sea Ice Floes (pancake-sea-ice-floes.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/06_pancake_ice_with_raised_rims.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-06-pancake-ice-with-raised-rims
// Pancake ice under a low polar sun. Rafted floes ride above a grease-ice matrix.
// 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; }
mat2 rotate2(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
struct Floe { float h; float salt; float rim; float surface; float shadow; };
void deposit(inout Floe hit,float radius,vec2 d,float seed,float jag,float slush) {
float shape = length(d)+.06*radius*sin(3.0*atan(d.y,d.x)+seed*8.0)
+(.15*jag-.072)*radius;
float margin = radius-shape;
float ridgeWidth = radius*(.061+.075*seed)*(.83+.41*slush);
float ridge = exp(-sq((margin-.86*ridgeWidth)/ridgeWidth));
ridge *= .56+.44*smoothstep(.28,.65,slush+.16*sin(7.4*d.x+seed*13.0));
float lift = .034+.065*seed;
float fractured = smoothstep(.06,.84,slush+.24*sin(15.0*d.x+seed));
float top = lift+(.057+.065*fractured)*ridge+.016*slush+.011*d.x;
// An inclined perimeter exposes the darker saturated edge at the waterline.
float wall = smoothstep(-.014,.017,margin);
float h = top*wall;
float contact = exp(-sq((margin+.034)/.047));
hit.shadow = max(hit.shadow,contact);
if(h>.001 && (hit.h<.001 || seed>hit.salt)) hit = Floe(h,seed,ridge,smoothstep(.005,.031,margin),hit.shadow);
}
Floe field(vec2 p) {
Floe h = Floe(0.0,0.0,0.0,0.0,0.0);
float jag = fbm(p*11.0);
float slush = fbm(p*14.0);
for(int level=0;level<2;level++) {
float spacing = level==0 ? 1.12 : .40;
vec2 grid = p/spacing+float(level)*3.4;
for(int j=-1;j<=1;j++) for(int i=-1;i<=1;i++) {
vec2 id = floor(grid)+vec2(i,j);
float s = hash(id+5.2);
if(level==1 && s<.58) continue;
vec2 center = id+.5+.76*(vec2(hash(id+2.8),hash(id+4.1))-.5);
vec2 d = (grid-center)*spacing;
d = rotate2(s*6.28)*d;
d.y *= .90+.27*hash(id+7.3);
float r = spacing*(.28+.40*s);
deposit(h,r,d,level==0?s:.24*s,jag,slush);
}
}
return h;
}
void main() {
vec2 uv = sceneCoord();
vec3 rd = normalize(vec3(uv.x*.77,1.0,-.73+uv.y*.38));
vec3 ro = vec3(.31,-2.05,1.32);
vec2 p = (ro-rd*ro.z/rd.z).xy;
Floe base = field(p);
// The exposed near sidewall connects the top surface to its waterline.
p += rd.xy/rd.z*.012;
Floe f = field(p);
vec2 dx = dFdx(p), dy = dFdy(p);
float det = dx.x*dy.y-dx.y*dy.x;
vec2 grad = (dFdx(f.h)*vec2(dy.y,-dy.x)+dFdy(f.h)*vec2(-dx.y,dx.x))/max(.000001,det);
vec3 n = normalize(vec3(-clamp(grad,vec2(-4),vec2(4))*.66,1));
vec3 light = normalize(vec3(-.75,.43,.55));
float direct = max(dot(n,light),0.0);
float snow = fbm(p*11.0+f.salt);
float grit = noise2(p*123.0);
vec3 centerIce = mix(vec3(.40,.49,.50),vec3(.77,.80,.77),.26+.53*snow+.21*f.salt);
vec3 ridgeIce = mix(vec3(.63,.70,.69),vec3(.96,.95,.86),.35+.6*snow);
vec3 ice = mix(centerIce,ridgeIce,f.rim)*(.68+.48*direct);
ice *= .93+.095*grit;
ice = mix(vec3(.23,.34,.37),ice,f.surface);
vec2 w = vec2(7.0*p.x+3.0*p.y,24.0*p.y);
float chop = fbm(w);
float frazil = smoothstep(.49,.68,fbm(p*vec2(3.5,8.5))+.07*chop);
vec3 water = mix(vec3(.092,.169,.204),vec3(.46,.55,.56),.57*chop+.31*frazil);
water += vec3(.20,.18,.13)*smoothstep(.63,.80,chop)*smoothstep(.0,2.7,p.y);
water *= 1.0-.23*base.shadow;
water = mix(water,vec3(.37,.48,.49)*(.83+.18*snow),smoothstep(.003,.04,base.h));
fragColor = vec4(mix(water,ice,smoothstep(.003,.032,f.h)),1);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Pancake Sea Ice Floes — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/06_pancake_ice_with_raised_rims.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-06-pancake-ice-with-raised-rims
// Pancake ice under a low polar sun. Rafted floes ride above a grease-ice matrix.
// 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; }
mat2 rotate2(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
struct Floe { float h; float salt; float rim; float surface; float shadow; };
void deposit(inout Floe hit,float radius,vec2 d,float seed,float jag,float slush) {
float shape = length(d)+.06*radius*sin(3.0*atan(d.y,d.x)+seed*8.0)
+(.15*jag-.072)*radius;
float margin = radius-shape;
float ridgeWidth = radius*(.061+.075*seed)*(.83+.41*slush);
float ridge = exp(-sq((margin-.86*ridgeWidth)/ridgeWidth));
ridge *= .56+.44*smoothstep(.28,.65,slush+.16*sin(7.4*d.x+seed*13.0));
float lift = .034+.065*seed;
float fractured = smoothstep(.06,.84,slush+.24*sin(15.0*d.x+seed));
float top = lift+(.057+.065*fractured)*ridge+.016*slush+.011*d.x;
// An inclined perimeter exposes the darker saturated edge at the waterline.
float wall = smoothstep(-.014,.017,margin);
float h = top*wall;
float contact = exp(-sq((margin+.034)/.047));
hit.shadow = max(hit.shadow,contact);
if(h>.001 && (hit.h<.001 || seed>hit.salt)) hit = Floe(h,seed,ridge,smoothstep(.005,.031,margin),hit.shadow);
}
Floe field(vec2 p) {
Floe h = Floe(0.0,0.0,0.0,0.0,0.0);
float jag = fbm(p*11.0);
float slush = fbm(p*14.0);
for(int level=0;level<2;level++) {
float spacing = level==0 ? 1.12 : .40;
vec2 grid = p/spacing+float(level)*3.4;
for(int j=-1;j<=1;j++) for(int i=-1;i<=1;i++) {
vec2 id = floor(grid)+vec2(i,j);
float s = hash(id+5.2);
if(level==1 && s<.58) continue;
vec2 center = id+.5+.76*(vec2(hash(id+2.8),hash(id+4.1))-.5);
vec2 d = (grid-center)*spacing;
d = rotate2(s*6.28)*d;
d.y *= .90+.27*hash(id+7.3);
float r = spacing*(.28+.40*s);
deposit(h,r,d,level==0?s:.24*s,jag,slush);
}
}
return h;
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = sceneCoord();
vec3 rd = normalize(vec3(uv.x*.77,1.0,-.73+uv.y*.38));
vec3 ro = vec3(.31,-2.05,1.32);
vec2 p = (ro-rd*ro.z/rd.z).xy;
Floe base = field(p);
// The exposed near sidewall connects the top surface to its waterline.
p += rd.xy/rd.z*.012;
Floe f = field(p);
vec2 dx = dFdx(p), dy = dFdy(p);
float det = dx.x*dy.y-dx.y*dy.x;
vec2 grad = (dFdx(f.h)*vec2(dy.y,-dy.x)+dFdy(f.h)*vec2(-dx.y,dx.x))/max(.000001,det);
vec3 n = normalize(vec3(-clamp(grad,vec2(-4),vec2(4))*.66,1));
vec3 light = normalize(vec3(-.75,.43,.55));
float direct = max(dot(n,light),0.0);
float snow = fbm(p*11.0+f.salt);
float grit = noise2(p*123.0);
vec3 centerIce = mix(vec3(.40,.49,.50),vec3(.77,.80,.77),.26+.53*snow+.21*f.salt);
vec3 ridgeIce = mix(vec3(.63,.70,.69),vec3(.96,.95,.86),.35+.6*snow);
vec3 ice = mix(centerIce,ridgeIce,f.rim)*(.68+.48*direct);
ice *= .93+.095*grit;
ice = mix(vec3(.23,.34,.37),ice,f.surface);
vec2 w = vec2(7.0*p.x+3.0*p.y,24.0*p.y);
float chop = fbm(w);
float frazil = smoothstep(.49,.68,fbm(p*vec2(3.5,8.5))+.07*chop);
vec3 water = mix(vec3(.092,.169,.204),vec3(.46,.55,.56),.57*chop+.31*frazil);
water += vec3(.20,.18,.13)*smoothstep(.63,.80,chop)*smoothstep(.0,2.7,p.y);
water *= 1.0-.23*base.shadow;
water = mix(water,vec3(.37,.48,.49)*(.83+.18*snow),smoothstep(.003,.04,base.h));
fragColor = vec4(mix(water,ice,smoothstep(.003,.032,f.h)),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;
// Pancake Sea Ice Floes — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/06_pancake_ice_with_raised_rims.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-06-pancake-ice-with-raised-rims
// Pancake ice under a low polar sun. Rafted floes ride above a grease-ice matrix.
// 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; }
mat2 rotate2(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
struct Floe { float h; float salt; float rim; float surface; float shadow; };
void deposit(inout Floe hit,float radius,vec2 d,float seed,float jag,float slush) {
float shape = length(d)+.06*radius*sin(3.0*atan(d.y,d.x)+seed*8.0)
+(.15*jag-.072)*radius;
float margin = radius-shape;
float ridgeWidth = radius*(.061+.075*seed)*(.83+.41*slush);
float ridge = exp(-sq((margin-.86*ridgeWidth)/ridgeWidth));
ridge *= .56+.44*smoothstep(.28,.65,slush+.16*sin(7.4*d.x+seed*13.0));
float lift = .034+.065*seed;
float fractured = smoothstep(.06,.84,slush+.24*sin(15.0*d.x+seed));
float top = lift+(.057+.065*fractured)*ridge+.016*slush+.011*d.x;
// An inclined perimeter exposes the darker saturated edge at the waterline.
float wall = smoothstep(-.014,.017,margin);
float h = top*wall;
float contact = exp(-sq((margin+.034)/.047));
hit.shadow = max(hit.shadow,contact);
if(h>.001 && (hit.h<.001 || seed>hit.salt)) hit = Floe(h,seed,ridge,smoothstep(.005,.031,margin),hit.shadow);
}
Floe field(vec2 p) {
Floe h = Floe(0.0,0.0,0.0,0.0,0.0);
float jag = fbm(p*11.0);
float slush = fbm(p*14.0);
for(int level=0;level<2;level++) {
float spacing = level==0 ? 1.12 : .40;
vec2 grid = p/spacing+float(level)*3.4;
for(int j=-1;j<=1;j++) for(int i=-1;i<=1;i++) {
vec2 id = floor(grid)+vec2(i,j);
float s = hash(id+5.2);
if(level==1 && s<.58) continue;
vec2 center = id+.5+.76*(vec2(hash(id+2.8),hash(id+4.1))-.5);
vec2 d = (grid-center)*spacing;
d = rotate2(s*6.28)*d;
d.y *= .90+.27*hash(id+7.3);
float r = spacing*(.28+.40*s);
deposit(h,r,d,level==0?s:.24*s,jag,slush);
}
}
return h;
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = sceneCoord();
vec3 rd = normalize(vec3(uv.x*.77,1.0,-.73+uv.y*.38));
vec3 ro = vec3(.31,-2.05,1.32);
vec2 p = (ro-rd*ro.z/rd.z).xy;
Floe base = field(p);
// The exposed near sidewall connects the top surface to its waterline.
p += rd.xy/rd.z*.012;
Floe f = field(p);
vec2 dx = dFdx(p), dy = dFdy(p);
float det = dx.x*dy.y-dx.y*dy.x;
vec2 grad = (dFdx(f.h)*vec2(dy.y,-dy.x)+dFdy(f.h)*vec2(-dx.y,dx.x))/max(.000001,det);
vec3 n = normalize(vec3(-clamp(grad,vec2(-4),vec2(4))*.66,1));
vec3 light = normalize(vec3(-.75,.43,.55));
float direct = max(dot(n,light),0.0);
float snow = fbm(p*11.0+f.salt);
float grit = noise2(p*123.0);
vec3 centerIce = mix(vec3(.40,.49,.50),vec3(.77,.80,.77),.26+.53*snow+.21*f.salt);
vec3 ridgeIce = mix(vec3(.63,.70,.69),vec3(.96,.95,.86),.35+.6*snow);
vec3 ice = mix(centerIce,ridgeIce,f.rim)*(.68+.48*direct);
ice *= .93+.095*grit;
ice = mix(vec3(.23,.34,.37),ice,f.surface);
vec2 w = vec2(7.0*p.x+3.0*p.y,24.0*p.y);
float chop = fbm(w);
float frazil = smoothstep(.49,.68,fbm(p*vec2(3.5,8.5))+.07*chop);
vec3 water = mix(vec3(.092,.169,.204),vec3(.46,.55,.56),.57*chop+.31*frazil);
water += vec3(.20,.18,.13)*smoothstep(.63,.80,chop)*smoothstep(.0,2.7,p.y);
water *= 1.0-.23*base.shadow;
water = mix(water,vec3(.37,.48,.49)*(.83+.18*snow),smoothstep(.003,.04,base.h));
fragColor = vec4(mix(water,ice,smoothstep(.003,.032,f.h)),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;
}
// Pancake Sea Ice Floes — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/ice/lib/06_pancake_ice_with_raised_rims.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-06-pancake-ice-with-raised-rims
// Pancake ice under a low polar sun. Rafted floes ride above a grease-ice matrix.
// 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; }
mat2 rotate2(float a) {
return mat2(cos(a),sin(a),-sin(a),cos(a));
}
struct Floe { float h; float salt; float rim; float surface; float shadow; };
void deposit(inout Floe hit,float radius,vec2 d,float seed,float jag,float slush) {
float shape = length(d)+.06*radius*sin(3.0*atan(d.y,d.x)+seed*8.0)
+(.15*jag-.072)*radius;
float margin = radius-shape;
float ridgeWidth = radius*(.061+.075*seed)*(.83+.41*slush);
float ridge = exp(-sq((margin-.86*ridgeWidth)/ridgeWidth));
ridge *= .56+.44*smoothstep(.28,.65,slush+.16*sin(7.4*d.x+seed*13.0));
float lift = .034+.065*seed;
float fractured = smoothstep(.06,.84,slush+.24*sin(15.0*d.x+seed));
float top = lift+(.057+.065*fractured)*ridge+.016*slush+.011*d.x;
// An inclined perimeter exposes the darker saturated edge at the waterline.
float wall = smoothstep(-.014,.017,margin);
float h = top*wall;
float contact = exp(-sq((margin+.034)/.047));
hit.shadow = max(hit.shadow,contact);
if(h>.001 && (hit.h<.001 || seed>hit.salt)) hit = Floe(h,seed,ridge,smoothstep(.005,.031,margin),hit.shadow);
}
Floe field(vec2 p) {
Floe h = Floe(0.0,0.0,0.0,0.0,0.0);
float jag = fbm(p*11.0);
float slush = fbm(p*14.0);
for(int level=0;level<2;level++) {
float spacing = level==0 ? 1.12 : .40;
vec2 grid = p/spacing+float(level)*3.4;
for(int j=-1;j<=1;j++) for(int i=-1;i<=1;i++) {
vec2 id = floor(grid)+vec2(i,j);
float s = hash(id+5.2);
if(level==1 && s<.58) continue;
vec2 center = id+.5+.76*(vec2(hash(id+2.8),hash(id+4.1))-.5);
vec2 d = (grid-center)*spacing;
d = rotate2(s*6.28)*d;
d.y *= .90+.27*hash(id+7.3);
float r = spacing*(.28+.40*s);
deposit(h,r,d,level==0?s:.24*s,jag,slush);
}
}
return h;
}
void main() {
vec2 uv = sceneCoord();
vec3 rd = normalize(vec3(uv.x*.77,1.0,-.73+uv.y*.38));
vec3 ro = vec3(.31,-2.05,1.32);
vec2 p = (ro-rd*ro.z/rd.z).xy;
Floe base = field(p);
// The exposed near sidewall connects the top surface to its waterline.
p += rd.xy/rd.z*.012;
Floe f = field(p);
vec2 dx = dFdx(p), dy = dFdy(p);
float det = dx.x*dy.y-dx.y*dy.x;
vec2 grad = (dFdx(f.h)*vec2(dy.y,-dy.x)+dFdy(f.h)*vec2(-dx.y,dx.x))/max(.000001,det);
vec3 n = normalize(vec3(-clamp(grad,vec2(-4),vec2(4))*.66,1));
vec3 light = normalize(vec3(-.75,.43,.55));
float direct = max(dot(n,light),0.0);
float snow = fbm(p*11.0+f.salt);
float grit = noise2(p*123.0);
vec3 centerIce = mix(vec3(.40,.49,.50),vec3(.77,.80,.77),.26+.53*snow+.21*f.salt);
vec3 ridgeIce = mix(vec3(.63,.70,.69),vec3(.96,.95,.86),.35+.6*snow);
vec3 ice = mix(centerIce,ridgeIce,f.rim)*(.68+.48*direct);
ice *= .93+.095*grit;
ice = mix(vec3(.23,.34,.37),ice,f.surface);
vec2 w = vec2(7.0*p.x+3.0*p.y,24.0*p.y);
float chop = fbm(w);
float frazil = smoothstep(.49,.68,fbm(p*vec2(3.5,8.5))+.07*chop);
vec3 water = mix(vec3(.092,.169,.204),vec3(.46,.55,.56),.57*chop+.31*frazil);
water += vec3(.20,.18,.13)*smoothstep(.63,.80,chop)*smoothstep(.0,2.7,p.y);
water *= 1.0-.23*base.shadow;
water = mix(water,vec3(.37,.48,.49)*(.83+.18*snow),smoothstep(.003,.04,base.h));
fragColor = vec4(mix(water,ice,smoothstep(.003,.032,f.h)),1);
}
`;
export function createPancakeSeaIceFloesMaterial(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 | pancake-sea-ice-floes |
|---|---|
| Category | Water & Ice Shaders · Snow & Glacial Ice |
| Upstream study | ice/lib/06_pancake_ice_with_raised_rims.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 110 lines · 4.5 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 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.
AnimatedFree-surface Rankine whirlpool depression with spiral capillary ridges and Fresnel sky reflection.