PURPOSE
Additive WebGL glow primitives for the new lighting system. Provides a two-quad pattern per glow call (outer color-tinted soft glow plus inner white-hot core) using the pre-baked glow atlas region — a smooth white radial gradient that handles per-pixel falloff. Callers tint the gradient via RGBA multiplication. A separate single-quad aura variant and a Canvas 2D fallback are also exported.
OWNS
addGlow(batch, glowRegion, x, y, radius, r, g, b, alpha)— pushes two quads (outer color glow at full radius with alpha × 0.5, inner white-hot core at 70 percent radius with alpha × 0.9).addAura(batch, glowRegion, x, y, radius, r, g, b, alpha)— single soft color quad with no white-hot core, intended for ship and boss “I am here” auras where the inner core would render as a sharp disc.addCanvasGlow(ctx, wx, wy, worldRadius, r, g, b, alpha)— Canvas 2D additive aura that converts world coordinates to screen space viaCamera.toSx/Camera.toSyand scales radius bycamera.zoombefore delegating toglow-stamp.drawGlow.
READS FROM
./sprite-batch— type-only imports ofSpriteBatchandAtlasRegion../camera—Camera.toSxandCamera.toSyfor world-to-screen conversion in the Canvas variant.../core— singletoncameraforcamera.zoom../glow-stamp—drawGlow(aliased as_drawGlow) used byaddCanvasGlow.
PUSHES TO
- The caller-supplied
SpriteBatchviabatch.add(...)calls. Each WebGL glow call adds two quads (addGlow) or one quad (addAura); position, size, rotation (always 0), atlas region, and tint are encoded as instance data. - The caller-supplied
CanvasRenderingContext2Dindirectly viadrawGlowfromglow-stamp.
DOES NOT
- Does not own or manage a sprite batch — the caller passes one in and is responsible for flushing it in
'additive'blend mode. - Does not mix normal-blend and additive-blend quads in the same flush; the bridge maintains a dedicated
_sbGlowsbatch that flushes after the main alpha batch. - Does not handle sprite batch overflow — drops silently to match
SpriteBatch.addbehavior (limit is 2048 quads per draw call, equating to 1024addGlowcalls per flush). - Does not call
ctx.save/ctx.restoreor setglobalCompositeOperationinaddCanvasGlow— the caller must set'lighter'blending and manage state. - Skips work when
radius <= 0oralpha <= 0(early return).
Signals
- Radius and alpha guards: both functions early-return on non-positive radius or alpha, so degenerate calls cost nothing.
- Two-quad layering in
addGlow: outer diameter isradius * 2, inner core diameter isradius * 0.7; outer alpha isalpha * 0.5, inner alpha isalpha * 0.9and is always tinted pure white (1, 1, 1). - Color convention: WebGL paths (
addGlow,addAura) expect tint components in 0–1 range; the Canvas 2D path (addCanvasGlow) expects 0–255 (passed straight through todrawGlow). addCanvasGlowv5.60.4 correction: the context at boss/ship aura draw sites is in screen space (verified againstrenderBossandrenderBossRoomWalls, both of which useCamera.toS), so world coordinates must be converted; v5.60.3 incorrectly assumed world-space ctx.- Auras (
addAura,addCanvasGlow) are intentionally single-quad — the white-hot core looked like a sharp pixellated disc at small radii because the gradient had no room to feather; auras should be given generous radius (for example ship visual size times two).
Entry points
addGlowis invoked by the sprite-batch / WebGL glow pipeline for projectiles, hit flashes, and other additive point lights routed through the_sbGlowsbatch.addAurais invoked for steady “I am here” auras on ships and bosses where the inner core would degrade visually.addCanvasGlowis invoked at the Canvas 2D fallback aura draw sites (renderBoss,renderBossRoomWalls) where the surrounding ctx is already in screen space.
Pattern notes
- Pre-baked gradient + multiplicative tinting: pushing the falloff math into the atlas region (a smooth white radial gradient) lets every glow color reuse the same texture sample, so per-call cost is just two instance writes for
addGlowor one foraddAura. - Caller-owned batching: the module is stateless — all batching, blend-mode selection, and flushing is the bridge’s responsibility, which keeps glow rendering composable with the rest of the sprite pipeline.
- Dual-pipeline parity: the WebGL (
addGlow/addAura) and Canvas 2D (addCanvasGlow) entry points share the same conceptual model (additive tinted radial gradient at a world position with a world radius), but differ in color range convention and in who handles the world-to-screen transform. - Silent overflow matches the broader sprite-batch contract — render systems degrade gracefully rather than throwing under load.