Skip to content

SpotLight ​

Represents a light that emits in a specific direction with a cone-shaped area of influence.

A spotlight combines directional and point light behavior: intensity follows physical inverse-square falloff with distance and diminishes 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. The target must belong to the same Scene as this object. Attaching or referencing a target from a different scene results in undefined behavior and is not supported.

cpp
my_scene->Add(vglx::SpotLight::Create({
  .color = 0xFFFFFFu,
  .intensity = 25.0f,
  .angle = vglx::math::DegToRad(10.0f),
  .penumbra = 0.3f,
  .target = nullptr,
  .range = 0.0f
}));

INFO

Derives from Light and inherits all public properties and methods.

Construction ​

Constructors ​


SpotLight() ​

Constructs a spotlight.

cpp
SpotLight::SpotLight(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the light.

Factories preferred ​


SpotLight::Create() std::unique_ptr<SpotLight> ​

Creates an instance of SpotLight with default parameters.

cpp
static std::unique_ptr<SpotLight> SpotLight::Create();

SpotLight::Create() std::unique_ptr<SpotLight> ​

Creates an instance of SpotLight.

cpp
static std::unique_ptr<SpotLight> SpotLight::Create(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the light.

Types ​

SpotLight::Parameters struct ​

Parameters for constructing a SpotLight object.

ParameterDescription
color ColorLight color.
intensity floatLight intensity multiplier.
angle floatCone angle (in radians) for spotlight cutoff.
penumbra floatSoftness of the spotlight edge.
target Node*Node the light is directed toward.
range floatMaximum range of influence. 0 = unbounded.
cast_shadow boolEnables shadow casting for this light.

Properties ​

angle float ​

Cone angle, in radians, of the spotlight.

cpp
float angle {};

cast_shadow bool ​

When true this light casts shadows.

cpp
bool cast_shadow {false};

penumbra float ​

Penumbra controlling the softness of the spotlight’s edge.

cpp
float penumbra {};

range float ​

Maximum range of influence in world units.

Falloff is smoothly windowed to reach zero at this distance. A value of 0 disables the cutoff, leaving pure inverse-square falloff.

cpp
float range {0.0f};

shadow Shadow ​

Shadow configuration used when cast_shadow is enabled.

cpp
Shadow shadow {};

target Node* ​

Node that the light is oriented toward.

cpp
Node* target {nullptr};

Functions ​

Direction() Vector3 ​

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.

cpp
Vector3 SpotLight::Direction();

GetPower() float ​

Returns the light's luminous power in lumens.

Uses the convention , where is intensity in candela, so power is independent of the cone angle.

cpp
float SpotLight::GetPower() const;

GetType() Light::Type virtual ​

Identifies this light as Light::Type::Spot.

cpp
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.

cpp
void SpotLight::OnUpdate(float delta) override;
ParameterDescription
deltaTime 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.

cpp
void SpotLight::SetDebugMode(bool is_debug_mode) override;
ParameterDescription
is_debug_modetrue to enable debug mode; false to disable.

SetPower() void ​

Sets intensity from luminous power in lumens.

cpp
void SpotLight::SetPower(float power);
ParameterDescription
powerLuminous power in lumens.

Released under the MIT License.