PBR StudyChalk-white papery birch periderm curling back to expose warm cinnamon inner bark.
Fabrics & Organic
lenticel-woodland-bark.glsl · 110 lines · GLSL ES 3.00 · MIT
#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.);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Lenticel Woodland Bark — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/01_bark_lenticels.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-01-bark-lenticels
// Cherry periderm | raised cork margins rupture the satin bark of a young limb.
// uResolution: viewport in pixels. No optional uniforms.
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.*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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.);
}
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;
// Lenticel Woodland Bark — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/01_bark_lenticels.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-01-bark-lenticels
// Cherry periderm | raised cork margins rupture the satin bark of a young limb.
// uResolution: viewport in pixels. No optional uniforms.
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.*pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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.);
}
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;
}
// Lenticel Woodland Bark — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/plants/lib/01_bark_lenticels.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-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.);
}
`;
export function createLenticelWoodlandBarkMaterial(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 | lenticel-woodland-bark |
|---|---|
| Category | Fabrics & Organic Shaders · Bark, Scales & Flora |
| Upstream study | plants/lib/01_bark_lenticels.glsl (commit c3a6f6c) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 110 lines · 4.7 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 StudyChalk-white papery birch periderm curling back to expose warm cinnamon inner bark.
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.