DirectionalLightComponent
A Component that emits directional light along an entity's local forward (-Z) axis.
This component creates light that behaves like a distant light source, where all light rays are parallel and the intensity does not diminish with distance, such as the sunlight.
Key Properties:
Direction: Inherited from the entity's transform (uses -Z axis by convention).
Uniform illumination: Affects all objects in the scene equally.
Color & Intensity: Fully customizable light appearance with color and intensity.
Shadow Casting: Configurable through castsShadowEnabled and related shadow properties.
To receive lighting effects, the Entity must use a Material that supports lighting. For example, PhysicallyBasedMaterial respond to lighting, while UnlitMaterial does not.
Code sample:
val sunEntity = Entity().apply {
components.set(DirectionalLightComponent(
color = Color4(1f, 0.95f, 0.9f, 1f),
intensity = 2000f, // Measured in lux
castsShadowEnabled = true
))
components[DirectionalLightComponent::class.java]!!.apply {
shadowDepthBias = 0.01f
shadowFaceCullingMode = ShadowFaceCullingMode.BACK
shadowProjectionType = ShadowProjectionType.Auto()
}
}Related components:
PointLightComponent - For bulb-like omnidirectional lighting.
SpotLightComponent - For directional cone lighting.