Skip to content

SdfShapesEffect

Source: SdfShapesEffect.h

SdfShapesEffect

class SdfShapesEffect
src/light/effects/SdfShapesEffect.h:31

Inherits: EffectBase

Effect: two SDF shapes orbiting and melting together, with a soft edge and an outline.

SdfShapesEffect card SdfShapesEffect controls

Two shapes drawn from signed distance fields rather than by rasterizing outlines. smin blends them, so they flow together like mercury rather than merely overlapping.

Prior art: Inigo Quilez's distance-function catalogue and his polynomial smooth-minimum.

Public Attributes

uint8_t bpm = 12 : Orbit speed.

uint8_t radius = 60 : Circle radius, as a fraction of the short side.

uint8_t boxSize = 45 : Box half-extent, on the same scale.

uint8_t blend = 90 : The melt radius, where 0 unions the shapes hard into the classic two-circles look.

uint8_t outline = 0 : Draw an outline of this width rather than filling, where 0 fills.

bool glow = true : Tint the surrounding field by its distance from the shape.

Public Methods

virtual inline const char * tags() const override : Catalog tags: this effect is the power-function showcase.

virtual inline Dim dimensions() const override : Writes the z=0 slice, which extrude fills through a volume.

virtual inline void defineControls() override : Publish the orbit, both shapes, the melt and the two draw styles.

virtual inline void tick() override : Ask each pixel its distance to both shapes, then read the fill, outline and glow off it.

More info

What one number buys

Each pixel asks the distance to a circle and to a box, and reads three looks off that distance. coverage(d) fills the shape with a soft edge, so a curve shows no staircase. The absolute distance less a width is an outline, needing no second pass or algorithm. The distance itself indexes the palette, so the surrounding field glows outward. A rasterizer would need separate code for each, where these are three reads of one value.

The dimension proof

length(p) - r is a circle on a matrix and a sphere in a volume, from identical code. That is why the shapes are addressed in sub-pixel coordinates and z collapses on a 2D layer. Measured on an S3, the shapes are cheap and the palette lookup dominates.