Dither Shader

A real-time ordered dithering effect for images, perfect for pixel art and retro aesthetics.

Installation

pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/dither-shader.json

Usage

<script lang="ts">	import { DitherShader } from "#lib/components/magic/dither-shader/index.js";</script>
<DitherShader	src="https://images.unsplash.com/photo-1493246507139-91e8fad9978e"	class="h-80 w-full"/>

Examples

Dither Shader Demo Simple

An example showcasing the Dither Shader component in action.

Dither Shader Demo Duotone

Emerald Halftone

Use a two-color palette and halftone pattern for an image thumbnail.

emerald halftone

Pixel Density

Compare a simple ocean image at three grid sizes in taller image containers.

gridSize = 2
gridSize = 4
gridSize = 8

Four-Color Palette

Map soft mountain layers to four warm tones ordered from darkest to lightest.

four-color palette

Props

Dither Shader

A component for Dither Shader.

NameTypeDefaultDescription
srcstringSource image URL (required).
gridSizenumber4Size of the dithering grid cells.
ditherMode"bayer" | "halftone" | "noise" | "crosshatch""bayer"Type of dithering pattern to use.
colorMode"original" | "grayscale" | "duotone" | "custom""original"Color processing mode for the output.
invertbooleanfalseInvert the dithered output colors.
pixelRationumber1Pixelation multiplier (1 = no pixelation, higher = more pixelated).
primaryColorstring"#000000"Primary color for duotone mode.
secondaryColorstring"#ffffff"Secondary color for duotone mode.
customPalettestring[]["#000000", "#ffffff"]Custom color palette array for custom mode.
brightnessnumber0Brightness adjustment (-1 to 1).
contrastnumber1Contrast adjustment (0 to 2, 1 = normal).
backgroundColorstring"transparent"Background color behind the dithered image.
objectFit"cover" | "contain" | "fill" | "none""cover"Object fit behavior for the source image.
thresholdnumber0.5Threshold bias for dithering (0 to 1).
animatedbooleanfalseEnable animation effect.
animationSpeednumber0.02Animation speed (lower = slower).
classClassValue""Additional CSS classes for the container (use this to set size via Tailwind).