SpotLightComponent
A Component that emits conical light along the entity's forward (-Z) axis.
This component creates a directional light source with controllable spread (like a flashlight or stage spotlight), supporting advanced features including light color and intensity, shadow casting and clipping plane configuration.
Key properties:
Direction: Inherited from entity's transform (uses -Z axis).
Color & Intensity: Fully customizable light appearance with color and intensity.
Angular Falloff: Controlled via innerAngle (full intensity) and outerAngle (falloff edge).
Distance Attenuation: Light intensity diminishes over attenuationRadius.
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.
Angular behavior:
Light is at full intensity within innerAngle cone.
Smoothly falls to zero between innerAngle and outerAngle.
No light emitted beyond outerAngle.
Code sample:
val spotlightEntity = Entity().apply{
components.set(SpotLightComponent(
color = Color4(1f, 0.95f, 0.9f, 1f),
intensity = 10000f, // Measured in lumens
attenuationRadius = 10f, // Measured in meters
innerAngle = 15f, // Measured in degrees
outerAngle = 30f, // Measured in degrees
castsShadowEnabled = true,
))
components[SpotLightComponent::class.java]!!.apply {
shadowFaceCullingMode = ShadowFaceCullingMode.BACK
shadowClippingPlaneType = ShadowClippingPlaneType.Auto
}
}Performance Notes:
Shadow casting impacts rendering performance.
Wider angles (outerAngle) increase shaded area complexity.
Multiple active spotlights require careful optimization.
Related components:
PointLightComponent - For bulb-like omnidirectional lighting.
DirectionalLightComponent - For sunlight-style parallel lighting.
Properties
The radius of the light's attenuation.
Weather the light casts shadows.
The inner cone angle of the spotlight, measured in degrees.
The outer angle of the spotlight, measured in degrees.
The shadow clipping plane type of the light.
The culling behavior for shadow rendering.