SpotLight
A spotlight combines directional and point light behavior: intensity diminishes with distance (via attenuation) and with the angle from the central axis of the cone. This is commonly used to simulate focused light sources such as flashlights or stage spotlights.
When the target parameter is set to nullptr, the light will point toward the world origin.
auto spot = vglx::SpotLight::Create({
.color = 0xFFFFFF,
.intensity = 1.0f,
.angle = vglx::math::DegToRad(10.0f),
.penumbra = 0.3f,
.target = nullptr,
.attenuation = {
.base = 1.0f,
.linear = 0.0f,
.quadratic = 0.0f
}
});INFO
Derives from Light and inherits all public properties and methods.
Construction
Constructors
SpotLight()
Constructs a spotlight.
SpotLight::SpotLight(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the light. |
Factories preferred
SpotLight::Create() auto
Creates a shared instance of SpotLight.
static auto SpotLight::Create(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the light. |
Types
SpotLight::Parameters struct
Parameters for constructing a SpotLight object.
| Parameter | Description |
|---|---|
| color Color | Light color. |
| intensity float | Light intensity multiplier. |
| angle float | Cone angle (in radians) for spotlight cutoff. |
| penumbra float | Softness of the spotlight edge. |
| target std::shared_ptr<Node> | Node the light is directed toward. |
| attenuation Attenuation | Attenuation parameters controlling distance-based falloff. |
Properties
angle float
Cone angle, in radians, of the spotlight.
float angle {};attenuation Attenuation
Attenuation parameters controlling distance-based falloff.
Attenuation attenuation {};penumbra float
Penumbra controlling the softness of the spotlight’s edge.
float penumbra {};Node that the light is oriented toward.
std::shared_ptr<Node> target {nullptr};Functions
Returns the normalized direction vector of the light.
The direction is derived from the light’s position and its target node. If no target is set, the light will point toward the origin.
Vector3 SpotLight::Direction();GetType() Light::Type virtual
Identifies this light as Light::Type::Spot.
Type vglx::SpotLight::GetType() const override;OnUpdate() void virtual
Called once per frame to update the light state.
Currently used to generate or dispose of debug geometry when debug mode is enabled.
void SpotLight::OnUpdate(float delta) override;| Parameter | Description |
|---|---|
| delta | Time in seconds since the last frame. |
SetDebugMode() void virtual
Enables or disables debug visualization for this light.
When enabled, the renderer will visualize the spotlight cone and influence region using helper line geometry.
void SpotLight::SetDebugMode(bool is_debug_mode) override;| Parameter | Description |
|---|---|
| is_debug_mode | true to enable debug mode; false to disable. |