Peeling White Birch Bark shader

peeling-white-birch-bark.glsl · 120 lines · GLSL ES 3.00 · MIT

Peeling White Birch BarkFabrics & Organic
Peeling White Birch Bark WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 120 linesSPEC GLSL ES 3.00

Seamless PNG Texture Baker
1-Click Engine Shader Export
WebGL2 .glsl
.glsl
Godot 4 .gdshader
Three.js GLSL3

Engine shader code & wrappers

Bark, Scales & Flora
peeling-white-birch-bark.glsl (120 lines)
#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);
}

Mathematical models & shader specifications

Identifierpeeling-white-birch-bark
CategoryFabrics & Organic Shaders · Bark, Scales & Flora
Upstream studyplants/lib/12_birch_bark.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size120 lines · 5.5 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT nature sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Procedural signed-distance and analytic surface shading

Adapted upstream mathematical helpers

David Hoskins, hash

All fabrics & organic shaders
Sphagnum Forest Moss WebGL2 procedural shaderAnimated

Dense cushion of star-shaped emerald sphagnum moss heads glistening with capillary moisture.

Fabrics & Organic