PBR StudyJigsaw puzzle plates of mature ponderosa pine bark terraced over dark resinous fissures.
Fabrics & Organic
peeling-white-birch-bark.glsl · 120 lines · GLSL ES 3.00 · MIT
#version 300 es
// Peeling White Birch Bark (peeling-white-birch-bark.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/12_birch_bark.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-plants-lib-12-birch-bark
// Paper birch with lifting periderm and transverse lenticels. uResolution only.
precision highp float;
uniform vec2 uResolution;
out vec4 fragColor;
float pixel(){ return 2.0 / min(uResolution.x, uResolution.y); }
vec2 screen(){ return (gl_FragCoord.xy - 0.5*uResolution)*pixel(); }
float sat(float x){ return clamp(x,0.0,1.0); }
float hash(vec2 p){
vec3 q=fract(vec3(p.xyx)*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p){
vec2 i=floor(p), f=fract(p); f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float fbm(vec2 p){
return .56*noise2(p)+.28*noise2(p*2.07+11.)+.16*noise2(p*4.13-5.);
}
float cover(float d){
float aa=max(.00001,min(fwidth(d),.2))*.65;
return 1.-smoothstep(-aa,aa,d);
}
mat2 turn(float a){ float c=cos(a),s=sin(a); return mat2(c,s,-s,c); }
float pores(vec2 p){
float marks=0.;
// Sparse, irregular groups; each cork rupture has tapered torn ends.
for(int band=0;band<2;band++){
float b=float(band);
vec2 g=p*vec2(2.8+2.*b,14.+17.*b);
g.y+=.27*sin(2.1*p.x+1.8*p.y)+.10*noise2(p*4.);
g.x+=hash(vec2(floor(g.y),b))*12.;
vec2 id=floor(g);vec2 v=fract(g)-.5;
float k=hash(id+13.),len=.04+.39*k*k;
float h=(.018+.106*k)*(1.-pow(sat(abs(v.x)/len),1.5));
float d=max(abs(v.x)-len,abs(v.y+.18*(hash(id+7.)-.5)+.023*sin(v.x*18.))-h);
marks=max(marks,cover(d)*smoothstep(.24,.72,k));
}
return marks;
}
vec3 sheet(vec3 col,vec2 uv,vec2 center,float span,float orient){
vec2 q=(uv-center)*vec2(orient,1.);
float u=sat(q.x/span+.5);
float taper=pow(max(.0,sin(3.14159*u)),.47);
float edge=.07*sin(4.*u)+.08*(u-.5)+.014*fbm(q*22.);
float lip=.026*taper*(.30+.97*u);
float panel=.11*taper*(.49+.51*noise2(vec2(5.*u,7.)));
float tear=.009*noise2(q*77.)+.004*noise2(q*145.);
float region=max(abs(q.x)-span*.5,max(q.y-edge-panel+tear,edge-lip-q.y));
float v=sat((q.y-edge+lip)/max(.001,lip));
// Cast shadow on exposed cinnamon underbark; the rolled free edge
// shows a bright crest and a much darker curled-under face.
float shade=exp(-max(q.y-edge+lip+.02,0.)*27.)*smoothstep(-.06,.0,q.y-edge+lip+.03);
col*=1.-.32*shade*taper*(1.-smoothstep(.9,1.,abs(q.x)*2./span));
float flap=.17*taper*(.4+.60*noise2(vec2(u*6.,2.)));
float gap=max(abs(q.x)-span*.5,abs(q.y-edge+flap*.48)-flap*.52);
vec3 under=mix(vec3(.54,.34,.22),vec3(.81,.60,.42),fbm(uv*vec2(12.,55.)));
float inner=exp(-15.*abs(q.y-edge+lip));
under=mix(under,vec3(.72,.61,.49),.35*pores(uv+vec2(.30,.12)));
under*=.88+.11*noise2(uv*vec2(9.,124.))-.22*inner;
col=mix(col,under,cover(gap));
vec3 scroll=mix(vec3(.47,.35,.26),vec3(.88,.855,.775),smoothstep(.05,.75,v));
scroll*=1.-.45*pores(uv+vec2(.08,.04))*smoothstep(.55,1.,v);
scroll+=vec3(.12,.10,.07)*exp(-14.*pow(abs(v-.67),2.));
scroll*=.94+.085*noise2(q*vec2(19.,130.));
return mix(col,scroll,cover(region));
}
// A partly detached sheet crosses the trunk silhouette. Its upturned end
// exposes the fibrous, ochre reverse while the attached face retains pores.
vec3 looseFlap(vec3 col,vec2 p){
vec2 q=p-vec2(.70,.22);
float t=sat((q.x+.21)/.44);
float top=.060*sin(4.2*t)+.090*t*t+.006*noise2(q*68.);
float width=.125*(.53+.55*sin(3.1*t))*(1.-.41*t);
float end=.228+.025*sin(q.y*24.);
float edge=max(max(-.21-q.x,q.x-end),max(q.y-top,top-width-q.y));
float v=sat((top-q.y)/width);
float blend=smoothstep(.42,.88,t);
vec3 paper=mix(vec3(.89,.87,.77),vec3(.73,.52,.345),blend);
paper*=.79+.24*sin(3.14*(.17+.72*t))+.055*fbm(q*vec2(21.,96.));
paper*=1.-.29*pores(q*vec2(1.23,1.1)+1.)*(1.-.7*blend);
paper+=vec3(.12,.095,.061)*exp(-31.*v);
float curl=smoothstep(.53,.98,t);
float underside=smoothstep(.76-.32*curl,.84-.32*curl,v)*curl;
paper=mix(paper,vec3(.54,.39,.25)*(.88+.18*fbm(q*vec2(20.,88.))),underside);
paper+=vec3(.073,.062,.044)*exp(-32.*abs(v-.73+.32*curl))*curl;
paper*=1.-.18*exp(-22.*(1.-v));
return mix(col,paper,cover(edge)*smoothstep(-.21,-.11,q.x));
}
void main(){
vec2 p=screen();float x=(p.x-.055*p.y+.026*sin(3.1*p.y))/.85;
float z=sqrt(max(.001,1.-x*x));vec2 uv=vec2(asin(clamp(x,-1.,1.)),p.y);
vec3 bg=mix(vec3(.15,.19,.16),vec3(.38,.39,.27),fbm(p*2.+2.));
float cloud=fbm(uv*vec2(3.7,5.7)),fibre=fbm(uv*vec2(17.,105.));
vec3 bark=mix(vec3(.71,.66,.55),vec3(.95,.94,.88),sat(.32+cloud*.70));
bark*=.92+.1*fibre;
float marks=pores(uv)*(.35+.65*smoothstep(.21,.69,fbm(uv*vec2(31.,13.))));
bark=mix(bark,vec3(.19,.165,.134)*(.70+.7*fibre),marks*(.73+.25*fibre));
// A healed branch scar interrupts the parallel lenticels.
vec2 scar=turn(.19)*(uv-vec2(-.52,.27))/vec2(.23,.11);
float ring=length(scar)+.13*fbm(uv*31.);
float split=abs(scar.y+.20*sin(scar.x*2.));
float wound=exp(-1.6*ring*ring);
bark=mix(bark,vec3(.33,.25,.19),wound*(.66+.25*cos(18.*ring+2.9*fbm(uv*22.))));
bark*=1.-.46*exp(-6.*split)*exp(-1.8*scar.x*scar.x);
bark=sheet(bark,uv,vec2(.24,-.47),1.45,1.);
bark=sheet(bark,uv,vec2(-.81,.72),.94,-1.);
bark*=.65+.36*max(0.,dot(normalize(vec2(-.48,.88)),vec2(x,z)));
vec2 shadow=(p-vec2(.71,.13))*vec2(4.,13.);
bark*=1.-.32*exp(-dot(shadow,shadow));
fragColor=vec4(looseFlap(mix(bg,bark,cover(abs(x)-1.)),p),1);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Peeling White Birch Bark — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/12_birch_bark.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-plants-lib-12-birch-bark
// Paper birch with lifting periderm and transverse lenticels. uResolution only.
float pixel(){ return 2.0 / min(uResolution.x, uResolution.y); }
vec2 screen(){ return (pfx_frag_xy - 0.5*uResolution)*pixel(); }
float sat(float x){ return clamp(x,0.0,1.0); }
float hash(vec2 p){
vec3 q=fract(vec3(p.xyx)*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p){
vec2 i=floor(p), f=fract(p); f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float fbm(vec2 p){
return .56*noise2(p)+.28*noise2(p*2.07+11.)+.16*noise2(p*4.13-5.);
}
float cover(float d){
float aa=max(.00001,min(fwidth(d),.2))*.65;
return 1.-smoothstep(-aa,aa,d);
}
mat2 turn(float a){ float c=cos(a),s=sin(a); return mat2(c,s,-s,c); }
float pores(vec2 p){
float marks=0.;
// Sparse, irregular groups; each cork rupture has tapered torn ends.
for(int band=0;band<2;band++){
float b=float(band);
vec2 g=p*vec2(2.8+2.*b,14.+17.*b);
g.y+=.27*sin(2.1*p.x+1.8*p.y)+.10*noise2(p*4.);
g.x+=hash(vec2(floor(g.y),b))*12.;
vec2 id=floor(g);vec2 v=fract(g)-.5;
float k=hash(id+13.),len=.04+.39*k*k;
float h=(.018+.106*k)*(1.-pow(sat(abs(v.x)/len),1.5));
float d=max(abs(v.x)-len,abs(v.y+.18*(hash(id+7.)-.5)+.023*sin(v.x*18.))-h);
marks=max(marks,cover(d)*smoothstep(.24,.72,k));
}
return marks;
}
vec3 sheet(vec3 col,vec2 uv,vec2 center,float span,float orient){
vec2 q=(uv-center)*vec2(orient,1.);
float u=sat(q.x/span+.5);
float taper=pow(max(.0,sin(3.14159*u)),.47);
float edge=.07*sin(4.*u)+.08*(u-.5)+.014*fbm(q*22.);
float lip=.026*taper*(.30+.97*u);
float panel=.11*taper*(.49+.51*noise2(vec2(5.*u,7.)));
float tear=.009*noise2(q*77.)+.004*noise2(q*145.);
float region=max(abs(q.x)-span*.5,max(q.y-edge-panel+tear,edge-lip-q.y));
float v=sat((q.y-edge+lip)/max(.001,lip));
// Cast shadow on exposed cinnamon underbark; the rolled free edge
// shows a bright crest and a much darker curled-under face.
float shade=exp(-max(q.y-edge+lip+.02,0.)*27.)*smoothstep(-.06,.0,q.y-edge+lip+.03);
col*=1.-.32*shade*taper*(1.-smoothstep(.9,1.,abs(q.x)*2./span));
float flap=.17*taper*(.4+.60*noise2(vec2(u*6.,2.)));
float gap=max(abs(q.x)-span*.5,abs(q.y-edge+flap*.48)-flap*.52);
vec3 under=mix(vec3(.54,.34,.22),vec3(.81,.60,.42),fbm(uv*vec2(12.,55.)));
float inner=exp(-15.*abs(q.y-edge+lip));
under=mix(under,vec3(.72,.61,.49),.35*pores(uv+vec2(.30,.12)));
under*=.88+.11*noise2(uv*vec2(9.,124.))-.22*inner;
col=mix(col,under,cover(gap));
vec3 scroll=mix(vec3(.47,.35,.26),vec3(.88,.855,.775),smoothstep(.05,.75,v));
scroll*=1.-.45*pores(uv+vec2(.08,.04))*smoothstep(.55,1.,v);
scroll+=vec3(.12,.10,.07)*exp(-14.*pow(abs(v-.67),2.));
scroll*=.94+.085*noise2(q*vec2(19.,130.));
return mix(col,scroll,cover(region));
}
// A partly detached sheet crosses the trunk silhouette. Its upturned end
// exposes the fibrous, ochre reverse while the attached face retains pores.
vec3 looseFlap(vec3 col,vec2 p){
vec2 q=p-vec2(.70,.22);
float t=sat((q.x+.21)/.44);
float top=.060*sin(4.2*t)+.090*t*t+.006*noise2(q*68.);
float width=.125*(.53+.55*sin(3.1*t))*(1.-.41*t);
float end=.228+.025*sin(q.y*24.);
float edge=max(max(-.21-q.x,q.x-end),max(q.y-top,top-width-q.y));
float v=sat((top-q.y)/width);
float blend=smoothstep(.42,.88,t);
vec3 paper=mix(vec3(.89,.87,.77),vec3(.73,.52,.345),blend);
paper*=.79+.24*sin(3.14*(.17+.72*t))+.055*fbm(q*vec2(21.,96.));
paper*=1.-.29*pores(q*vec2(1.23,1.1)+1.)*(1.-.7*blend);
paper+=vec3(.12,.095,.061)*exp(-31.*v);
float curl=smoothstep(.53,.98,t);
float underside=smoothstep(.76-.32*curl,.84-.32*curl,v)*curl;
paper=mix(paper,vec3(.54,.39,.25)*(.88+.18*fbm(q*vec2(20.,88.))),underside);
paper+=vec3(.073,.062,.044)*exp(-32.*abs(v-.73+.32*curl))*curl;
paper*=1.-.18*exp(-22.*(1.-v));
return mix(col,paper,cover(edge)*smoothstep(-.21,-.11,q.x));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
vec2 p=screen();float x=(p.x-.055*p.y+.026*sin(3.1*p.y))/.85;
float z=sqrt(max(.001,1.-x*x));vec2 uv=vec2(asin(clamp(x,-1.,1.)),p.y);
vec3 bg=mix(vec3(.15,.19,.16),vec3(.38,.39,.27),fbm(p*2.+2.));
float cloud=fbm(uv*vec2(3.7,5.7)),fibre=fbm(uv*vec2(17.,105.));
vec3 bark=mix(vec3(.71,.66,.55),vec3(.95,.94,.88),sat(.32+cloud*.70));
bark*=.92+.1*fibre;
float marks=pores(uv)*(.35+.65*smoothstep(.21,.69,fbm(uv*vec2(31.,13.))));
bark=mix(bark,vec3(.19,.165,.134)*(.70+.7*fibre),marks*(.73+.25*fibre));
// A healed branch scar interrupts the parallel lenticels.
vec2 scar=turn(.19)*(uv-vec2(-.52,.27))/vec2(.23,.11);
float ring=length(scar)+.13*fbm(uv*31.);
float split=abs(scar.y+.20*sin(scar.x*2.));
float wound=exp(-1.6*ring*ring);
bark=mix(bark,vec3(.33,.25,.19),wound*(.66+.25*cos(18.*ring+2.9*fbm(uv*22.))));
bark*=1.-.46*exp(-6.*split)*exp(-1.8*scar.x*scar.x);
bark=sheet(bark,uv,vec2(.24,-.47),1.45,1.);
bark=sheet(bark,uv,vec2(-.81,.72),.94,-1.);
bark*=.65+.36*max(0.,dot(normalize(vec2(-.48,.88)),vec2(x,z)));
vec2 shadow=(p-vec2(.71,.13))*vec2(4.,13.);
bark*=1.-.32*exp(-dot(shadow,shadow));
fragColor=vec4(looseFlap(mix(bg,bark,cover(abs(x)-1.)),p),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;
// Peeling White Birch Bark — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/12_birch_bark.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-plants-lib-12-birch-bark
// Paper birch with lifting periderm and transverse lenticels. uResolution only.
float pixel(){ return 2.0 / min(uResolution.x, uResolution.y); }
vec2 screen(){ return (pfx_frag_xy - 0.5*uResolution)*pixel(); }
float sat(float x){ return clamp(x,0.0,1.0); }
float hash(vec2 p){
vec3 q=fract(vec3(p.xyx)*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p){
vec2 i=floor(p), f=fract(p); f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float fbm(vec2 p){
return .56*noise2(p)+.28*noise2(p*2.07+11.)+.16*noise2(p*4.13-5.);
}
float cover(float d){
float aa=max(.00001,min(fwidth(d),.2))*.65;
return 1.-smoothstep(-aa,aa,d);
}
mat2 turn(float a){ float c=cos(a),s=sin(a); return mat2(c,s,-s,c); }
float pores(vec2 p){
float marks=0.;
// Sparse, irregular groups; each cork rupture has tapered torn ends.
for(int band=0;band<2;band++){
float b=float(band);
vec2 g=p*vec2(2.8+2.*b,14.+17.*b);
g.y+=.27*sin(2.1*p.x+1.8*p.y)+.10*noise2(p*4.);
g.x+=hash(vec2(floor(g.y),b))*12.;
vec2 id=floor(g);vec2 v=fract(g)-.5;
float k=hash(id+13.),len=.04+.39*k*k;
float h=(.018+.106*k)*(1.-pow(sat(abs(v.x)/len),1.5));
float d=max(abs(v.x)-len,abs(v.y+.18*(hash(id+7.)-.5)+.023*sin(v.x*18.))-h);
marks=max(marks,cover(d)*smoothstep(.24,.72,k));
}
return marks;
}
vec3 sheet(vec3 col,vec2 uv,vec2 center,float span,float orient){
vec2 q=(uv-center)*vec2(orient,1.);
float u=sat(q.x/span+.5);
float taper=pow(max(.0,sin(3.14159*u)),.47);
float edge=.07*sin(4.*u)+.08*(u-.5)+.014*fbm(q*22.);
float lip=.026*taper*(.30+.97*u);
float panel=.11*taper*(.49+.51*noise2(vec2(5.*u,7.)));
float tear=.009*noise2(q*77.)+.004*noise2(q*145.);
float region=max(abs(q.x)-span*.5,max(q.y-edge-panel+tear,edge-lip-q.y));
float v=sat((q.y-edge+lip)/max(.001,lip));
// Cast shadow on exposed cinnamon underbark; the rolled free edge
// shows a bright crest and a much darker curled-under face.
float shade=exp(-max(q.y-edge+lip+.02,0.)*27.)*smoothstep(-.06,.0,q.y-edge+lip+.03);
col*=1.-.32*shade*taper*(1.-smoothstep(.9,1.,abs(q.x)*2./span));
float flap=.17*taper*(.4+.60*noise2(vec2(u*6.,2.)));
float gap=max(abs(q.x)-span*.5,abs(q.y-edge+flap*.48)-flap*.52);
vec3 under=mix(vec3(.54,.34,.22),vec3(.81,.60,.42),fbm(uv*vec2(12.,55.)));
float inner=exp(-15.*abs(q.y-edge+lip));
under=mix(under,vec3(.72,.61,.49),.35*pores(uv+vec2(.30,.12)));
under*=.88+.11*noise2(uv*vec2(9.,124.))-.22*inner;
col=mix(col,under,cover(gap));
vec3 scroll=mix(vec3(.47,.35,.26),vec3(.88,.855,.775),smoothstep(.05,.75,v));
scroll*=1.-.45*pores(uv+vec2(.08,.04))*smoothstep(.55,1.,v);
scroll+=vec3(.12,.10,.07)*exp(-14.*pow(abs(v-.67),2.));
scroll*=.94+.085*noise2(q*vec2(19.,130.));
return mix(col,scroll,cover(region));
}
// A partly detached sheet crosses the trunk silhouette. Its upturned end
// exposes the fibrous, ochre reverse while the attached face retains pores.
vec3 looseFlap(vec3 col,vec2 p){
vec2 q=p-vec2(.70,.22);
float t=sat((q.x+.21)/.44);
float top=.060*sin(4.2*t)+.090*t*t+.006*noise2(q*68.);
float width=.125*(.53+.55*sin(3.1*t))*(1.-.41*t);
float end=.228+.025*sin(q.y*24.);
float edge=max(max(-.21-q.x,q.x-end),max(q.y-top,top-width-q.y));
float v=sat((top-q.y)/width);
float blend=smoothstep(.42,.88,t);
vec3 paper=mix(vec3(.89,.87,.77),vec3(.73,.52,.345),blend);
paper*=.79+.24*sin(3.14*(.17+.72*t))+.055*fbm(q*vec2(21.,96.));
paper*=1.-.29*pores(q*vec2(1.23,1.1)+1.)*(1.-.7*blend);
paper+=vec3(.12,.095,.061)*exp(-31.*v);
float curl=smoothstep(.53,.98,t);
float underside=smoothstep(.76-.32*curl,.84-.32*curl,v)*curl;
paper=mix(paper,vec3(.54,.39,.25)*(.88+.18*fbm(q*vec2(20.,88.))),underside);
paper+=vec3(.073,.062,.044)*exp(-32.*abs(v-.73+.32*curl))*curl;
paper*=1.-.18*exp(-22.*(1.-v));
return mix(col,paper,cover(edge)*smoothstep(-.21,-.11,q.x));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
vec2 p=screen();float x=(p.x-.055*p.y+.026*sin(3.1*p.y))/.85;
float z=sqrt(max(.001,1.-x*x));vec2 uv=vec2(asin(clamp(x,-1.,1.)),p.y);
vec3 bg=mix(vec3(.15,.19,.16),vec3(.38,.39,.27),fbm(p*2.+2.));
float cloud=fbm(uv*vec2(3.7,5.7)),fibre=fbm(uv*vec2(17.,105.));
vec3 bark=mix(vec3(.71,.66,.55),vec3(.95,.94,.88),sat(.32+cloud*.70));
bark*=.92+.1*fibre;
float marks=pores(uv)*(.35+.65*smoothstep(.21,.69,fbm(uv*vec2(31.,13.))));
bark=mix(bark,vec3(.19,.165,.134)*(.70+.7*fibre),marks*(.73+.25*fibre));
// A healed branch scar interrupts the parallel lenticels.
vec2 scar=turn(.19)*(uv-vec2(-.52,.27))/vec2(.23,.11);
float ring=length(scar)+.13*fbm(uv*31.);
float split=abs(scar.y+.20*sin(scar.x*2.));
float wound=exp(-1.6*ring*ring);
bark=mix(bark,vec3(.33,.25,.19),wound*(.66+.25*cos(18.*ring+2.9*fbm(uv*22.))));
bark*=1.-.46*exp(-6.*split)*exp(-1.8*scar.x*scar.x);
bark=sheet(bark,uv,vec2(.24,-.47),1.45,1.);
bark=sheet(bark,uv,vec2(-.81,.72),.94,-1.);
bark*=.65+.36*max(0.,dot(normalize(vec2(-.48,.88)),vec2(x,z)));
vec2 shadow=(p-vec2(.71,.13))*vec2(4.,13.);
bark*=1.-.32*exp(-dot(shadow,shadow));
fragColor=vec4(looseFlap(mix(bg,bark,cover(abs(x)-1.)),p),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;
}
// Peeling White Birch Bark — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/12_birch_bark.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-plants-lib-12-birch-bark
// Paper birch with lifting periderm and transverse lenticels. uResolution only.
precision highp float;
uniform vec2 uResolution;
out vec4 fragColor;
float pixel(){ return 2.0 / min(uResolution.x, uResolution.y); }
vec2 screen(){ return (gl_FragCoord.xy - 0.5*uResolution)*pixel(); }
float sat(float x){ return clamp(x,0.0,1.0); }
float hash(vec2 p){
vec3 q=fract(vec3(p.xyx)*vec3(.1031,.1030,.0973));
q+=dot(q,q.yzx+33.33);
return fract((q.x+q.y)*q.z);
}
float noise2(vec2 p){
vec2 i=floor(p), f=fract(p); f=f*f*(3.-2.*f);
return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),
mix(hash(i+vec2(0,1)),hash(i+1.),f.x),f.y);
}
float fbm(vec2 p){
return .56*noise2(p)+.28*noise2(p*2.07+11.)+.16*noise2(p*4.13-5.);
}
float cover(float d){
float aa=max(.00001,min(fwidth(d),.2))*.65;
return 1.-smoothstep(-aa,aa,d);
}
mat2 turn(float a){ float c=cos(a),s=sin(a); return mat2(c,s,-s,c); }
float pores(vec2 p){
float marks=0.;
// Sparse, irregular groups; each cork rupture has tapered torn ends.
for(int band=0;band<2;band++){
float b=float(band);
vec2 g=p*vec2(2.8+2.*b,14.+17.*b);
g.y+=.27*sin(2.1*p.x+1.8*p.y)+.10*noise2(p*4.);
g.x+=hash(vec2(floor(g.y),b))*12.;
vec2 id=floor(g);vec2 v=fract(g)-.5;
float k=hash(id+13.),len=.04+.39*k*k;
float h=(.018+.106*k)*(1.-pow(sat(abs(v.x)/len),1.5));
float d=max(abs(v.x)-len,abs(v.y+.18*(hash(id+7.)-.5)+.023*sin(v.x*18.))-h);
marks=max(marks,cover(d)*smoothstep(.24,.72,k));
}
return marks;
}
vec3 sheet(vec3 col,vec2 uv,vec2 center,float span,float orient){
vec2 q=(uv-center)*vec2(orient,1.);
float u=sat(q.x/span+.5);
float taper=pow(max(.0,sin(3.14159*u)),.47);
float edge=.07*sin(4.*u)+.08*(u-.5)+.014*fbm(q*22.);
float lip=.026*taper*(.30+.97*u);
float panel=.11*taper*(.49+.51*noise2(vec2(5.*u,7.)));
float tear=.009*noise2(q*77.)+.004*noise2(q*145.);
float region=max(abs(q.x)-span*.5,max(q.y-edge-panel+tear,edge-lip-q.y));
float v=sat((q.y-edge+lip)/max(.001,lip));
// Cast shadow on exposed cinnamon underbark; the rolled free edge
// shows a bright crest and a much darker curled-under face.
float shade=exp(-max(q.y-edge+lip+.02,0.)*27.)*smoothstep(-.06,.0,q.y-edge+lip+.03);
col*=1.-.32*shade*taper*(1.-smoothstep(.9,1.,abs(q.x)*2./span));
float flap=.17*taper*(.4+.60*noise2(vec2(u*6.,2.)));
float gap=max(abs(q.x)-span*.5,abs(q.y-edge+flap*.48)-flap*.52);
vec3 under=mix(vec3(.54,.34,.22),vec3(.81,.60,.42),fbm(uv*vec2(12.,55.)));
float inner=exp(-15.*abs(q.y-edge+lip));
under=mix(under,vec3(.72,.61,.49),.35*pores(uv+vec2(.30,.12)));
under*=.88+.11*noise2(uv*vec2(9.,124.))-.22*inner;
col=mix(col,under,cover(gap));
vec3 scroll=mix(vec3(.47,.35,.26),vec3(.88,.855,.775),smoothstep(.05,.75,v));
scroll*=1.-.45*pores(uv+vec2(.08,.04))*smoothstep(.55,1.,v);
scroll+=vec3(.12,.10,.07)*exp(-14.*pow(abs(v-.67),2.));
scroll*=.94+.085*noise2(q*vec2(19.,130.));
return mix(col,scroll,cover(region));
}
// A partly detached sheet crosses the trunk silhouette. Its upturned end
// exposes the fibrous, ochre reverse while the attached face retains pores.
vec3 looseFlap(vec3 col,vec2 p){
vec2 q=p-vec2(.70,.22);
float t=sat((q.x+.21)/.44);
float top=.060*sin(4.2*t)+.090*t*t+.006*noise2(q*68.);
float width=.125*(.53+.55*sin(3.1*t))*(1.-.41*t);
float end=.228+.025*sin(q.y*24.);
float edge=max(max(-.21-q.x,q.x-end),max(q.y-top,top-width-q.y));
float v=sat((top-q.y)/width);
float blend=smoothstep(.42,.88,t);
vec3 paper=mix(vec3(.89,.87,.77),vec3(.73,.52,.345),blend);
paper*=.79+.24*sin(3.14*(.17+.72*t))+.055*fbm(q*vec2(21.,96.));
paper*=1.-.29*pores(q*vec2(1.23,1.1)+1.)*(1.-.7*blend);
paper+=vec3(.12,.095,.061)*exp(-31.*v);
float curl=smoothstep(.53,.98,t);
float underside=smoothstep(.76-.32*curl,.84-.32*curl,v)*curl;
paper=mix(paper,vec3(.54,.39,.25)*(.88+.18*fbm(q*vec2(20.,88.))),underside);
paper+=vec3(.073,.062,.044)*exp(-32.*abs(v-.73+.32*curl))*curl;
paper*=1.-.18*exp(-22.*(1.-v));
return mix(col,paper,cover(edge)*smoothstep(-.21,-.11,q.x));
}
void main(){
vec2 p=screen();float x=(p.x-.055*p.y+.026*sin(3.1*p.y))/.85;
float z=sqrt(max(.001,1.-x*x));vec2 uv=vec2(asin(clamp(x,-1.,1.)),p.y);
vec3 bg=mix(vec3(.15,.19,.16),vec3(.38,.39,.27),fbm(p*2.+2.));
float cloud=fbm(uv*vec2(3.7,5.7)),fibre=fbm(uv*vec2(17.,105.));
vec3 bark=mix(vec3(.71,.66,.55),vec3(.95,.94,.88),sat(.32+cloud*.70));
bark*=.92+.1*fibre;
float marks=pores(uv)*(.35+.65*smoothstep(.21,.69,fbm(uv*vec2(31.,13.))));
bark=mix(bark,vec3(.19,.165,.134)*(.70+.7*fibre),marks*(.73+.25*fibre));
// A healed branch scar interrupts the parallel lenticels.
vec2 scar=turn(.19)*(uv-vec2(-.52,.27))/vec2(.23,.11);
float ring=length(scar)+.13*fbm(uv*31.);
float split=abs(scar.y+.20*sin(scar.x*2.));
float wound=exp(-1.6*ring*ring);
bark=mix(bark,vec3(.33,.25,.19),wound*(.66+.25*cos(18.*ring+2.9*fbm(uv*22.))));
bark*=1.-.46*exp(-6.*split)*exp(-1.8*scar.x*scar.x);
bark=sheet(bark,uv,vec2(.24,-.47),1.45,1.);
bark=sheet(bark,uv,vec2(-.81,.72),.94,-1.);
bark*=.65+.36*max(0.,dot(normalize(vec2(-.48,.88)),vec2(x,z)));
vec2 shadow=(p-vec2(.71,.13))*vec2(4.,13.);
bark*=1.-.32*exp(-dot(shadow,shadow));
fragColor=vec4(looseFlap(mix(bg,bark,cover(abs(x)-1.)),p),1);
}
`;
export function createPeelingWhiteBirchBarkMaterial(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 | peeling-white-birch-bark |
|---|---|
| Category | Fabrics & Organic Shaders · Bark, Scales & Flora |
| Upstream study | plants/lib/12_birch_bark.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 120 lines · 5.5 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT nature sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Procedural signed-distance and analytic surface shading
David Hoskins, hash
PBR StudyJigsaw puzzle plates of mature ponderosa pine bark terraced over dark resinous fissures.
PBR StudyKeeled diamond dragon and serpent scales imbricated over flexible interstitial skin.
AnimatedCycloid silver-blue scales with concentric growth circuli and guanine thin-film shimmer.
AnimatedDense cushion of star-shaped emerald sphagnum moss heads glistening with capillary moisture.
AnimatedBranching cyan-green fungal rhizomorph veins pulsing across damp cavern bark.
PBR StudyPlush uncut cotton yarn loops casting soft micro-occlusion across woven backing.