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

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

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

Factories preferred


SpotLight::Create() auto

Creates a shared instance of SpotLight.

cpp
static auto 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 std::shared_ptr<Node>Node the light is directed toward.
attenuation AttenuationAttenuation parameters controlling distance-based falloff.

Properties

angle float

Cone angle, in radians, of the spotlight.

cpp
float angle {};

attenuation Attenuation

Attenuation parameters controlling distance-based falloff.

cpp
Attenuation attenuation {};

penumbra float

Penumbra controlling the softness of the spotlight’s edge.

cpp
float penumbra {};

target std::shared_ptr<Node>

Node that the light is oriented toward.

cpp
std::shared_ptr<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();

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.

Released under the MIT License.