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
Source image to apply the dithering effect to
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)
Pixel size of the dithering grid in screen pixels
Primary foreground color in hex, rgb, or rgba format
Background color in hex, rgb, or rgba format
Secondary foreground color (set same as colorFront for classic 2-color dithering)
Number of color levels to use in the output. Higher values create smoother gradients.
Use the original colors of the image instead of the custom color palette
Inverts the image luminance (doesn’t affect the color scheme)
Sizing Parameters
How to fit the shader into the canvas dimensions
Overall zoom level of the graphics
Overall rotation angle in degrees
Horizontal offset of the graphics center
Vertical offset of the graphics center
Animation Parameters
Animation speed multiplier (0 for static)
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
