Worn Street Cobblestones shader

worn-street-cobblestones.glsl · 102 lines · GLSL ES 3.00 · MIT

Worn Street CobblestonesStone & Masonry
Worn Street Cobblestones WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 102 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
worn-street-cobblestones.glsl (102 lines)
#version 300 es
// Worn Street Cobblestones (worn-street-cobblestones.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/construction/lib/14_cobblestones.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-14-cobblestones
// Rain on porphyry | radiating setts, soldier courses and water pooled in the joints.
// WebGL2: draw a fullscreen triangle. Set uResolution to the viewport in pixels.
precision highp float;
precision highp int;
uniform vec2 uResolution;
out vec4 fragColor;
const float PI=3.14159265;
const float TAU=6.28318531;
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 mask(float d,float aa){return 1.-smoothstep(-aa,aa,d);}
float box(vec2 p,vec2 b,float r){vec2 q=abs(p)-b+r;return length(max(q,0.))+min(max(q.x,q.y),0.)-r;}
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 Sett { float d; float seed; vec2 uv; };
Sett paving(vec2 p){

    vec2 ray=p-vec2(-.89,-3.9);float rad=length(ray);
    float a=atan(ray.y,abs(ray.x)+abs(ray.y)<1e-7?1.:ray.x);
    float lane=max(0.,floor(rad/.54)),mid=(lane+.5)*.54;
    float count=max(1.,floor(TAU*mid/.69+.5));
    float along=(a/TAU+.5)*count+.49*mod(lane,2.);
    float id=floor(along);
    vec2 q=vec2((fract(along)-.5)*TAU*mid/count,rad-mid);
    float h=rnd(vec2(mod(id,count),lane));
    float chip=.026*(fb(p*18.)-.5);
    float d=-box(rot((h-.5)*.073)*q,vec2(TAU*mid/count*.5-.021,.255),.075+.048*h);
    // A soldier course follows the arc. Its radial joints end at full stones.
    if(lane==9. || lane==10.){
        count=floor(TAU*mid/.36+.5);
        along=(a/TAU+.5)*count+.5*mod(lane,2.);
        q=vec2((fract(along)-.5)*TAU*mid/count,rad-mid);
        h=.70+.17*rnd(vec2(mod(floor(along),count),lane));
        d=-box(q,vec2(TAU*mid/count*.5-.012,.255),.043);
    }
    return Sett(d+chip,h,q);
}
// A single fallen beech leaf gives a physical scale to the wet setts.
float leafEdge(vec2 q){
    float t=clamp(q.x/.59,0.,1.);
    float belly=.128*pow(max(0.,sin(PI*t)),.77)*(.78+.37*t);
    belly+=.006*sin(148.*q.x)*sin(PI*t);
    return max(abs(q.y-.029*sin(PI*t))-belly,max(-q.x,q.x-.59));
}
void main(){
    vec2 v=screen(),p=rot(.20)*v*3.55;p.y*=1.39;
    p/=max(.65,1.-.16*p.y);
    Sett s=paving(p);
    float broad=fb(p*4.7+s.seed*16.),fine=noiseAt(p*165.);
    float e=max(0.,s.d);
    float height=.111*(1.-exp(-e*15.))+.028*broad+.006*noiseAt(p*34.);
    vec2 grad=vec2(dFdx(height),dFdy(height))/max(length(fwidth(p))*.69,.0001);
    vec3 n=normalize(vec3(-grad,1.));
    vec3 sky=vec3(.42,.56,.62),sun=normalize(vec3(-.63,.70,.34));
    vec3 stone=mix(vec3(.28,.234,.242),vec3(.57,.465,.412),s.seed);
    stone=mix(stone,vec3(.40,.45,.47),.78*smoothstep(.51,.79,s.seed));
    stone+=.13*(broad-.5)+.10*(fine-.5);
    float crystals=noiseAt(p*77.)+.26*noiseAt(p*153.);
    stone+=vec3(.17,.154,.143)*smoothstep(.82,1.04,crystals);
    vec3 col=stone*(.57+.65*max(0.,dot(n,sun)));
    // A grazing sky reflection breaks across worn crowns and drops out in rough patches.
    float damp=.20+.77*smoothstep(.37,.72,fb(p*1.9)+.13*broad);
    float refl=pow(max(0.,dot(n,normalize(vec3(-.41,.43,.81)))),10.);
    col=mix(col,col*.77+sky*(.09+.53*refl),damp);
    vec3 bed=vec3(.125,.115,.11)+.09*noiseAt(p*100.);
    float pool=fb(p*1.22)+.17*fb(p*8.);
    bed=mix(bed,sky*(.38+.23*fb(p*vec2(2.,13.))),smoothstep(.40,.64,pool));
    float aa=max(.0003,length(fwidth(p))*.58);
    col=mix(bed,col,smoothstep(-aa,aa,s.d));
    col+=vec3(.19,.20,.18)*exp(-abs(s.d+.005)*280.)*smoothstep(.56,.71,pool);
    vec2 leaf=rot(-.54)*(p-vec2(.48,-.27));
    float ld=leafEdge(leaf);
    col*=1.-.32*(1.-smoothstep(-.010,.030,leafEdge(leaf-vec2(.023,-.027))));
    float t=sat(leaf.x/.59),midrib=leaf.y-.029*sin(PI*t);
    float vein=abs(fract(leaf.x*15.5-abs(midrib)*10.+.18*sin(leaf.x*21.))-.5);
    vec3 copper=mix(vec3(.58,.285,.106),vec3(.84,.55,.235),smoothstep(-.13,.07,midrib));
    copper*=.84+.21*fb(leaf*24.)+.13*exp(-vein*15.)+.18*exp(-abs(midrib)*160.);
    col=mix(col,copper,mask(ld,aa));
    float stem=length(leaf-vec2(clamp(leaf.x,-.105,.017),0.))-.007;
    col=mix(col,vec3(.44,.30,.14),mask(stem,aa));
    fragColor=vec4(finish(col,v),1);
}

Mathematical models & shader specifications

Identifierworn-street-cobblestones
CategoryStone & Masonry Shaders · Architectural Masonry
Upstream studyconstruction/lib/14_cobblestones.glsl (commit 1fbd084)
Animation cycleStatic analytical PBR surface
Declared uniformsuResolution
Source size102 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

Inigo Quilez, distance formulation

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