Light
Descriptionβ
This component makes an entity emit light.
Propertiesβ
Property | Type | Default | Description |
---|---|---|---|
type (Required) | string | 'directional' | Supported types are: 'directional', 'point' and 'ambient' |
castShadow | boolean | true | If the light source should cast shadows. |
intensity | number | 0.5 | The emission strength. |
r | number (0-255) | 255 | The amount of red the light emits. |
g | number (0-255) | 255 | The amount of green the light emits. |
b | number (0-255) | 255 | The amount of blue the light emits. |
shadowBias | number | -0.005 | How much to add or subtract from the normalized depth when deciding whether a surface is in shadow. |
shadowNormalBias | number | 0 | How much the position used to query the shadow map is offset along the object normal. |
shadowRadius | number | 1 | The radius of the shadow |
shadowAutoUpdate | boolean | true | Should the shadow be automatically calculated and updated |
shadowBlurSamples | number | 8 | The amount of samples to use when calculating the Virtual Shadow Map. |
shadowMapSizeHeight | number | 1024 | The height of the Shadow Map. (Values must be powers of 2) |
shadowMapSizeWidth | number | 1024 | The width of the Shadow Map. (Values must be powers of 2) |
shadowCameraNear | number | 0.5 | Camera frustum near-pane for calculating shadows |
shadowCameraFar | number | 200 | Camera frustum far-pane for calculating shadows |
shadowCameraLeft | number | -50 | Camera frustum left-pane for calculating shadows |
shadowCameraRight | number | 50 | Camera frustum right-pane for calculating shadows |
shadowCameraBottom | number | -50 | Camera frustum bottom-pane for calculating shadows |
shadowCameraTop | number | 50 | Camera frustum top-pane for calculating shadows |
targetX | number | 0 | The target X coordinate of the light (Directional only) |
targetY | number | 0 | The target Y coordinate of the light (Directional only) |
targetZ | number | 0 | The 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)