Task 1 of 6
A signed distance field describes a shape with one function:
for any point in space it returns the distance to the nearest surface — positive outside,
negative inside, exactly zero on the skin. A whole sphere collapses into one line:
length(p - center) - radius. No vertices, no triangles, just math.
That's a perfect fit for a kernel: one thread per sample point, each evaluating the same
tiny function. Here every pixel owns a point on the z = 0 slice through the
scene — pixel (ix, iy) maps to world ((ix - 32) / 16, (iy - 32) / 16),
so the canvas spans −2…2 and the center pixel sits exactly at the origin.
(cx, cy) with radius r.(this.thread.x - 32) / 16 (already wired up)(wx - cx, wy - cy)Math.sqrt, minus rFor the unit sphere at the origin: the center pixel is inside, distance
-1. A pixel one unit from the center sits exactly on the surface —
distance 0. The far corner at (−2, −2) reads √8 − 1 ≈ 1.83.
const dx = wx - cx;
const dy = wy - cy;
return Math.sqrt(dx * dx + dy * dy) - r;This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.