Lenticel Woodland Bark shader

lenticel-woodland-bark.glsl · 110 lines · GLSL ES 3.00 · MIT

Lenticel Woodland BarkFabrics & Organic
Lenticel Woodland Bark WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 110 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
lenticel-woodland-bark.glsl (110 lines)
#version 300 es
// Lenticel Woodland Bark (lenticel-woodland-bark.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/01_bark_lenticels.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-01-bark-lenticels
// Cherry periderm | raised cork margins rupture the satin bark of a young limb.
// uResolution: viewport in pixels. No optional uniforms.
precision highp float;
uniform vec2 uResolution;
out vec4 fragColor;

const float PI=3.14159265;
const float TAU=6.28318531;
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){
    mat2 turn=mat2(.8,.6,-.6,.8);
    return .55*noise2(p)+.27*noise2(turn*p*2.13+5.)
         +.13*noise2(p*4.57-9.)+.05*noise2(turn*p*9.12);
}
float gauss(float x){return exp(-x*x);}
float pixel(){return 2./min(uResolution.x,uResolution.y);}
vec2 viewport(){return (2.*gl_FragCoord.xy-uResolution)*(.5*pixel());}
float cover(float d){return 1.-smoothstep(-pixel()*.65,pixel()*.65,d);}
// All primitives are intersected along the camera's z axis. Shading uses the
// foremost intersection, including across separate whorls and branch junctions.
struct Hit { float z; vec3 normal; vec2 uv; float id; float seed; };
struct Vertex { vec3 pos; vec2 uv; };
vec3 backdrop(vec2 p,vec3 dark,vec3 light,float seed){
    // Defocused canopy gaps and out-of-focus branches at two depth planes.
    vec2 q=mat2(.8,.6,-.6,.8)*p+seed;
    float shade=.48*noise2(q*1.25)+.34*noise2(p*2.7-seed)+.18*noise2(q*5.3+6.);
    vec3 c=mix(dark,light,smoothstep(.25,.77,shade));
    for(int i=0;i<8;i++){
        float k=float(i),r=hash(vec2(k,seed));
        float x=-1.9+.48*k+.37*r+(.18-r*.59)*p.y+.026*sin(4.*p.y+k);
        c=mix(c,dark,.22*gauss((p.x-x)/(.027+.073*r)));
    }
    vec2 grid=q*3.1,cell=floor(grid);
    vec2 d=fract(grid)-.24-.50*vec2(hash(cell),hash(cell+13.));
    float bokeh=1.-smoothstep(.085,.215,length(d));
    c+=vec3(.078,.075,.049)*bokeh*smoothstep(.52,.90,hash(cell+9.))*(.35+.65*shade);
    return c;
}
vec3 lit(vec3 albedo,vec3 n,float gloss,float power){
    vec3 key=normalize(vec3(-.57,.68,.62));
    float diffuse=max(dot(n,key),0.);
    float sky=.45+.16*n.y;
    float spec=pow(max(dot(n,normalize(key+vec3(0,0,1))),0.),power);
    return albedo*(sky+vec3(.66,.59,.49)*diffuse+.10*max(-n.x,0.))
          +vec3(1.,.91,.73)*gloss*spec;
}

vec4 periderm(vec2 uv){
    float stripes=fbm(uv*vec2(8.,45.));
    float fibers=fbm(uv*vec2(35.,112.));
    float axial=fbm(uv*vec2(14.,2.7));
    vec3 skin=mix(vec3(.27,.135,.10),vec3(.56,.337,.245),.60*stripes+.40*axial);
    skin+=vec3(.11,.086,.068)*smoothstep(.47,.71,fibers);
    float height=.0017*stripes+.0007*fibers;
    vec2 field=uv*vec2(2.6,5.7);
    vec2 cell=floor(field);
    for(int y=-1;y<=1;y++)for(int x=-1;x<=1;x++){
        vec2 id=cell+vec2(x,y);
        float seed=hash(id+9.3);
        vec2 q=field-id-.20-.60*vec2(hash(id+3.),hash(id+8.));
        float width=.11+.62*pow(seed,1.7);
        q.y+=.047*sin(6.*q.x+seed*15.)+.039*q.x+.025*(noise2(uv*97.)-.5);
        float s=q.x/width;
        float taper=pow(max(0.,1.-s*s),.72);
        float aperture=(.029+.086*seed)*taper;
        float exposed=(abs(q.y)-aperture)/5.7;
        float ends=max(abs(s)-1.,0.)*.10;
        float boundary=max(exposed,ends-.028);
        float mouth=cover(max(exposed,abs(q.x)-width));
        float lip=gauss((abs(q.y)-aperture-.033)/.035)*smoothstep(.0,.30,taper);
        float lower=1.-smoothstep(-.013,.011,q.y);
        float debris=fbm(vec2(q.x*96.,q.y*38.)+seed);
        vec3 cork=mix(vec3(.31,.211,.156),vec3(.76,.57,.40),smoothstep(.25,.75,debris));
        skin=mix(skin,cork,mouth);
        skin=mix(skin,vec3(.77,.57,.40),lip*(.39+.31*lower));
        height+=.0025*lip-.0019*mouth+.001*(debris-.5)*mouth;
        skin*=1.-.11*gauss((boundary-.013)/.006)*taper;
    }
    return vec4(skin,height);
}
void main(){
    vec2 p=mat2(.946,-.324,.324,.946)*viewport();
    float radius=.74-.050*p.y;
    float axis=.082*sin(1.5*p.y)-.10;
    float sx=clamp((p.x-axis)/radius,-.99999,.99999);
    float z=sqrt(1.-sx*sx),angle=asin(sx);
    vec2 uv=vec2(angle*.84,p.y+.035*sin(3.*angle));
    vec4 bark=periderm(uv);
    vec2 slope=vec2(dFdx(bark.a),dFdy(bark.a))/pixel();
    vec3 normal=normalize(vec3(sx-slope.x,z*.21-slope.y,z));
    vec3 skin=lit(bark.rgb,normal,.11,23.);
    skin+=.072*gauss((sx+.40)/.20)*fbm(uv*vec2(8.,74.));
    vec3 sky=backdrop(p,vec3(.135,.19,.19),vec3(.63,.68,.59),13.);
    float coverage=cover(abs(p.x-axis)-radius);
    fragColor=vec4(mix(sky,skin,coverage),1.);
}

Mathematical models & shader specifications

Identifierlenticel-woodland-bark
CategoryFabrics & Organic Shaders · Bark, Scales & Flora
Upstream studyplants/lib/01_bark_lenticels.glsl (commit c3a6f6c)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size110 lines · 4.7 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