Back to shaders

Shader test bench

Stained Glass Mosaic

stronghold-curated pattern 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;
vec2 hash(vec2 p){p=vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3)));return fract(sin(p)*43758.5453);} 
void main(){
 vec2 uv=gl_FragCoord.xy/resolution.xy; uv.x*=resolution.x/resolution.y;
 vec2 g=uv*8.0,id=floor(g),f=fract(g); float d=9.0; vec2 cell=vec2(0.0);
 for(int y=-1;y<=1;y++)for(int x=-1;x<=1;x++){vec2 o=vec2(float(x),float(y));vec2 r=hash(id+o);float nd=length(o+r-f);if(nd<d){d=nd;cell=id+o;}}
 float lead=smoothstep(0.06,0.025,d);
 vec3 glass=0.5+0.5*cos(vec3(0.0,2.2,4.4)+hash(cell).x*6.283+time*0.05);
 gl_FragColor=vec4(mix(glass*0.85,vec3(0.02),lead),1.0);
}