AnimatedEncroaching flaky orange-ochre iron oxide eating across painted industrial steel.
copper-verdigris-patina.glsl · 118 lines · GLSL ES 3.00 · MIT
#version 300 es
// Copper Verdigris Patina (copper-verdigris-patina.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/wear/lib/05_copper_verdigris_runoff.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-wear-lib-05-copper-verdigris-runoff
// Copper scupper with a rolled lip and a layered verdigris wash down its splash plate.
// WebGL2 fullscreen pass. Set uResolution to drawing-buffer pixels.
precision highp float;
precision highp int;
uniform vec2 uResolution;
out vec4 fragColor;
float hash(vec2 p) {
uvec2 cell=uvec2(ivec2(floor(p)));
uint h=(cell.x+731u)*15485863u ^ (cell.y+1871u)*32452843u;
h=(h^(h>>13u))*49979687u;
h=(h^(h>>16u))*67867967u;
return float((h^(h>>11u))>>8u)/16777216.;
}
float noise(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);
}
mat2 rotate(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }
float fbm(vec2 p) {
mat2 m=mat2(1.73,1.12,-1.12,1.73);
vec2 a=m*p+11., b=m*a+7.;
return .53*noise(p)+.265*noise(a)+.135*noise(b)+.07*noise(m*b);
}
float pixel() { return 2./max(1.,min(uResolution.x,uResolution.y)); }
float inside(float d) {
float w=max(fwidth(d)*.65,.00001);
return 1.-smoothstep(-w,w,d);
}
float sq(float x) { return x*x; }
float gauss(float x) { return exp(-sq(x)); }
vec3 heightNormal(float height) {
return normalize(vec3(-dFdx(height),-dFdy(height),pixel()));
}
vec3 studio(vec3 n,float rough) {
vec3 r=reflect(vec3(0.,0.,-1.),n);
float strip=gauss((r.x+.48*r.y+.32)/(.08+.42*rough));
float window=smoothstep(-.18-rough,.05+rough,r.y+.43*r.x);
float warm=gauss((r.y+.2*r.x+.40)/(.12+.26*rough));
return vec3(.14,.17,.21)+window*vec3(.52,.58,.64)+strip*vec3(.85,.91,.97)+warm*vec3(.57,.37,.19);
}
vec3 copper(vec3 n,float oxide,float grain) {
vec3 metal=vec3(.68,.355,.228)*(.32+.62*studio(n,.36));
metal*=.85+.20*grain;
vec3 crust=mix(vec3(.09,.31,.25),vec3(.52,.73,.58),grain);
return mix(metal,crust,clamp(oxide,0.,1.));
}
vec3 study(vec2 p) {
vec2 q=rotate(-.055)*p;
float weather=fbm(q*5.), grains=fbm(q*70.);
float run=.36-q.y;
float fan=.16+.30*smoothstep(.0,1.35,run);
float wander=.072*sin(3.*run)+.028*sin(8.*run);
float x=q.x+.32-wander;
float flow=fbm(vec2((x+.02*sin(8.*q.y))*16.,q.y*2.6));
float trickle=fbm(vec2(x*51.+1.6*sin(3.1*q.y),q.y*3.3));
float shelf=smoothstep(-.17,.05,run);
float wet=shelf*(1.-smoothstep(fan*.49,fan*1.39,abs(x)+.12*(flow-.5)));
// Two drainage lines leave opposite points of the lower lip, then feather into the wash.
float edgeFlow=gauss((abs(x+.024)-fan*.64)/(.023+.025*smoothstep(0.,1.,run)));
float trace=wet*(.16+.48*flow+.45*trickle+.12*weather+.22*edgeFlow);
// Repeated wetting leaves channels of exposed brown copper between pale crusts.
float streak=smoothstep(.38,.83,trace+.19*(grains-.5));
float margin=gauss((abs(x)-fan*.84)/.083)*shelf;
float lap=q.x-.81-.045*q.y;
float standing=.09*gauss(lap/.050)+.025*gauss((lap-.070)/.028);
float dents=.0034*fbm(q*13.)+.0003*grains;
vec3 n=heightNormal(standing+dents+.005*streak);
float general=smoothstep(.68,.85,weather+.15*grains+.21*gauss(lap/.14));
vec3 col=copper(n,max(streak,general*.70),.51*flow+.49*grains);
col*=.65+.20*weather+.17*gauss((q.x+.2*q.y+.5)/.74)+.15*streak;
col+=vec3(.06,.14,.12)*streak*trickle;
float ledge=gauss((length((q-vec2(-.29,.31))/vec2(.32,.12))-.69)/.63);
col*=1.-.40*ledge;
col=mix(col,vec3(.12,.20,.15),.32*margin*(1.-streak));
col*=1.-.32*gauss((lap-.053)/.019);
// Oblique drain barrel projects from above the plate. The lip is an elliptical annulus.
vec2 pipe=rotate(-.28)*(q-vec2(-.36,.38));
float width=.265;
float side=abs(pipe.x)-width;
float cut=length(vec2(pipe.x/width,pipe.y/.107));
float barrel=inside(side)*smoothstep(-.012,.012,pipe.y);
float shadow=exp(-max(0.,pipe.x-width-.047)/.073)*smoothstep(.0,.16,pipe.y)*smoothstep(.24,.29,pipe.x);
col*=1.-.36*shadow;
float nx=clamp(pipe.x/width,-1.,1.);
vec3 tubeN=normalize(vec3(nx,.15,sqrt(max(.001,1.-nx*nx))));
float tubeWeather=fbm(pipe*vec2(14.,4.));
float tarnish=smoothstep(.48,.79,tubeWeather+.10*grains+.12*abs(nx));
vec3 tube=copper(tubeN,tarnish,.45*tubeWeather+.55*grains);
tube*=.76+.24*sqrt(max(0.,1.-nx*nx))+.13*gauss((nx+.52)/.23);
float bead=gauss((pipe.y-.14)/.035);
tube+=bead*vec3(.16,.116,.064)-.11*gauss((pipe.y-.10)/.015);
col=mix(col,tube,barrel);
vec3 lip=copper(normalize(vec3(nx,-.53,1.)),.58*tarnish,grains)+.13*gauss((cut-.99)/.048);
col=mix(col,lip,inside(cut-1.08));
vec3 bore=mix(vec3(.037,.040,.03),vec3(.27,.155,.083),smoothstep(-.074,.082,pipe.y)*(.58+.39*tubeWeather));
return mix(col,bore,inside(cut-.86));
}
void main() {
vec2 position=(2.0*gl_FragCoord.xy-uResolution)/max(1.0,min(uResolution.x,uResolution.y));
fragColor=vec4(clamp(study(position),0.0,1.0),1.0);
}
shader_type canvas_item;
// Attach to a ColorRect, Sprite2D, or SubViewport texture baker in Godot 4.2+.
// Copper Verdigris Patina — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/wear/lib/05_copper_verdigris_runoff.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-wear-lib-05-copper-verdigris-runoff
// Copper scupper with a rolled lip and a layered verdigris wash down its splash plate.
// WebGL2 fullscreen pass. Set uResolution to drawing-buffer pixels.
float hash(vec2 p) {
uvec2 cell=uvec2(ivec2(floor(p)));
uint h=(cell.x+731u)*15485863u ^ (cell.y+1871u)*32452843u;
h=(h^(h>>13u))*49979687u;
h=(h^(h>>16u))*67867967u;
return float((h^(h>>11u))>>8u)/16777216.;
}
float noise(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);
}
mat2 rotate(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }
float fbm(vec2 p) {
mat2 m=mat2(1.73,1.12,-1.12,1.73);
vec2 a=m*p+11., b=m*a+7.;
return .53*noise(p)+.265*noise(a)+.135*noise(b)+.07*noise(m*b);
}
float pixel() { return 2./max(1.,min(uResolution.x,uResolution.y)); }
float inside(float d) {
float w=max(fwidth(d)*.65,.00001);
return 1.-smoothstep(-w,w,d);
}
float sq(float x) { return x*x; }
float gauss(float x) { return exp(-sq(x)); }
vec3 heightNormal(float height) {
return normalize(vec3(-dFdx(height),-dFdy(height),pixel()));
}
vec3 studio(vec3 n,float rough) {
vec3 r=reflect(vec3(0.,0.,-1.),n);
float strip=gauss((r.x+.48*r.y+.32)/(.08+.42*rough));
float window=smoothstep(-.18-rough,.05+rough,r.y+.43*r.x);
float warm=gauss((r.y+.2*r.x+.40)/(.12+.26*rough));
return vec3(.14,.17,.21)+window*vec3(.52,.58,.64)+strip*vec3(.85,.91,.97)+warm*vec3(.57,.37,.19);
}
vec3 copper(vec3 n,float oxide,float grain) {
vec3 metal=vec3(.68,.355,.228)*(.32+.62*studio(n,.36));
metal*=.85+.20*grain;
vec3 crust=mix(vec3(.09,.31,.25),vec3(.52,.73,.58),grain);
return mix(metal,crust,clamp(oxide,0.,1.));
}
vec3 study(vec2 p) {
vec2 q=rotate(-.055)*p;
float weather=fbm(q*5.), grains=fbm(q*70.);
float run=.36-q.y;
float fan=.16+.30*smoothstep(.0,1.35,run);
float wander=.072*sin(3.*run)+.028*sin(8.*run);
float x=q.x+.32-wander;
float flow=fbm(vec2((x+.02*sin(8.*q.y))*16.,q.y*2.6));
float trickle=fbm(vec2(x*51.+1.6*sin(3.1*q.y),q.y*3.3));
float shelf=smoothstep(-.17,.05,run);
float wet=shelf*(1.-smoothstep(fan*.49,fan*1.39,abs(x)+.12*(flow-.5)));
// Two drainage lines leave opposite points of the lower lip, then feather into the wash.
float edgeFlow=gauss((abs(x+.024)-fan*.64)/(.023+.025*smoothstep(0.,1.,run)));
float trace=wet*(.16+.48*flow+.45*trickle+.12*weather+.22*edgeFlow);
// Repeated wetting leaves channels of exposed brown copper between pale crusts.
float streak=smoothstep(.38,.83,trace+.19*(grains-.5));
float margin=gauss((abs(x)-fan*.84)/.083)*shelf;
float lap=q.x-.81-.045*q.y;
float standing=.09*gauss(lap/.050)+.025*gauss((lap-.070)/.028);
float dents=.0034*fbm(q*13.)+.0003*grains;
vec3 n=heightNormal(standing+dents+.005*streak);
float general=smoothstep(.68,.85,weather+.15*grains+.21*gauss(lap/.14));
vec3 col=copper(n,max(streak,general*.70),.51*flow+.49*grains);
col*=.65+.20*weather+.17*gauss((q.x+.2*q.y+.5)/.74)+.15*streak;
col+=vec3(.06,.14,.12)*streak*trickle;
float ledge=gauss((length((q-vec2(-.29,.31))/vec2(.32,.12))-.69)/.63);
col*=1.-.40*ledge;
col=mix(col,vec3(.12,.20,.15),.32*margin*(1.-streak));
col*=1.-.32*gauss((lap-.053)/.019);
// Oblique drain barrel projects from above the plate. The lip is an elliptical annulus.
vec2 pipe=rotate(-.28)*(q-vec2(-.36,.38));
float width=.265;
float side=abs(pipe.x)-width;
float cut=length(vec2(pipe.x/width,pipe.y/.107));
float barrel=inside(side)*smoothstep(-.012,.012,pipe.y);
float shadow=exp(-max(0.,pipe.x-width-.047)/.073)*smoothstep(.0,.16,pipe.y)*smoothstep(.24,.29,pipe.x);
col*=1.-.36*shadow;
float nx=clamp(pipe.x/width,-1.,1.);
vec3 tubeN=normalize(vec3(nx,.15,sqrt(max(.001,1.-nx*nx))));
float tubeWeather=fbm(pipe*vec2(14.,4.));
float tarnish=smoothstep(.48,.79,tubeWeather+.10*grains+.12*abs(nx));
vec3 tube=copper(tubeN,tarnish,.45*tubeWeather+.55*grains);
tube*=.76+.24*sqrt(max(0.,1.-nx*nx))+.13*gauss((nx+.52)/.23);
float bead=gauss((pipe.y-.14)/.035);
tube+=bead*vec3(.16,.116,.064)-.11*gauss((pipe.y-.10)/.015);
col=mix(col,tube,barrel);
vec3 lip=copper(normalize(vec3(nx,-.53,1.)),.58*tarnish,grains)+.13*gauss((cut-.99)/.048);
col=mix(col,lip,inside(cut-1.08));
vec3 bore=mix(vec3(.037,.040,.03),vec3(.27,.155,.083),smoothstep(-.074,.082,pipe.y)*(.58+.39*tubeWeather));
return mix(col,bore,inside(cut-.86));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 position=(2.0*pfx_frag_xy-uResolution)/max(1.0,min(uResolution.x,uResolution.y));
fragColor=vec4(clamp(study(position),0.0,1.0),1.0);
}
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;
// Copper Verdigris Patina — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/wear/lib/05_copper_verdigris_runoff.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-wear-lib-05-copper-verdigris-runoff
// Copper scupper with a rolled lip and a layered verdigris wash down its splash plate.
// WebGL2 fullscreen pass. Set uResolution to drawing-buffer pixels.
float hash(vec2 p) {
uvec2 cell=uvec2(ivec2(floor(p)));
uint h=(cell.x+731u)*15485863u ^ (cell.y+1871u)*32452843u;
h=(h^(h>>13u))*49979687u;
h=(h^(h>>16u))*67867967u;
return float((h^(h>>11u))>>8u)/16777216.;
}
float noise(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);
}
mat2 rotate(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }
float fbm(vec2 p) {
mat2 m=mat2(1.73,1.12,-1.12,1.73);
vec2 a=m*p+11., b=m*a+7.;
return .53*noise(p)+.265*noise(a)+.135*noise(b)+.07*noise(m*b);
}
float pixel() { return 2./max(1.,min(uResolution.x,uResolution.y)); }
float inside(float d) {
float w=max(fwidth(d)*.65,.00001);
return 1.-smoothstep(-w,w,d);
}
float sq(float x) { return x*x; }
float gauss(float x) { return exp(-sq(x)); }
vec3 heightNormal(float height) {
return normalize(vec3(-dFdx(height),-dFdy(height),pixel()));
}
vec3 studio(vec3 n,float rough) {
vec3 r=reflect(vec3(0.,0.,-1.),n);
float strip=gauss((r.x+.48*r.y+.32)/(.08+.42*rough));
float window=smoothstep(-.18-rough,.05+rough,r.y+.43*r.x);
float warm=gauss((r.y+.2*r.x+.40)/(.12+.26*rough));
return vec3(.14,.17,.21)+window*vec3(.52,.58,.64)+strip*vec3(.85,.91,.97)+warm*vec3(.57,.37,.19);
}
vec3 copper(vec3 n,float oxide,float grain) {
vec3 metal=vec3(.68,.355,.228)*(.32+.62*studio(n,.36));
metal*=.85+.20*grain;
vec3 crust=mix(vec3(.09,.31,.25),vec3(.52,.73,.58),grain);
return mix(metal,crust,clamp(oxide,0.,1.));
}
vec3 study(vec2 p) {
vec2 q=rotate(-.055)*p;
float weather=fbm(q*5.), grains=fbm(q*70.);
float run=.36-q.y;
float fan=.16+.30*smoothstep(.0,1.35,run);
float wander=.072*sin(3.*run)+.028*sin(8.*run);
float x=q.x+.32-wander;
float flow=fbm(vec2((x+.02*sin(8.*q.y))*16.,q.y*2.6));
float trickle=fbm(vec2(x*51.+1.6*sin(3.1*q.y),q.y*3.3));
float shelf=smoothstep(-.17,.05,run);
float wet=shelf*(1.-smoothstep(fan*.49,fan*1.39,abs(x)+.12*(flow-.5)));
// Two drainage lines leave opposite points of the lower lip, then feather into the wash.
float edgeFlow=gauss((abs(x+.024)-fan*.64)/(.023+.025*smoothstep(0.,1.,run)));
float trace=wet*(.16+.48*flow+.45*trickle+.12*weather+.22*edgeFlow);
// Repeated wetting leaves channels of exposed brown copper between pale crusts.
float streak=smoothstep(.38,.83,trace+.19*(grains-.5));
float margin=gauss((abs(x)-fan*.84)/.083)*shelf;
float lap=q.x-.81-.045*q.y;
float standing=.09*gauss(lap/.050)+.025*gauss((lap-.070)/.028);
float dents=.0034*fbm(q*13.)+.0003*grains;
vec3 n=heightNormal(standing+dents+.005*streak);
float general=smoothstep(.68,.85,weather+.15*grains+.21*gauss(lap/.14));
vec3 col=copper(n,max(streak,general*.70),.51*flow+.49*grains);
col*=.65+.20*weather+.17*gauss((q.x+.2*q.y+.5)/.74)+.15*streak;
col+=vec3(.06,.14,.12)*streak*trickle;
float ledge=gauss((length((q-vec2(-.29,.31))/vec2(.32,.12))-.69)/.63);
col*=1.-.40*ledge;
col=mix(col,vec3(.12,.20,.15),.32*margin*(1.-streak));
col*=1.-.32*gauss((lap-.053)/.019);
// Oblique drain barrel projects from above the plate. The lip is an elliptical annulus.
vec2 pipe=rotate(-.28)*(q-vec2(-.36,.38));
float width=.265;
float side=abs(pipe.x)-width;
float cut=length(vec2(pipe.x/width,pipe.y/.107));
float barrel=inside(side)*smoothstep(-.012,.012,pipe.y);
float shadow=exp(-max(0.,pipe.x-width-.047)/.073)*smoothstep(.0,.16,pipe.y)*smoothstep(.24,.29,pipe.x);
col*=1.-.36*shadow;
float nx=clamp(pipe.x/width,-1.,1.);
vec3 tubeN=normalize(vec3(nx,.15,sqrt(max(.001,1.-nx*nx))));
float tubeWeather=fbm(pipe*vec2(14.,4.));
float tarnish=smoothstep(.48,.79,tubeWeather+.10*grains+.12*abs(nx));
vec3 tube=copper(tubeN,tarnish,.45*tubeWeather+.55*grains);
tube*=.76+.24*sqrt(max(0.,1.-nx*nx))+.13*gauss((nx+.52)/.23);
float bead=gauss((pipe.y-.14)/.035);
tube+=bead*vec3(.16,.116,.064)-.11*gauss((pipe.y-.10)/.015);
col=mix(col,tube,barrel);
vec3 lip=copper(normalize(vec3(nx,-.53,1.)),.58*tarnish,grains)+.13*gauss((cut-.99)/.048);
col=mix(col,lip,inside(cut-1.08));
vec3 bore=mix(vec3(.037,.040,.03),vec3(.27,.155,.083),smoothstep(-.074,.082,pipe.y)*(.58+.39*tubeWeather));
return mix(col,bore,inside(cut-.86));
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 position=(2.0*pfx_frag_xy-uResolution)/max(1.0,min(uResolution.x,uResolution.y));
fragColor=vec4(clamp(study(position),0.0,1.0),1.0);
}
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.85;
EMISSION = tinted * 0.0;
}
// Copper Verdigris Patina — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/wear/lib/05_copper_verdigris_runoff.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-wear-lib-05-copper-verdigris-runoff
// Copper scupper with a rolled lip and a layered verdigris wash down its splash plate.
// WebGL2 fullscreen pass. Set uResolution to drawing-buffer pixels.
precision highp float;
precision highp int;
uniform vec2 uResolution;
out vec4 fragColor;
float hash(vec2 p) {
uvec2 cell=uvec2(ivec2(floor(p)));
uint h=(cell.x+731u)*15485863u ^ (cell.y+1871u)*32452843u;
h=(h^(h>>13u))*49979687u;
h=(h^(h>>16u))*67867967u;
return float((h^(h>>11u))>>8u)/16777216.;
}
float noise(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);
}
mat2 rotate(float a) { return mat2(cos(a),sin(a),-sin(a),cos(a)); }
float fbm(vec2 p) {
mat2 m=mat2(1.73,1.12,-1.12,1.73);
vec2 a=m*p+11., b=m*a+7.;
return .53*noise(p)+.265*noise(a)+.135*noise(b)+.07*noise(m*b);
}
float pixel() { return 2./max(1.,min(uResolution.x,uResolution.y)); }
float inside(float d) {
float w=max(fwidth(d)*.65,.00001);
return 1.-smoothstep(-w,w,d);
}
float sq(float x) { return x*x; }
float gauss(float x) { return exp(-sq(x)); }
vec3 heightNormal(float height) {
return normalize(vec3(-dFdx(height),-dFdy(height),pixel()));
}
vec3 studio(vec3 n,float rough) {
vec3 r=reflect(vec3(0.,0.,-1.),n);
float strip=gauss((r.x+.48*r.y+.32)/(.08+.42*rough));
float window=smoothstep(-.18-rough,.05+rough,r.y+.43*r.x);
float warm=gauss((r.y+.2*r.x+.40)/(.12+.26*rough));
return vec3(.14,.17,.21)+window*vec3(.52,.58,.64)+strip*vec3(.85,.91,.97)+warm*vec3(.57,.37,.19);
}
vec3 copper(vec3 n,float oxide,float grain) {
vec3 metal=vec3(.68,.355,.228)*(.32+.62*studio(n,.36));
metal*=.85+.20*grain;
vec3 crust=mix(vec3(.09,.31,.25),vec3(.52,.73,.58),grain);
return mix(metal,crust,clamp(oxide,0.,1.));
}
vec3 study(vec2 p) {
vec2 q=rotate(-.055)*p;
float weather=fbm(q*5.), grains=fbm(q*70.);
float run=.36-q.y;
float fan=.16+.30*smoothstep(.0,1.35,run);
float wander=.072*sin(3.*run)+.028*sin(8.*run);
float x=q.x+.32-wander;
float flow=fbm(vec2((x+.02*sin(8.*q.y))*16.,q.y*2.6));
float trickle=fbm(vec2(x*51.+1.6*sin(3.1*q.y),q.y*3.3));
float shelf=smoothstep(-.17,.05,run);
float wet=shelf*(1.-smoothstep(fan*.49,fan*1.39,abs(x)+.12*(flow-.5)));
// Two drainage lines leave opposite points of the lower lip, then feather into the wash.
float edgeFlow=gauss((abs(x+.024)-fan*.64)/(.023+.025*smoothstep(0.,1.,run)));
float trace=wet*(.16+.48*flow+.45*trickle+.12*weather+.22*edgeFlow);
// Repeated wetting leaves channels of exposed brown copper between pale crusts.
float streak=smoothstep(.38,.83,trace+.19*(grains-.5));
float margin=gauss((abs(x)-fan*.84)/.083)*shelf;
float lap=q.x-.81-.045*q.y;
float standing=.09*gauss(lap/.050)+.025*gauss((lap-.070)/.028);
float dents=.0034*fbm(q*13.)+.0003*grains;
vec3 n=heightNormal(standing+dents+.005*streak);
float general=smoothstep(.68,.85,weather+.15*grains+.21*gauss(lap/.14));
vec3 col=copper(n,max(streak,general*.70),.51*flow+.49*grains);
col*=.65+.20*weather+.17*gauss((q.x+.2*q.y+.5)/.74)+.15*streak;
col+=vec3(.06,.14,.12)*streak*trickle;
float ledge=gauss((length((q-vec2(-.29,.31))/vec2(.32,.12))-.69)/.63);
col*=1.-.40*ledge;
col=mix(col,vec3(.12,.20,.15),.32*margin*(1.-streak));
col*=1.-.32*gauss((lap-.053)/.019);
// Oblique drain barrel projects from above the plate. The lip is an elliptical annulus.
vec2 pipe=rotate(-.28)*(q-vec2(-.36,.38));
float width=.265;
float side=abs(pipe.x)-width;
float cut=length(vec2(pipe.x/width,pipe.y/.107));
float barrel=inside(side)*smoothstep(-.012,.012,pipe.y);
float shadow=exp(-max(0.,pipe.x-width-.047)/.073)*smoothstep(.0,.16,pipe.y)*smoothstep(.24,.29,pipe.x);
col*=1.-.36*shadow;
float nx=clamp(pipe.x/width,-1.,1.);
vec3 tubeN=normalize(vec3(nx,.15,sqrt(max(.001,1.-nx*nx))));
float tubeWeather=fbm(pipe*vec2(14.,4.));
float tarnish=smoothstep(.48,.79,tubeWeather+.10*grains+.12*abs(nx));
vec3 tube=copper(tubeN,tarnish,.45*tubeWeather+.55*grains);
tube*=.76+.24*sqrt(max(0.,1.-nx*nx))+.13*gauss((nx+.52)/.23);
float bead=gauss((pipe.y-.14)/.035);
tube+=bead*vec3(.16,.116,.064)-.11*gauss((pipe.y-.10)/.015);
col=mix(col,tube,barrel);
vec3 lip=copper(normalize(vec3(nx,-.53,1.)),.58*tarnish,grains)+.13*gauss((cut-.99)/.048);
col=mix(col,lip,inside(cut-1.08));
vec3 bore=mix(vec3(.037,.040,.03),vec3(.27,.155,.083),smoothstep(-.074,.082,pipe.y)*(.58+.39*tubeWeather));
return mix(col,bore,inside(cut-.86));
}
void main() {
vec2 position=(2.0*gl_FragCoord.xy-uResolution)/max(1.0,min(uResolution.x,uResolution.y));
fragColor=vec4(clamp(study(position),0.0,1.0),1.0);
}
`;
export function createCopperVerdigrisPatinaMaterial(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 | copper-verdigris-patina |
|---|---|
| Category | Metals & Armor Shaders · Weathered Armor |
| Upstream study | wear/lib/05_copper_verdigris_runoff.glsl (commit 1fbd084) |
| Animation cycle | Static analytical PBR surface |
| Declared uniforms | uResolution |
| Source size | 118 lines · 4.8 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
Standalone GLSL ES 3.00 math primitives
AnimatedEncroaching flaky orange-ochre iron oxide eating across painted industrial steel.
AnimatedCNC-lathed 6061 aluminum surface with concentric anisotropic micro-grooves and bowtie specular.
AnimatedHot-dip galvanized steel sheet with Voronoi crystalline zinc spangle facets and grain orientation.
AnimatedDual-layer metallic paint with stochastic aluminum micro-flakes under glossy dielectric clearcoat.
AnimatedThin-film oxide interference on bead-blasted titanium shifting across violet, cobalt, and gold.
AnimatedHeavy foundry cast iron with mold-sand stipple micro-relief, graphite dark oxide, and parting seam.