BGE/Lighting
Alias: BGE.Lighting
Static Methods
prepareLights(
lights: Array.<BGE.Light>,
): Array.<BGE.Lighting.PreparedLight>
The enabled lights in lights, prepared for shading.
Parameters
lights(Array.<BGE.Light>)
Returns
Array.<BGE.Lighting.PreparedLight>
getLightingSignature(lights: Array.<BGE.Light>): Array.<object>
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
lights(Array.<BGE.Light>)
Returns
Array.<object>— empty when no light is enabled
isSameLightingSignature(
a: Array.<object>,
b: Array.<object>,
): boolean
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>
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
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
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 spacenormal(BGE.Math.Vector) — unit normal of the visible sidewrap(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
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>
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>
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 planenormal(BGE.Math.Vector) — unit normal of the visible side
Returns
Array.<BGE.Lighting.PlaneLightPool>
lightPoolFalloff(fraction: float, heightRatio: float): float
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 edgeheightRatio(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
rgba lit by lightAmount (from computeLightAmount()), with no channel darker than floor - see Drawable.ambientBrightness.
Parameters
rgba(integer) — packed RGBA colorlightAmount(BGE.Math.Vector) — red/green/blue light, each 0-1floor(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
rgba as seen on a surface lit by lights.
Parameters
rgba(integer) — packed RGBA colorlights(Array.<BGE.Lighting.PreparedLight>)point(BGE.Math.Vector) — a point on the surface, in world spacenormal(BGE.Math.Vector) — unit normal of the visible sidefloor(float) — the least light any channel gets, 0-1wrap(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
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 brightnessg(float)b(float)toLight(BGE.Math.Vector) — directional only: unit vector from a surface toward the lightposition(BGE.Math.Vector) — point onlyrange(float)
LightSnapshot
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 lightr(float) — strength per channel at the point, after a point light's falloffg(float)b(float)
PlaneLightPool
Extends: roAssociativeArray
The patch of a plane one point light reaches - see getPlaneLightPools().
Properties
center(BGE.Math.Vector) — the light's foot on the planeradius(float) — world-space radius where the light runs outheightRatio(float) — the light's height above the plane as a fraction of its range, 0-1 - sets ther(float) — light per channel at the pool's centreg(float)b(float)