GLSL shader example
Bayer Ordered Dithering
A fixed 4×4 threshold pattern turns gray into binary dots. Cell scale magnifies the pattern without changing source luminance.
Live example
Edit the code and the preview updates as you type.
What to observe
Bayer Ordered Dithering.
Mechanism
A fixed 4×4 threshold pattern turns gray into binary dots. Cell scale magnifies the pattern without changing source luminance.
The controlling code
vec3 src=texture2D(u_texture,uv).rgb;float gray=dot(src,vec3(.2126,.7152,.0722));vec2 q=mod(floor(gl_FragCoord.xy/(1.+floor(u_parameter*3.))),4.);float row=mod(q.y,2.)*2.+mod(floor(q.y/2.),2.)*.5;float b=mod(q.x,2.)*2.+mod(floor(q.x/2.),2.)*.5;float threshold=mod((b*2.+row),4.)/4.+floor(b)/4.;c=vec3(step(fract(threshold),gray));
Experiment
Move u_parameter from 0 to 1 to increase 1.+floor(u_parameter*3.) from one to four screen pixels per threshold cell. The binary pattern grows larger without adding gray output levels.
Debugging and cost
This filter reads the source once, then computes a 4×4 threshold pattern arithmetically. Replace gray in the final step call with 0.5 to inspect the fixed half-brightness pattern independently of the colored fixture.