Skip to main content
Image Dithering is an image filter shader that posterizes an input image using ordered or random dithering algorithms. It supports predefined 2- and 3-color palettes as well as sampling colors directly from the original image, and exposes controls for dithering type, pixel size, and color step count.
This is an image filter shader — it requires an image input. In React, pass a URL string to the image prop and it is loaded automatically. In vanilla JS, pass a fully loaded HTMLImageElement to u_image.

Usage

import { ImageDithering } from '@paper-design/shaders-react';

export default function Example() {
  return (
    <ImageDithering
      image="/my-photo.jpg"
      type="8x8"
      size={2}
      colorFront="#94ffaf"
      colorBack="#000c38"
      colorHighlight="#eaff94"
      colorSteps={2}
      originalColors={false}
      inverted={false}
      style={{ width: 600, height: 400 }}
    />
  );
}

Props

image
string (React) | HTMLImageElement (vanilla JS)
required
The source image to dither. In React, pass a URL string — the component loads it automatically. In vanilla JS, pass a fully loaded HTMLImageElement as u_image.
type
DitheringType
default:"'8x8'"
The dithering algorithm. Use the DitheringTypes enum (vanilla JS) or string literal (React).
ValueDescription
randomRandomized threshold dithering
2x22×2 Bayer ordered dithering
4x44×4 Bayer ordered dithering
8x88×8 Bayer ordered dithering
size
number
default:"2"
Pixel size of the dithering grid in screen pixels. Range: 0.5 to 20.
colorSteps
number
default:"2"
Number of quantization levels applied to both color modes. Range: 1 to 7.
originalColors
boolean
default:"false"
When true, colors are sampled directly from the original image rather than using the colorFront / colorBack / colorHighlight palette.
inverted
boolean
default:"false"
Inverts the image luminance before dithering. Has no effect when colorSteps is at its minimum (zero contrast).
colorFront
string
default:"'#94ffaf'"
Foreground (dark) color used in the dithering palette when originalColors is false.
colorBack
string
default:"'#000c38'"
Background (light) color used in the dithering palette when originalColors is false.
colorHighlight
string
default:"'#eaff94'"
Secondary foreground color blended in at the brightest steps. Set equal to colorFront for classic 2-color dithering.

Presets

The following presets are exported from @paper-design/shaders-react:
ExportNameDescription
defaultPresetDefault8×8 Bayer with a green/navy palette
noisePresetNoiseRandom dithering in monochrome
retroPresetRetro2×2 Bayer using original image colors
naturalPresetNatural8×8 Bayer in grayscale with 5 color steps
import { imageDitheringPresets } from '@paper-design/shaders-react';

Enums

Import DitheringTypes from @paper-design/shaders when using the vanilla JS API:
import { DitheringTypes } from '@paper-design/shaders';

// DitheringTypes: random | '2x2' | '4x4' | '8x8'

Build docs developers (and LLMs) love