Create the global light system plugin
textureSize Vector2 optionalSize of the lightmap texture (defaults to following mainCanvasSize, which is css pixels, so the lightmap is not scaled by canvasPixelRatio; pass mainCanvasSize.scale(getCanvasPixelRatio()) for a full resolution lightmap)
ambientColor Color optionalColor applied to unlit areas of the scene (defaults to BLACK = pitch dark). Set a small RGB like rgb(0.1,0.1,0.15) for a faint "moonlight" baseline so unlit areas aren't fully black.
// simplest usage
new LightSystemPlugin();
Baseline color applied to unlit areas of the scene. Defaults to BLACK (pitch dark). Set to a small RGB for a faint ambient. The lightmap is cleared to this color each frame, then lights add on top, then the result multiplies the scene.
The background map, objects with castBackgroundShadow drawn black on
white, the shadow map's size and place, made by a directional light when something casts into it and kept while the light is, read only
Shader for compositing the lightmap over the main scene
Vertex array object for the composite shader
The scene's directional light, a sun, or undefined, read only
The directional light as built this frame, white where it reaches,
over the shadow map's area, read only
Pixels across the square textures a directional light is built in, covering the
shadow map's area; larger is sharper and slower; a power of two, as shadowMapSize, so their texels line up
True while emissive objects draw into the lightmap, read only, see EngineObject.emissive
When false, the render pass is skipped entirely
Shader for drawing per-Light falloff blobs into the lightmap
Vertex array object for the light shader
Where Canvas2D draws go during the shadow and emissive passes, a 1x1 canvas, so text in a render() is not drawn twice
Copies the shadow map around a light into its texture
Vertex array object for the copy shader
The shadow map, casters drawn black on white around the camera, read only
World position of the shadow map's bottom left corner, set each shadow pass
How many times the larger side of the view the shadow map covers, so casters just off screen still cast in; raise it when lights reach further than a view past the screen
Pixels across the square shadow map, made again when changed
World size the shadow map covers, set each shadow pass
True while the shadow pass runs, read only, so a render() can skip parts that should not cast
Stretch passes per shadow casting light, fewer is cheaper and shorter shadows
Cast shadows: every object draws black into a shadow map once a frame and each light's rays stop at them; off by default and free when off
How much light bleeds into a caster's near side, 0 for hard edged casters, 1 for most;
the bleed reaches further in under a bigger light, so a thin wall under a big one lets some through, lower it
for those
One stretch pass of a light's shadow texture
Vertex array object for the stretch shader
One of the two textures each light's shadow is built in
Pixels across each light's own shadow texture, made again when changed; larger is sharper,
and a gap between casters narrower than about 4*radius/shadowTextureSize world units closes
Size of the lightmap texture, follows mainCanvasSize (css pixels, so it is not scaled by canvasPixelRatio) unless a size was passed
True when no size was passed, so the lightmap follows mainCanvasSize
Bring the sizes of the textures it makes down to what the device can make: shadowMapSize, shadowTextureSize
and a textureSize given by hand; called before they are made, so a size too big falls back instead of failing
Draw a single Light's falloff blob into the currently bound lightmap.
Called by Light.renderLight() during the plugin's render pass.
light Light
Build a light's shadow texture from the shadow map: the map around the light, its casters stretched
away from the light a little further each pass with light bled into their near sides. Leaves the
result on texture unit 1 and the lightmap bound again. Called by drawLight.
light Light
In the shadow pass, let the draws that follow keep their color in the shadow map, so light passing
through them is tinted instead of blocked: a stained glass window, colored smoke. Any draw blocks light
by its alpha, so a fading sprite casts a fading shadow; this keeps the color as well. It covers what was drawn
under it in the map as any draw does, so glass drawn after a wall cuts a tinted window in the wall's shadow, and
a wall drawn after the glass covers it. Does nothing outside
the pass, so a render() can call it around those draws unconditionally; set it back to false after them.
transparent boolean optional, default true