Skip to content

RaymarchEffect

Source: RaymarchEffect.h

RaymarchEffect

class RaymarchEffect
src/light/effects/RaymarchEffect.h:29

Inherits: EffectBase

Effect: a raymarched 3D scene of melting spheres, lit by a normal derived from the field.

RaymarchEffect card RaymarchEffect controls

The effect is deliberately thin, and that is its point. The tracing, the primitives, the normal, the camera and the lighting all live in raymarch.h. What remains here is a scene() of two spheres and a floor, and a choice of colors. Writing a different 3D effect means writing a different scene(), which is the whole API.

Prior art: Inigo Quilez's distance-function and raymarching articles.

Public Attributes

uint8_t bpm = 10 : How fast the scene animates.

uint8_t steps = 40 : How far each ray may search, which is the quality and cost knob.

uint8_t blend = 80 : How much the two spheres melt into each other.

uint8_t cameraY = 128 : The camera's height above the floor.

bool showFloor = true : Draw the floor plane under the spheres.

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 animation, the ray budget, the melt and the camera.

virtual inline void tick() override : Place the spheres and the camera, then march one ray per pixel into the scene.

More info

Cost is per pixel, not per chip

Measured on a desktop at 128x128 and on an S3 at 4096 lights, it holds hundreds of frames a second. steps caps how far each ray may search, so halving it roughly halves the cost.