Skip to content

StarFieldEffect

Source: StarFieldEffect.h

Star

struct Star
src/light/effects/StarFieldEffect.h:145

One star: a position in space and its own palette index.

Public Attributes

float x

float y

float z

uint8_t colorIndex

StarFieldEffect

class StarFieldEffect
src/light/effects/StarFieldEffect.h:32

Inherits: EffectBase

Star-field effect: drifting points like flying through stars.

StarFieldEffect card StarFieldEffect controls Author: @Brandon502 (MoonLight), inspired by Daniel Shiffman / Coding Train, https://www.youtube.com/watch?v=17WoOqgXsRM , https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Nodes/Effects/E_MoonLight.h

Each star is a 3D point drifting toward the viewer, re-projected onto the panel every advance. So a near star splays outward and flies off the edge while a distant one sits near the center. That is the classic warp look, and a star passing the camera respawns at the far plane.

Prior art: MoonLight's StarField, whose model and respawn rule this reproduces.

Public Attributes

uint8_t speed = 20 : How fast the field advances, where 0 pauses it.

uint8_t numStars = 16 : How many stars are active.

uint8_t blur = 128 : The fade rate, where a stronger fade leaves shorter streaks.

bool usePalette = false : Color the stars from the palette rather than in grayscale.

Public Methods

virtual inline const char * tags() const override : Catalog tags: MoonLight origin.

virtual inline Dim dimensions() const override : Writes the z=0 slice.

virtual inline void defineControls() override : Publish the flight speed, the population, the streaks and the coloring.

virtual inline void prepare() override : Size the star table to the control's maximum, re-seeding only when the grid changes.

virtual inline void tick() override : Fade the streaks, then advance and re-project every star when a step is due.

More info

Depth drives brightness, and the fade draws the streak

A nearer star is brighter, and with usePalette its depth picks the hue too. blur fades the previous frame rather than clearing it, so each star leaves a motion streak. speed throttles how often the field advances, and 0 pauses it.

The port is exact on purpose

The per-star perspective divide keeps floats, running once a star rather than once a pixel. The center offset and the projection scale are integer halves, so an odd-width panel matches. A ported effect that looks different is a regression, so fidelity wins over tidiness here.