Back to shaders

Shader test bench

Procedural Brick Weathering

stronghold-curated material glsl runnable fragment MIT
Source
runnable fragment

Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.

Code

precision mediump float;
uniform vec2 resolution;
uniform float time;
float hash(vec2 p){return fract(sin(dot(p,vec2(91.7,45.3)))*43758.5453);} 
float noise(vec2 p){vec2 i=floor(p),f=fract(p);f=f*f*(3.0-2.0*f);return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),mix(hash(i+vec2(0,1)),hash(i+1.0),f.x),f.y);} 
void main(){
 vec2 uv=gl_FragCoord.xy/resolution.xy; uv.x*=resolution.x/resolution.y; vec2 p=uv*vec2(8.0,5.0); p.x+=mod(floor(p.y),2.0)*0.5; vec2 f=fract(p); vec2 id=floor(p);
 float mortar=step(f.x,0.06)+step(0.94,f.x)+step(f.y,0.08)+step(0.92,f.y); float n=noise(uv*28.0)+0.5*noise(uv*71.0); vec3 brick=mix(vec3(0.32,0.08,0.035),vec3(0.72,0.24,0.12),hash(id)*0.6+n*0.25); vec3 col=mix(brick,vec3(0.48,0.43,0.36),clamp(mortar,0.0,1.0)); gl_FragColor=vec4(col,1.0);
}