LightSystem

LittleJS Light System Plugin

  • Adds 2D dynamic lighting to the scene
  • Lights are first-class EngineObjects (the Light class)
  • Each Light draws a soft falloff blob of its color into a shared lightmap
  • Lights accumulate ADDITIVELY in the lightmap (red + blue = magenta)
  • The lightmap is then MULTIPLIED with the scene during composite, so unlit areas go to the ambient color and lit areas show the scene tinted by the accumulated light color
  • Draw the world at full brightness — the lightmap does the darkening
  • The pass runs after gameRenderPost, so a HUD drawn there with WebGL is darkened too; draw the HUD with useWebGL=false (the main canvas) or from a plugin created after this one
  • Any EngineObject may override renderLight() to additively contribute to the lightmap (e.g. lava that lights the floor around it, weapon flashes, glowing crystals)
  • Set obj.emissive to 1 to show an object at full brightness in its own colors, lit or not, or between 0 and 1 for partly: it draws its shape into the lightmap through renderEmissive(), which calls render() by default; exact for solid pixels, a partly transparent one is self lit by its alpha too, so it shows darker
  • Set lightSystem.shadows for objects to block light: each frame every object draws black into a shadow map through renderShadow(), which calls render() by default; obj.castShadow = false keeps it out (a floor TileLayer, a background), a draw's alpha sets how much light it blocks, and setShadowTransparent lets its color tint the light
  • Must be constructed BEFORE PostProcessPlugin so post-process sees lit pixels

Classes

Light
LightSystemPlugin

Members

(static) lightSystem :LightSystemPlugin

Global Light System plugin object

Type:
  • LightSystemPlugin