AnimatedCrushed basalt road aggregate in dark bitumen binder crossed by glossy poured-tar crack sealant.
worn-street-cobblestones.glsl · 102 lines · GLSL ES 3.00 · MIT
#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);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Worn Street Cobblestones — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/construction/lib/14_cobblestones.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;
// 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.
const float PI=3.14159265;
const float TAU=6.28318531;
vec2 screen(){return (pfx_frag_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(pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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);
}
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;
// Worn Street Cobblestones — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/construction/lib/14_cobblestones.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;
// 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.
const float PI=3.14159265;
const float TAU=6.28318531;
vec2 screen(){return (pfx_frag_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(pfx_frag_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 pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor){
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);
}
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;
}
// Worn Street Cobblestones — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/construction/lib/14_cobblestones.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 */ `
// 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);
}
`;
export function createWornStreetCobblestonesMaterial(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 | worn-street-cobblestones |
|---|---|
| Category | Stone & Masonry Shaders · Architectural Masonry |
| Upstream study | construction/lib/14_cobblestones.glsl (commit 1fbd084) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 102 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
Inigo Quilez, distance formulation
AnimatedCrushed basalt road aggregate in dark bitumen binder crossed by glossy poured-tar crack sealant.
AnimatedBrutalist poured concrete imprinted with timber plank grain, form-tie cones, and air bug-holes.
AnimatedRain-soaked street puddle with thin-film rainbow petroleum sheen lapping aggregate stones.
AnimatedTroweled lime-terracotta facade plaster with hairline craze cracks and sun-bleached wash.
AnimatedConcentric chalcedony fortification bands growing inward toward a crystalline quartz cavity.
AnimatedMetallic brass-gold fool’s gold cubes with orthogonal crystal striations in matrix rock.