BGE/Lighting

Alias: BGE.Lighting


Static Methods

prepareLights( lights: Array.<BGE.Light>, ): Array.<BGE.Lighting.PreparedLight>

static

The enabled lights in lights, prepared for shading.

Parameters

Returns

  • Array.<BGE.Lighting.PreparedLight>

getLightingSignature(lights: Array.<BGE.Light>): Array.<object>

static

Every value about lights that affects shading, in order - compare two with isSameLightingSignature() to tell when cached drawings need relighting. Kept as raw values, not a string, so no change is lost to float formatting.

Parameters

Returns

  • Array.<object> — empty when no light is enabled

isSameLightingSignature( a: Array.<object>, b: Array.<object>, ): boolean

static

Whether two getLightingSignature() results are identical.

Parameters

  • a (Array.<object>)
  • b (Array.<object>)

Returns

  • boolean

snapshotLightsAt( lights: Array.<BGE.Lighting.PreparedLight>, point: BGE.Math.Vector, ): Array.<BGE.Lighting.LightSnapshot>

static

How each light reaches point, whichever way a surface there faces - what a cached drawing of an object at point was lit by. Compare two with lightSnapshotsFit().

Parameters

  • lights (Array.<BGE.Lighting.PreparedLight>)
  • point (BGE.Math.Vector)

Returns

  • Array.<BGE.Lighting.LightSnapshot>

lightSnapshotsFit( before: Array.<BGE.Lighting.LightSnapshot>, after: Array.<BGE.Lighting.LightSnapshot>, maxAngleDegrees: float, maxChange: float, ): boolean

static

Whether lighting has changed so little between two snapshots of the same point that a drawing lit by before still passes for one lit by after: the same lights, none turned more than maxAngleDegrees, and no channel stronger or weaker by more than maxChange.

Parameters

  • before (Array.<BGE.Lighting.LightSnapshot>)
  • after (Array.<BGE.Lighting.LightSnapshot>)
  • maxAngleDegrees (float)
  • maxChange (float) — 0-1, a fraction of full brightness

Returns

  • boolean

computeLightAmount( lights: Array.<BGE.Lighting.PreparedLight>, point: BGE.Math.Vector, normal: BGE.Math.Vector, wrap?: float, ): BGE.Math.Vector

static

How much light reaches a surface, per channel: a diffuse (Lambert) sum over every light, capped at 1. normal must be the unit normal of the side being seen.

Parameters

  • lights (Array.<BGE.Lighting.PreparedLight>)
  • point (BGE.Math.Vector) — a point on the surface, in world space
  • normal (BGE.Math.Vector) — unit normal of the visible side
  • wrap (float, optional, default: "0.0") — 0-1, how far light wraps round past the lit side - see Drawable.lightWrap

Returns

  • BGE.Math.Vector — x/y/z = red/green/blue light, each 0-1

isPoolLight(light: BGE.Lighting.PreparedLight): boolean

static

Whether a light is drawn as a pool on a plane rather than in its uniform tint: a point light with a range. One with no range reaches the whole plane.

Parameters

  • light (BGE.Lighting.PreparedLight)

Returns

  • boolean

withoutPoolLights( lights: Array.<BGE.Lighting.PreparedLight>, ): Array.<BGE.Lighting.PreparedLight>

static

lights without the ones isPoolLight() picks out.

Parameters

  • lights (Array.<BGE.Lighting.PreparedLight>)

Returns

  • Array.<BGE.Lighting.PreparedLight>

getPlaneLightPools( lights: Array.<BGE.Lighting.PreparedLight>, planePoint: BGE.Math.Vector, normal: BGE.Math.Vector, ): Array.<BGE.Lighting.PlaneLightPool>

static

The pool of light each ranged point light casts on a plane, seen from the side normal points to. Lights behind that side, or too high to reach it, cast none.

Parameters

  • lights (Array.<BGE.Lighting.PreparedLight>)
  • planePoint (BGE.Math.Vector) — any point on the plane
  • normal (BGE.Math.Vector) — unit normal of the visible side

Returns

  • Array.<BGE.Lighting.PlaneLightPool>

lightPoolFalloff(fraction: float, heightRatio: float): float

static

A pool's brightness fraction of the way out from its centre to its edge, relative to the centre - computeLightAmount()'s point light falloff on a plane.

Parameters

  • fraction (float) — 0 at the centre, 1 at the edge
  • heightRatio (float) — the light's height over its range, as in PlaneLightPool

Returns

  • float — 1 at the centre, 0 at the edge

applyLightAmount( rgba: integer, lightAmount: BGE.Math.Vector, floor: float, ): integer

static

rgba lit by lightAmount (from computeLightAmount()), with no channel darker than floor - see Drawable.ambientBrightness.

Parameters

  • rgba (integer) — packed RGBA color
  • lightAmount (BGE.Math.Vector) — red/green/blue light, each 0-1
  • floor (float) — the least light any channel gets, 0-1

Returns

  • integer — packed RGBA color, alpha unchanged

shadeColor( rgba: integer, lights: Array.<BGE.Lighting.PreparedLight>, point: BGE.Math.Vector, normal: BGE.Math.Vector, floor: float, wrap?: float, ): integer

static

rgba as seen on a surface lit by lights.

Parameters

  • rgba (integer) — packed RGBA color
  • lights (Array.<BGE.Lighting.PreparedLight>)
  • point (BGE.Math.Vector) — a point on the surface, in world space
  • normal (BGE.Math.Vector) — unit normal of the visible side
  • floor (float) — the least light any channel gets, 0-1
  • wrap (float, optional, default: "0.0") — 0-1, how far light wraps round past the lit side - see Drawable.lightWrap

Returns

  • integer — packed RGBA color

Other

PreparedLight

static

Extends: roAssociativeArray

A light reduced to what shading needs, built once per lighting change so shading a surface doesn't re-normalize or unpack anything.

Properties

  • type (BGE.LightType)
  • r (float) — color * intensity, per channel, as fractions of full brightness
  • g (float)
  • b (float)
  • toLight (BGE.Math.Vector) — directional only: unit vector from a surface toward the light
  • position (BGE.Math.Vector) — point only
  • range (float)

LightSnapshot

static

Extends: roAssociativeArray

One light as it reaches a point - see snapshotLightsAt().

Properties

  • type (BGE.LightType)
  • toLight (BGE.Math.Vector) — unit vector toward the light; invalid for an ambient light
  • r (float) — strength per channel at the point, after a point light's falloff
  • g (float)
  • b (float)

PlaneLightPool

static

Extends: roAssociativeArray

The patch of a plane one point light reaches - see getPlaneLightPools().

Properties

  • center (BGE.Math.Vector) — the light's foot on the plane
  • radius (float) — world-space radius where the light runs out
  • heightRatio (float) — the light's height above the plane as a fraction of its range, 0-1 - sets the
  • r (float) — light per channel at the pool's centre
  • g (float)
  • b (float)