Passer au contenu principal

Light

Description​

This component makes an entity emit light.

Properties​

PropertyTypeDefaultDescription
type (Required)string'directional'Supported types are: 'directional', 'point' and 'ambient'
castShadowbooleantrueIf the light source should cast shadows.
intensitynumber0.5The emission strength.
rnumber (0-255)255The amount of red the light emits.
gnumber (0-255)255The amount of green the light emits.
bnumber (0-255)255The amount of blue the light emits.
shadowBiasnumber-0.005How much to add or subtract from the normalized depth when deciding whether a surface is in shadow.
shadowNormalBiasnumber0How much the position used to query the shadow map is offset along the object normal.
shadowRadiusnumber1The radius of the shadow
shadowAutoUpdatebooleantrueShould the shadow be automatically calculated and updated
shadowBlurSamplesnumber8The amount of samples to use when calculating the Virtual Shadow Map.
shadowMapSizeHeightnumber1024The height of the Shadow Map. (Values must be powers of 2)
shadowMapSizeWidthnumber1024The width of the Shadow Map. (Values must be powers of 2)
shadowCameraNearnumber0.5Camera frustum near-pane for calculating shadows
shadowCameraFarnumber200Camera frustum far-pane for calculating shadows
shadowCameraLeftnumber-50Camera frustum left-pane for calculating shadows
shadowCameraRightnumber50Camera frustum right-pane for calculating shadows
shadowCameraBottomnumber-50Camera frustum bottom-pane for calculating shadows
shadowCameraTopnumber50Camera frustum top-pane for calculating shadows
targetXnumber0The target X coordinate of the light (Directional only)
targetYnumber0The target Y coordinate of the light (Directional only)
targetZnumber0The target Z coordinate of the light (Directional only)

Functions​

Get​

Returns a read-only reference.

Example

ecs.Light.get(world, component.eid)

Set​

Ensures the component exists on the entity, then assigns the (optional) data to the component.

Example

ecs.Light.set(world, component.eid, {
type: 'directional',
castShadow: true,
intensity: 0.5,
r: 255,
g: 255,
b: 255,
shadowBias: -0.005,
shadowNormalBias: 0,
shadowRadius: 1,
shadowAutoUpdate: true,
shadowBlurSamples: 8,
shadowMapSizeHeight: 1024,
shadowMapSizeWidth: 1024,
shadowCameraNear: 0.5,
shadowCameraFar: 200,
shadowCameraLeft: -50,
shadowCameraRight: 50,
shadowCameraBottom: -50,
shadowCameraTop: 50,
targetX: 0,
targetY: 0,
targetZ: 0
})

Mutate​

Perform an update to the component within a callback function. Return true to indicate no changes made.

Example

ecs.Light.mutate(world, component.eid, (cursor) => {
cursor.intensity = 1.0;
cursor.castShadow = false;
return false;
})

Remove​

Removes the component from the entity.

Example

ecs.Light.remove(world, component.eid)

Has​

Returns true if the component is present on the entity.

Example

ecs.Light.has(world, component.eid)

Reset​

Adds, or resets the component to its default state.

Example

ecs.Light.reset(world, component.eid)

Advanced Functions​

Cursor​

Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.

Example
ecs.Light.cursor(world, component.eid)

Acquire​

Same behavior as cursor, but commit must be called after the cursor is done being used.

Example
ecs.Light.acquire(world, component.eid)

Commit​

Called after acquire. An optional third argument determines whether the cursor was mutated or not.

Example
ecs.Light.commit(world, component.eid)
ecs.Light.commit(world, component.eid, false)

Dirty​

Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.

Example
ecs.Light.dirty(world, component.eid)