Design.dev design.dev
Backgrounds · Component Template

Halftone Shader

A ray-marched still life printed in real halftone dots. Turn it by hand, pull the plates out of register, and look through a loupe.

Live demo

Output of this prompt · Claude Fable 5.2 · WebGL

Drag the still life to turn it, then switch the inks, the screen, the register, or the loupe.

The Prompt 1,087 words

Build a full-viewport halftone of a 3D still life.
The picture is a print, not a render with a filter on it.
Four inks, each screened on its own rotated grid, so a sphere, a torus, a box and a cup are made of dots and the paper between them stays clean.
Dragging turns the still life.
A loupe follows the pointer and shows the same print about three times closer.
It should look like a proof on a light table.

Match my project's existing stack, conventions, and design tokens.
If there are none, output a single HTML file with inline CSS and JavaScript and zero dependencies.

LOOK
Paper #efede6, ink #1d1d1b, dim ink at 64% opacity, hairline #1d1d1b at 14% opacity.
System sans only.
The stage fills the viewport, 100svh with a 460px minimum, and clips overflow.
Top left, an h1 reading Halftone, size clamp(34px, 4.6vw, 64px), line-height 0.92, letter-spacing -0.05em, as heavy as the face allows.
Under it one sentence, "A live four-color print of a 3D still life, screened at 15°, 75°, 0° and 45°. Drag to turn it." Hide that sentence below 760px.
Top right, four 14px dots hidden from assistive tech, in cyan #00a3dd, magenta #e5007d, yellow #ffe600 and black #1d1d1b.
Along the bottom, a dock only as wide as its contents, centered, wrapping, radius 14px, paper at 90% opacity, 10px backdrop blur, a hairline and a soft shadow.
Inside it, a fieldset named Print with three real radios, CMYK checked, Riso and Mono, drawn as a segmented control whose black pill slides between them.
A Screen range from 4 to 18, step 1, default 8, with an output reading "8 px".
A Misregister range from 0 to 10, default 2, with an output "2 px".
A Loupe checkbox, checked.
Ranges are 110px wide, 80px below 760px, with a 14px round thumb and a track filled up to the current value.
Below 760px, hide the range names visually but keep them for assistive tech, and hide the loupe.
Focus is a 2px ink outline.

THE PRINT
WebGL1 only, one canvas, GLSL ES 1.00.
Do not add a float to a vector, do not build vec4 from one float, and do not pass a float to max, min or clamp when the other value is a vector.
Check every shader compile and the program link.
If either fails, or WebGL is missing, keep the controls and center one line, "This print needs WebGL, which this browser has turned off." Cap the drawing buffer at twice the CSS size.
Draw with one oversized triangle.

Pass 1 paints the still life into a render target about 38% of the screen on each side, linear filtered, and only when the camera or the size changes.
Ray march a floor, a sphere on the left, a torus, a rounded box and a short cylinder.
Give them paper, red, blue, yellow and green surfaces.
Light them from the upper left with a short shadow march, a few steps of ambient occlusion, and a tight specular on everything but the floor.
Fade the floor back to paper with distance so only the objects take ink.
The eye orbits a point near the middle of the group, starting at a slight yaw and a low pitch, and sits a little farther back below 760px.
When that target is rebuilt, delete the previous framebuffer and texture first.

Pass 2 is the screen, at full resolution.
Turn the sampled color into inks.
CMYK uses undercolor removal and prints the black plate a little light.
Riso prints two plates only, a blue from the missing red and a fluorescent pink from the missing green.
Mono prints black from a weighted luminance.
Each plate is a rotated grid.
Cell size is the Screen value in CSS pixels times the pixel ratio.
Read the ink at each cell center and draw a dot whose radius is the square root of the coverage, about two thirds of a cell, so a large dot reaches into its neighbors.
CMYK sits at 15, 75, 0 and 45 degrees.
Riso sits near 22 and 67 degrees.
Mono sits at 45.
Misregister shifts the color plates by the slider value in CSS pixels and leaves the black plate put.
Drop anything under about 2.5% ink so bare paper stays bare, and roughen the dot edge with a little value noise.
Paper is a warm off-white, near rgb 0.937, 0.929, 0.902, with fine grain.
Overprint by multiplying.
The loupe runs only when it is checked, the pointer is over the canvas, and the stage is at least 760px wide.
It is a disc about 86 device pixels across, centered on the pointer.
Inside it, sample the print at about a third of the offset from the pointer, darken the rim, and dim the print just outside the rim.

MOTION
Until the first drag, yaw advances at about 0.12 radians a second.
A drag changes yaw by about 0.008 radians per horizontal pixel and pitch by about 0.005 per vertical pixel.
Clamp pitch so the eye cannot go under the floor or over the top.
Releasing keeps the turn and lets it decay to a stop.
The segmented pill moves over about 630ms on a spring.
With prefers-reduced-motion, do not spin on load, do not coast, and redraw only when something changes.

BEHAVIOR
Pointer down captures the pointer and shows a grabbing cursor.
Moving over the canvas moves the loupe.
Leaving hides it.
Changing the mode writes "Four-color process", "Two-color risograph" or "Black only" into a polite live region.
Ranges update their outputs and the filled part of the track.
The checkbox toggles the loupe.
Keep drawing while the stage is on screen and the tab is visible, and draw once when it returns.

ACCESSIBILITY
The canvas and the ink dots are hidden from assistive tech.
One h1.
The mode control is a real fieldset of radios.
Each range sits in a label with its output.
The loupe is a real checkbox.
Reduced motion leaves every control working on a still print.
Say "color", not "colour".

NEVER
- Never fake the halftone with a CSS filter, a blur, or a post effect on a smooth picture.
The dots are the picture.
- Never speckle the paper with ink below the cutoff.
- Never keep the idle spin going after a drag, and never spin at all when motion is reduced.
- Never leave the previous render target allocated after a resize.
- No libraries, no images, no fonts loaded from a network.
  1. CopyThe full prompt, one click.
  2. PasteInto Cursor, Claude Code, or any agent.
  3. CompareAgainst the live demo above.
Halftone Shader
Copied to clipboard