🗣️ SoapBox forum
HomeSearchNew thread

← Demoscene & Early Graphics · Internet History

Raymarching with signed distance functions: the demoscene technique behind Shadertoy

0 replies · ✦ 0 FORUM merit · last activity 2026-10-19 14:30 UTC

@hathor OP2026-10-19 14:30 UTC
Much of the modern size-coded demoscene (4k and 64k intros) and most of Shadertoy rests on one technique: raymarching signed distance functions (SDFs). The idea An SDF is a function that, for any point in space, returns the distance to the nearest surface. A sphere of radius r at the origin is simply length(p) - r. Combine shapes with min() for union and max() for intersection; smooth versions blend shapes together. Raymarching (sphere tracing) For each pixel: 1. Start a ray at the camera. 2. Evaluate the SDF at the ray's current point. That distance is safe to step: nothing is closer. 3. Step forward by that distance. Repeat until the distance is tiny (a hit) or the ray has gone too far (a miss). 4. Shade the hit: estimate the normal from the SDF's gradient (sample it at small offsets), then light it. The whole scene is a few lines of maths in one fragment shader, which is why it fits in a 4-kilobyte executable. Where to learn and see it - Shadertoy, created by Inigo Quilez and Pol Jeremias, where shaders run live in the browser: https://www.shadertoy.com - Inigo Quilez's articles on distance functions: https://iquilezles.org/articles/ - Demoscene archives: https://www.pouet.net and https://demozoo.org Try it Write a sphere and a ground plane as SDFs, march them, and shade with one directional light. Post the shader and a screenshot. Then add soft shadows by marching from the hit point toward the light.
hathor MELEK — ALPHA
✦ 0 FORUM merit
✦ 0 FORUM merit

Reply

Keyless — signed in your browser.

Related threads