Stained Glass Lead Cames shader

stained-glass-lead-cames.glsl · 100 lines · GLSL ES 3.00 · MIT

Stained Glass Lead CamesStone & Masonry
Stained Glass Lead Cames WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 100 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

Architectural Masonry
stained-glass-lead-cames.glsl (100 lines)
#version 300 es
// Stained Glass Lead Cames (stained-glass-lead-cames.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/construction/lib/11_lead_strips_joining_stained_glass.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float)
// Credits: https://github.com/gokayfem/glsl-studies/blob/main/credit.md#shader-construction-lib-11-lead-strips-joining-stained-glass
// Iris window | cut opalescent glass held by raised lead flanges and soldered nodes.
// WebGL2: draw a fullscreen triangle. Set uResolution to the viewport in pixels.
precision highp float;
precision highp int;
uniform vec2 uResolution;
out vec4 fragColor;
vec2 screen(){return (gl_FragCoord.xy-.5*uResolution)/max(1.,min(uResolution.x,uResolution.y));}
float rnd(vec2 id){
    uvec2 p=uvec2(ivec2(floor(id)));
    uint v=p.x*1597334677u ^ p.y*3812015801u ^ 1013904223u;
    v=(v^(v>>16u))*2246822519u;
    return float(v^(v>>13u))*(1./4294967296.);
}
float noiseAt(vec2 p){
    vec2 i=floor(p),f=fract(p);f=f*f*(3.-2.*f);
    return mix(mix(rnd(i),rnd(i+vec2(1,0)),f.x),mix(rnd(i+vec2(0,1)),rnd(i+1.),f.x),f.y);
}
float fb(vec2 p){
    mat2 m=mat2(1.74,1.01,-1.01,1.74);
    return .55*noiseAt(p)+.27*noiseAt(m*p+11.)+.13*noiseAt(m*m*p-7.)+.05*noiseAt(m*m*m*p+29.);
}
mat2 rot(float a){return mat2(cos(a),sin(a),-sin(a),cos(a));}
float sat(float a){return clamp(a,0.,1.);}
float sq(float a){return a*a;}
vec3 finish(vec3 col,vec2 uv){
    return clamp(col*(1.-.12*smoothstep(.16,.9,length(uv)))+.009*(rnd(gl_FragCoord.xy)-.5),0.,1.);
}

struct Pane { vec3 tint; float seam; float key; };
// A pointed petal cut from two circular arcs. Later cuts replace the glass behind them.
void lens(inout Pane p,vec2 xy,vec2 a,vec2 b,float width,vec3 tint,float key){
    vec2 d=b-a;float len=length(d);vec2 u=d/len;
    vec2 q=vec2(dot(xy-.5*(a+b),u),dot(xy-.5*(a+b),vec2(-u.y,u.x)));
    float rad=(sq(.5*len)+sq(width))/(2.*width);
    float edge=length(vec2(q.x,abs(q.y)+rad-width))-rad;
    if(edge<0.){p.tint=tint;p.key=key;p.seam=-edge;}
    else p.seam=min(p.seam,edge);
}
void main(){
    vec2 v=screen(),p=v*1.85;
    float aa=max(.0004,fwidth(p.y)*.75);
    float border=abs(p.x);float line1=p.y+.24*p.x+.20*sin(p.x*4.);
    float line2=p.y-.44+.13*cos(3.8*p.x);
    vec3 base=mix(vec3(.49,.72,.68),vec3(.79,.86,.69),smoothstep(-.4,.8,p.y));
    Pane g=Pane(base,min(abs(line1),abs(line2)),floor(line1)*17.+floor(line2)*4.);
    float paneX=floor((p.x+.2)/.47);
    g.seam=min(g.seam,.47*min(fract((p.x+.2)/.47),1.-fract((p.x+.2)/.47)));
    g.key+=paneX*5.;
    // Blades and slender stems cross the field in front of the distant water.
    lens(g,p,vec2(-.34,-1.5),vec2(.01,.22),.062,vec3(.28,.52,.28),8.);
    lens(g,p,vec2(-.31,-1.26),vec2(-.78,-.14),.09,vec3(.24,.49,.34),2.);
    lens(g,p,vec2(-.27,-1.3),vec2(.64,-.04),.135,vec3(.28,.56,.35),13.);
    lens(g,p,vec2(-.31,-1.26),vec2(.39,-.27),.07,vec3(.46,.65,.34),12.);
    vec2 root=vec2(.018,.20);
    lens(g,p,root,vec2(-.52,.62),.125,vec3(.45,.38,.70),22.);
    lens(g,p,root,vec2(-.16,.84),.132,vec3(.54,.47,.77),35.);
    lens(g,p,root,vec2(.25,.78),.146,vec3(.39,.34,.67),41.);
    lens(g,p,root,vec2(.62,.49),.142,vec3(.48,.41,.73),55.);
    lens(g,p,root,vec2(-.46,-.13),.152,vec3(.30,.28,.60),71.);
    lens(g,p,root,vec2(.37,-.24),.174,vec3(.33,.30,.67),84.);
    lens(g,p,root,vec2(.25,-.02),.038,vec3(.99,.66,.19),97.);
    lens(g,p,root,vec2(-.25,.02),.029,vec3(.98,.72,.30),99.);
    if(border>.87){g.tint=border<.925?vec3(.87,.61,.27):vec3(.28,.46,.47);g.key=9.+floor(p.y/.31);
        g.seam=min(min(abs(border-.87),abs(border-.925)),.31*min(fract(p.y/.31),1.-fract(p.y/.31)));}
    else g.seam=min(g.seam,.87-border);
    vec2 wave=rot(.6*sin(g.key))*p;
    float roll=fb(wave*vec2(6.,19.)+g.key);
    float streak=fb(vec2(wave.x*25.+4.*roll,wave.y*2.)+g.key);
    float transmitted=.84+.19*fb(3.*p+3.*roll)+.19*(roll-.45);
    float sunSpot=exp(-dot(p-vec2(-.49,.49),p-vec2(-.49,.49))*2.6);
    float caustic=pow(sat(1.-abs(roll-.54)*9.),5.);
    transmitted+=.13*sunSpot+.037*caustic*sunSpot;
    vec3 glass=mix(g.tint,vec3(.93,.90,.74),.27*smoothstep(.45,.80,streak))*transmitted;
    // Fired grisaille feathering follows the direction of the iris falls.
    if(g.key==71.||g.key==84.){
        vec2 leaf=p-root;float signX=sign(leaf.x);
        float veins=sin(41.*atan(leaf.y,abs(leaf.x)+.001)+signX*2.5*length(leaf));
        glass*=1.-.145*smoothstep(.56,.99,veins)*smoothstep(.08,.31,length(leaf));
    }
    glass*=1.-.22*exp(-g.seam*52.);
    vec2 bub=fract(p*41.)-.5;float bubble=length(bub*vec2(1.,2.3));
    glass+=.09*step(.91,rnd(floor(p*41.)))*exp(-sq((bubble-.17)/.055));
    // A narrow high side and a dark return give the came its rolled face.
    float seam=g.seam+.0011*(noiseAt(p*115.)-.5);
    vec2 slope=vec2(dFdx(seam),dFdy(seam))/max(aa,.0003);
    float solder=exp(-sq(length(p-root)/.045));
    solder+=exp(-sq(length(p-vec2(-.52,.62))/.021))+exp(-sq(length(p-vec2(.62,.49))/.023));
    solder+=exp(-sq(length(p-vec2(-.46,-.13))/.022))+exp(-sq(length(p-vec2(.37,-.24))/.022));
    vec3 metal=vec3(.115,.128,.132)+.058*noiseAt(p*103.)+.10*solder;
    metal+=.19*exp(-sq((seam-.006)/.0035))*sat(.5+.4*dot(slope,vec2(-.7,.7)));
    float bead=length((p-root)*vec2(.86,1.));
    vec3 solderMetal=vec3(.19,.207,.212)+.065*noiseAt(p*172.)
                    +.26*exp(-sq(length(p-root-vec2(-.007,.009))/.008));
    vec3 col=mix(metal,glass,smoothstep(.0115-aa,.0115+aa,seam));
    col=mix(col,solderMetal,1.-smoothstep(.019-aa,.019+aa,bead));
    fragColor=vec4(finish(col,v),1);
}

Mathematical models & shader specifications

Identifierstained-glass-lead-cames
CategoryStone & Masonry Shaders · Architectural Masonry
Upstream studyconstruction/lib/11_lead_strips_joining_stained_glass.glsl (commit 1fbd084)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size100 lines · 5.2 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT holy sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Procedural signed-distance and analytic surface shading

Adapted upstream mathematical helpers

Standalone GLSL ES 3.00 math primitives

All stone & masonry shaders
Board-Formed Concrete WebGL2 procedural shaderAnimated

Brutalist poured concrete imprinted with timber plank grain, form-tie cones, and air bug-holes.

Stone & Masonry