LittleJS 1.28.0

LightSystem

Light

A Light is an EngineObject that contributes a soft additive blob of color to the LightSystem plugin's lightmap.

  • castShadow on a Light means its rays stop at casters when lightSystem.shadows is on, three.js's meaning for a light; a Light's own render() draws nothing so the object meaning never applies to it
  • A light inside a caster is blocked entirely, so the object that holds it, its lamp, a torch, the player carrying it, needs a shadowCore that reaches past it, castShadow = false, or a renderShadow that leaves the light's spot out
  • A coneAngle makes it a cone along its up, turned by its angle, and a gel is a picture it shines through; both are applied over the round light with its shadows, so they cost next to nothing

Extends EngineObject

Constructor

new Light(pos, radius, color, fadeRange)lightSystem.js:1090

Create a light object and add it to the engine object list

pos Vector2

World space position

radius number

Total extent of the light in world units

color Color optional

Color of the light; alpha modulates intensity

fadeRange number optional

Width of the soft edge in world units (defaults to radius)

new Light(vec2(5, 5), 4, rgb(1, 0.5, 0));        // orange light, full soft blob
new Light(vec2(0, 0), 8, rgb(1, 1, 1), 2);       // white core with 2-unit soft halo
const flashlight = new Light(vec2(), 10);        // a flashlight looking right, its beam 60 degrees across
flashlight.coneAngle = PI/6;
flashlight.angle = PI/2;

Members

Methods

Inherited from EngineObject

Members

coneAngle : numberlightSystem.js:1124

Makes it a cone, like a flashlight or headlight: the angle in radians from its up out to the edge of the cone, so the beam is twice this across; it looks along getUp(), turned by its angle and by what it is attached to; 0 for a light that shines every way

coneSoftness : numberlightSystem.js:1127

How much of the cone is its fading edge: 0 a hard edge, .2 by default, the outer fifth, 1 fading all the way from the middle of the beam

fadeRange : numberlightSystem.js:1108

Width of the soft edge in world units

A gel, a picture the light shines through, called a cookie in some engines: stretched across the light's square, twice its radius, its top the way the light looks, turned with it, and multiplied into its color, so one light can be a car's headlights and tail lights; a TileInfo's own tile, or a whole TextureInfo; shadows still fall through it

glow : numberlightSystem.js:1115

Size across of a soft hazy glow drawn over the light, like a lamp at night, 0 for none; it is added over the lit scene, in front of everything there

glowFalloff : numberlightSystem.js:1118

How fast the glow fades from its middle: 1 by default, .5 a wide haze, 2 a tight bright core

glowTileInfo : TileInfo|undefinedlightSystem.js:1120
radius : numberlightSystem.js:1106

Total extent of the light in world units

shadowCore : numberlightSystem.js:1112

Radius around the light where casters are left out of its shadow, so the lamp or torch that holds it, or the player carrying it, does not block it; it has to reach past that object's corners, about half its diagonal and a little more, or dark rays run out from them

Methods

Lights are invisible in the main render pass — they only contribute to the lightmap via renderLight().

Draw this light's glow, soft and round, its glow size across and in its color, added over the lit scene; called by LightSystemPlugin after the lightmap is applied

renderLight()lightSystem.js:1143

Draw this light's falloff blob into the lightmap. Called by LightSystemPlugin during its render pass. No-op when the plugin or WebGL is unavailable.