Skip to content

About

A browser image editor that runs every filter and layer composite on the GPU through WebGPU compute and render shaders.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

gpu-editor

A browser image editor that runs every filter and layer composite on the GPU through WebGPU compute and render shaders. Open a photo, stack non-destructive filters, composite layers with blend modes, and export. Nothing leaves your machine.

React 19 Vite 8 WebGPU + WGSL TypeScript strict 100% client-side

The editor: a graded mountain photo on the GPU canvas, a layers panel with blend and opacity, and a non-destructive filter stack

There is no server. The image is decoded to a texture, every filter is a WGSL compute shader, and the layers are composited by a blend shader, all on your GPU. The source pixels are never modified; the filter stack and layers are re-evaluated on each change and the result is drawn to a WebGPU canvas. A browser without WebGPU sees a clean unsupported screen, because the whole point of the tool is the GPU pipeline.

How it works

  1. An image is decoded with createImageBitmap and uploaded to a premultiplied-alpha texture. The document lives in React state; the GPU only holds textures.
  2. Each image layer runs its own filter stack. Filters are compute shaders that ping-pong between two storage textures, because WebGPU cannot read and write the same storage texture in one pass.
  3. Neighborhood filters (blur, sharpen, edge detect, bilateral) load their pixel window into workgroup shared memory once, then read neighbors from there instead of re-sampling the texture per tap.
  4. The compositor folds the layers bottom to top, blending each into an accumulator in premultiplied space with a single shader branched across all 16 W3C blend modes. Adjustment layers read the accumulator, run their stack, and composite back, so they affect everything below.
  5. The final texture is drawn to the canvas. Rendering is on a dirty flag with a single requestAnimationFrame, so an idle document does no work.
  6. During a slider drag the chain renders at half resolution for a responsive preview, then re-renders at full resolution on release. Undo and redo replay immer patches over the document.
  7. Export re-composites every layer at full document resolution and encodes the result to PNG, JPEG, or WebP.

Features

Non-destructive filter stack. Add filters from a searchable list, reorder them by drag, toggle each one, and tune it with a slider or a numeric field. The source pixels are never touched, so any edit is reversible and the order is the pipeline order. Ten filters ship: brightness/contrast, saturation/hue, gaussian blur, unsharp sharpen, Sobel edge detect, color grade (matrix and 3D LUT), bilateral noise reduction, invert, and vignette.

The filter panel: a stack of Saturation, Brightness/Contrast, and Vignette, with Brightness/Contrast expanded to its sliders and numeric fields

Layers and blend modes. Stack multiple image layers, each with its own filter stack, plus adjustment layers that apply to everything beneath them. Every layer has per-layer opacity and all 16 W3C blend modes, from Multiply and Screen to the four HSL modes, matched exactly to the spec formulas. Hovering a blend mode previews it live; clicking commits it.

Two image layers composited with the blend-mode dropdown open, showing Normal through Color Dodge

Honest performance readout. The status bar shows the real measured GPU time per frame. The comparison tool runs the same filter stack on the GPU and on a pure-TypeScript CPU path, then reports the median over warmed-up runs and the ratio derived from those two numbers. It is measured on your image and your hardware. There is no hardcoded speedup anywhere in the code.

The GPU vs CPU comparison modal: GPU 0.162 ms chain, 3.1 ms end to end, CPU 253 ms, 81.5x faster on this run

Every filter is a real shader. The grid below is one photo run through the actual WGSL shaders, read back pixel by pixel. Brightness/contrast, saturation, vignette, color grade, gaussian blur, sharpen, Sobel edge detect, bilateral denoise, and invert, each computed on the GPU.

One photo processed by nine different GPU filters, laid out in a labeled grid

Viewport and I/O. Import PNG, JPEG, and WebP by drop, paste, or file picker. Pan, zoom toward the cursor, fit to screen, snap to zoom presets, and a checkerboard that scales with the image for transparency. Undo and redo span the whole document, layers and filters included. Export the full composited result.

Tech

Layer Choice
Framework React 19 + Vite 8, a standalone SPA with no SSR
Language TypeScript 6, strict mode with noUncheckedIndexedAccess
GPU WebGPU + WGSL for all image processing (compute and render passes)
State Zustand for the store, immer for patch-based undo/redo
Styling Tailwind CSS v4 with CSS-variable theming
UI dnd-kit (drag to reorder), react-colorful, react-resizable-panels, sonner, lucide-react
Validation Zod with .strict() on every filter parameter schema
Testing Vitest + Testing Library (unit and component), Playwright (e2e), golden-image tests on a real GPU
Tooling Biome for lint and format

Notes on the pipeline

  • Premultiplied alpha end to end. The source upload and every filter write premultiplied color, so a weighted sum of neighbors is already valid premultiplied and blur needs no round-trip. The blend shader un-premultiplies only to evaluate the blend function on straight color, then stores the premultiplied result. Comparing premultiplied is also the honest correctness metric, since un-premultiplying amplifies quantization on near-transparent pixels.
  • Ping-pong, not read-write. A storage texture in WGSL cannot be read_write for the rgba8unorm format, so filters alternate between two textures. The runner keeps the result texture out of the pool until the next pass consumes it.
  • Shared-memory tiling. Blur and bilateral load an along-axis tile into var<workgroup> once per workgroup; edge detect uses a tile with a one-texel halo. Neighbor reads then hit shared memory instead of the texture.
  • One blend shader, sixteen modes. All 16 W3C modes are one compute pipeline branched by a mode index uniform, so there is a single golden path to verify. Each composited layer gets its own params buffer; sharing one buffer silently made every layer use the top layer's opacity, a bug the multi-layer golden test caught on real hardware.
  • Hot and cold state. The pan and zoom transform lives in a component ref and drives the canvas imperatively, never through React, so a 60fps drag stays off the React tree. Only committed values are published to the store.
  • Measured, not claimed. The CPU baseline reuses the same pure-TypeScript filter references the golden tests verify, so the CPU and GPU run the identical algorithm and the millisecond comparison is apples to apples.

Requirements

A WebGPU-capable browser: Chrome or Edge 113+, Firefox 141+ (Windows) or 145+ (macOS), Safari 26+. Browsers without WebGPU get a clean unsupported screen with the versions above. There is no Canvas2D fallback editor by design.

Running locally

npm install
npm run dev

Open the printed local URL and drop in an image. Build for production with npm run build and preview it with npm run preview.

Testing

npm run test        # unit and component (vitest)
npm run test:e2e    # end to end (playwright)
npm run typecheck   # tsc, whole project
npm run lint        # biome

The golden-image tests upload known pixels, run the real shaders, read the result back, and compare it to the pure-TypeScript reference for every filter and every blend mode. They run on a real GPU; on a machine without a WebGPU adapter they skip cleanly.

About

A browser image editor that runs every filter and layer composite on the GPU through WebGPU compute and render shaders.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages