Most browser survivor-like games either draw flat 2D sprites on Canvas 2D or pull in a heavy 3D engine just to render glowing circles in space. When we built STAR AGAINST THE DARK — a free space survivor roguelite in the browser where you play as a newborn star and your orbiting worlds are your weapons — we wanted deep-space lighting, procedural spinning planets, gravitational lensing, and hundreds of enemies at 60 FPS with zero engine framework overhead.
This post walks through two halves of how the game actually works under the hood: the custom linear-HDR WebGL2 renderer we wrote in TypeScript, and the lagged orbital physics and alignment-beam math that make orbiting planets feel like active weapons instead of passive rings.
Watch the 16:9 gameplay trailer: STAR AGAINST THE DARK Official Trailer on YouTube
Why orbiting worlds need lagged physics to feel like weapons
In a classic survivor-like, rotating shields or orbitals spin at a fixed radius around the player. You walk near enemies and wait for the ring to clip them. That works for a secondary passive, but when orbiting planets are your primary weapon, a rigid ring feels sluggish.
In STAR AGAINST THE DARK, every world orbits a lagged center (cx, cy) that chases the star with exponential inertia rather than snapping to (player.x, player.y):
const k = 1 - Math.exp(-dt / Math.max(0.02, b.def.lag));
b.cx += (p.x - b.cx) * k;
b.cy += (p.y - b.cy) * k;
We clamp that lag distance to 190 world units so planets never get left behind off-screen. Every tick, the body computes its actual world velocity from its previous position and scales contact damage through a speed-based "whip" multiplier (clamped between 0.5× and 3.5× relative to a reference orbital speed).
That single change turns movement into melee combat:
- Sharp turns and reversals snap the lagged center across the star, whipping outer worlds through a crowd at high velocity for up to
3.5×damage and stronger knockback. - Surge (Space or right mouse button) dashes the star through enemies unharmed, dragging every orbit behind it and slinging planets forward on exit.
- Swept segment collision (
segDist2from the body's previous position(px, py)to its new position(x, y)) ensures a fast-whipped world never tunnels through small swarm enemies between frames. - Keplerian eccentricity (
ecc > 0) speeds up elliptical worlds at periapsis and slows them at apoapsis, giving each of the 13 worlds a distinct rhythm before you even reach its level-6 ascension.
Measuring alignments on a circle without wrap-around bugs
The game's signature payoff is lining worlds up through the star:
- Two worlds on the same line through the star fire a Conjunction arc.
- Three or more worlds on one line trigger an Alignment (syzygy) beam that anchors to the star, burns in both directions for roughly
0.62seconds, ticks damage every0.15seconds, and erases hostile enemy shots along the whole beam.
Because alignment is an undirected line through the star (a planet at 1° and a planet at 181° are collinear), naive angle averaging breaks at the 0° / 180° boundary. We reduce every planet's bearing from the star modulo π, then compute the mean direction on the doubled-angle circle:
sx += Math.cos(2 * phi[j]);
sy += Math.sin(2 * phi[j]);
// ...
return modPi(Math.atan2(sy, sx) * 0.5);
Because alignment is measured from the star's live position while the orbits lag behind, moving and surging deliberately pulls worlds into temporary collinear bands. A player running Sirius (the Binary Star, which starts with three worlds, zero star weapons, 40% wider alignment tolerance, and +30% alignment damage) plays almost entirely around baiting swarms into the beam lane and erasing bullet walls on cue.
A zero-framework linear-HDR WebGL2 pipeline
Space bullet-heaven games live or die on visual readability: you need glowing lasers, pulsing stars, and dense enemy waves without turning the screen into muddy white noise. We skipped third-party renderers and built a focused WebGL2 pipeline in src/render/gl/ with seven shader stages:
- Quarter-resolution nebula pass: Domain-warped 3D fractional Brownian motion (
fbm) generates drifting gas filaments and a dusty galactic band at1/4resolution, stored square-root encoded so gradients stay smooth in compact targets. - Background pass: Combines space colour, the upsampled nebula, rare procedural spiral and elliptical distant galaxies, and 4 parallax star layers (
STAR_PARALLAX = [0.04, 0.08, 0.15, 0.26]) wrapped cleanly on the CPU so floating-point coordinates never lose precision in long endless runs. - Additive trail ribbons: Orbiting worlds and projectiles feed a pooled
TrailStorerendered as soft-shouldered additive strips in linear light. - Instanced SDF + procedural body batch: All gameplay shapes, glyphs, enemies, bullets, stars, and planets append 16 floats per instance into a single growable
Float32Array(capped at262,144instances, zero per-draw CPU allocations, frustum-culled on the CPU before writing). Two instanced programs handle the entire scene: a signed-distance shape shader (SHAPES_FS) and a procedural celestial body shader (BODIES_FS). - Procedural planets on a quad: Rather than shipping dozens of planet textures,
BODIES_FSprojects each planet quad onto a rotating 3D sphere and evaluates band-limited gradient noise with analytic derivatives (fbmd) across 12 planet families (rock,ember,ice,gas,lava,garden,crystal,metal,storm,desert,moon,void), lit dynamically by the direction and distance to the player's star. - Mip-chain bloom with partial Karis averaging: When the GPU supports floating-point render targets (
RGBA16F), the scene renders in linear HDR. The first 13-tap bloom downsample applies a soft-knee threshold and a partial Karis average across five sub-groups—taming single-pixel shimmer on tiny stars and sparks without flattening real highlights—followed by additive3×3tent upsampling. On GPUs without float render targets, the renderer drops cleanly toSRGB8_ALPHA8with tuned thresholds so the game never renders black. - Single composite pass: Applies up to
4gravitational lenses (softened Einstein-radius deflection around black-hole effects), up to8dispersive shockwaves, radial chromatic aberration, bloom, exposure, flash, a hybrid filmic tonemapper (mix(maxChannelCurve, perChannelCurve, 0.55)so neon colours stay vivid while ultra-bright cores roll to white), vignette, sRGB encoding, asampler3Dcolour lookup table, and triangular dithering to eliminate banding in dark space.
How the content scales across five epochs
A 20-to-30-minute run crosses five distinct epochs — First Light, The Gathering, The Long Night, The Devouring, and Heat Death — each shifting the nebula palette, dimming the background starfield as the Dark closes in, raising the spawn budget, and ending in a multi-phase boss (Maw, Arachne, Twins, Ouroboros, and Entropy).
Around that core loop sit:
- 13 worlds with level-6 ascensions, 8 star weapons, 25 passives, and 29 relics
- 6 playable stars (
Sol,Vega,Proxima,Sirius,Vela, andErebus) and 7 stellar evolutions - 22 enemy kinds, elites, 61 achievements, Entropy tiers 0–10, a seeded daily run, an endless mode, and permanent stardust upgrades in the Observatory
- Full keyboard, mouse, gamepad, and touch input, with English and Simplified Chinese in-game interfaces
Try it in your browser
If you want to see how lagged orbital physics, syzygy beams, and a custom HDR WebGL2 renderer feel in a real run, play STAR AGAINST THE DARK right in your browser. It is free, no pay to win, no sign-up, and plays in the browser with nothing to install.
A note on how it was made: the game was built with heavy AI assistance (including Claude Code), directed, tuned, and verified by our team at Ant Games, and this article was also drafted with AI assistance.