Features
- Multiple dithering algorithms (random, 2x2, 4x4, 8x8 Bayer matrices)
- Custom color palettes (2-7 colors)
- Original color preservation mode
- Inverted luminance option
- Adjustable pixel grid size
- Retro/vintage aesthetic
Basic Usage
Parameters
Visual Parameters
string | HTMLImageElement
required
Source image to apply the dithering effect to
'random' | '2x2' | '4x4' | '8x8'
default:"'8x8'"
Dithering algorithm type:
random: Random noise dithering2x2: 2×2 Bayer matrix (coarse pattern)4x4: 4×4 Bayer matrix (medium pattern)8x8: 8×8 Bayer matrix (fine pattern)
number
default:"2"
Pixel size of the dithering grid in screen pixels
string
default:"'#94ffaf'"
Primary foreground color in hex, rgb, or rgba format
string
default:"'#000c38'"
Background color in hex, rgb, or rgba format
string
default:"'#eaff94'"
Secondary foreground color (set same as colorFront for classic 2-color dithering)
number
default:"2"
Number of color levels to use in the output. Higher values create smoother gradients.
boolean
default:"false"
Use the original colors of the image instead of the custom color palette
boolean
default:"false"
Inverts the image luminance (doesn’t affect the color scheme)
Sizing Parameters
'none' | 'contain' | 'cover'
default:"'cover'"
How to fit the shader into the canvas dimensions
number
default:"1"
Overall zoom level of the graphics
number
default:"0"
Overall rotation angle in degrees
number
default:"0"
Horizontal offset of the graphics center
number
default:"0"
Vertical offset of the graphics center
Animation Parameters
number
default:"0"
Animation speed multiplier (0 for static)
number
default:"0"
Manual frame control for animation
Presets
The ImageDithering shader comes with several built-in presets:- Default: 8×8 dithering with custom 3-color palette
- Noise: Random dithering with warm colors
- Retro: 2×2 dithering preserving original colors
- Natural: 8×8 dithering with original colors and 5 levels
Examples
Classic Two-Color Dithering
Retro Game Effect
Noise Effect
Natural Gradient
Technical Details
Shader Uniforms (Vanilla JS)
When using the vanilla JavaScript API:Dithering Types
random(1): Random noise pattern2x2(2): Coarse 2×2 Bayer matrix4x4(3): Medium 4×4 Bayer matrix8x8(4): Fine 8×8 Bayer matrix
Color Modes
Custom Palette Mode (originalColors: false):
- Uses
colorFront,colorBack, andcolorHighlight colorHighlightis used for the brightest areascolorStepscontrols gradient smoothness
originalColors: true):
- Preserves image colors while applying dithering
colorStepscontrols quantization levels- Color palette parameters are ignored
Performance Notes
- Static shader (no animation by default)
- Pixel-based rendering for crisp dithering
- Performance scales with canvas size
- Lower
sizevalues = more pixels = slower rendering - Bayer matrices (2×2, 4×4, 8×8) are faster than random
