メインコンテンツへスキップ

Lighting

This section provides guidance on setting up lights and shadows.

Lights and shadows can be added to the entity via the Studio interface or in code. Adding them in Studio is done via the (+) button on the Hierarchy or adding "New Component" via the Inspector for a selected entity. The Light and Shadow components feature various settings.

Light Component:

LightComponent

Shadow Component:

ShadowComponent

Lights

Add a light source

ecs.Light.set(world, eid, {type: 'directional'})

Setting custom light properties

ecs.Light.set(world, component.id, {
type: 'directional',
castShadow: true,
intensity: 0.5,
r: 255,
g: 0,
b: 0,
targetX: 10,
targetY: 10,
targetZ: 10,
shadowBias: 0,
})

Light properties

メモ
  • Keep the rotation of the entity that the light component is on to (0, 0, 0). The light will act unpredictably if it is not.
  • Shadow Camera can not be configured through the light configurator.
  • If an entity with a light is selected, a helper will appear to show the shadow camera of the light.
Property NameTypeDefaultRequiredDescription
typestringdirectionaltrueThe type of light: directional, point, ambient
castShadowbooleantruefalseEnables light to cast shadows
intensitynumber0.5falseThe light's intensity, or strength.
rnumber255falseThe red component of the light’s color.
gnumber255falseThe green component of the light’s color.
bnumber255falseThe blue component of the light’s color.
targetXnumber0falseThe x coordinate of the point the light is targeting.
targetYnumberfalseThe y coordinate of the point the light is targeting.
targetZnumber0falseThe z coordinate of the point the light is targeting.
shadowBiasnumber -0.005falseHow much to add or subtract from the normalized depth when deciding whether a surface is in shadow.
shadowNormalBiasnumber0falseDefines how much the position used to query the shadow map is offset along the object normal.
shadowRadiusnumber1false The radius of the shadow.
shadowAutoUpdatebooleantruefalseEnables automatic updates of the light's shadow. Default is true. If you do not require dynamic lighting / shadows, you may set this to false.
shadowBlurSamplesnumber8falseThe amount of samples to use when blurring a VSM shadow map.
shadowMapSizeheightnumber 1024 falseHeight of the shadow map. Higher values give better quality shadows at the cost of computation time. Values must be powers of 2
shadowMapSizeWidthnumber 1024falseWidth of the shadow map. Higher values give better quality shadows at the cost of computation time. Values must be powers of 2
shadowCameraNearnumber0.5falseCamera frustum near plane. The valid range is between 0 and the current value of the far plane.
shadowCameraFarnumber 200 false Camera frustum far plane. Must be greater than the current value of the near plane.
shadowCameraLeftnumber -50 false Camera frustum left plane.
shadowCameraRightnumber 50falseCamera frustum right plane.
shadowCameraTopnumber50falseCamera frustum top plane.
shadowCameraBottomnumber-50falseCamera frustum bottom plane.

Shadows

Cast and receive shadows

ecs.Shadow.set(world, eid, {castShadow: true, receiveShadow: true})

Shadow Properties

Property NameTypeDefaultRequiredDescription
castShadowbooleanfalse falseIndicates if an entity can cast shadows.
receiveShadowbooleanfalsefalseIndicates if an entity can receive shadows.