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:

Constructors

Link copied to clipboard
constructor(color: Color4, intensity: Float)
constructor(color: Color4, intensity: Float, castsShadowEnabled: Boolean)

Properties

Link copied to clipboard
var castsShadowEnabled: Boolean

Weather the light casts shadows.

Link copied to clipboard

The color of the light.

Link copied to clipboard
var intensity: Float

The intensity of the light in lux, defined as luminous flux per unit area. One lux equals one lumen per square metre.

Link copied to clipboard
var shadowDepthBias: Float

The shadow depth bias of the light.

Link copied to clipboard

The shadow culling mode of the light.

Link copied to clipboard

The shadow projection type of the light.

Functions

Link copied to clipboard
open override fun clone(): Component

Creates and returns a copy of this Component instance.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String