Skip to content

SpotLight

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

The light intensity diminishes both with distance and with the angle from the central axis of the cone. This type of light is commonly used to simulate focused sources such as flashlights or stage spotlights, where illumination is limited to a defined region and falls off outside of it.

cpp
auto spot_light = 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
  }
});

When the target parameter is set to nullptr the light points to (0, 0, 0).

INFO

Derives from Light and inherits all public properties and methods.

Construction

Constructors


SpotLight()

cpp
vglx::SpotLight::SpotLight(const Parameters &params)
ParameterDescription
paramsSpotLight::Parameters

Constructs a SpotLight object.

Factories preferred


SpotLight::Create() auto

cpp
static auto vglx::SpotLight::Create(const Parameters &params)
ParameterDescription
paramsSpotLight::Parameters

Creates a shared pointer to a SpotLight object.

Types

SpotLight::Parameters struct

Parameters for constructing a SpotLight object.

NameTypeDescription
anglefloatCone angle (in radians) for spotlight cutoff.
attenuationAttenuationLight attenuation properties.
colorColorLight color.
intensityfloatLight intensity.
penumbrafloatSoftness of the spotlight edge.
targetstd::shared_ptr<Node>Light target position.

Properties

angle float

cpp
float angle

Angle, in radians, of the spotlight's cone.

attenuation Attenuation

cpp
Attenuation attenuation

Light attenuation properties.

penumbra float

cpp
float penumbra

Penumbra value controlling the softness of the spotlight's edge.

target std::shared_ptr<Node>

cpp
std::shared_ptr<Node> target { nullptr }

Node that the light is directed towards.

Functions

Direction() Vector3

cpp
Vector3 vglx::SpotLight::Direction()

Returns the direction vector of the light. Calculates and returns the normalized direction in which the spotlight is pointing. The direction is determined based on the light's position and its target node.

GetType() LightType virtual

cpp
LightType vglx::SpotLight::GetType() const override

Returns light type.

OnUpdate() void virtual

cpp
void vglx::SpotLight::OnUpdate(float delta) override
ParameterDescription
deltaTime in seconds since the last update.

Updates the light each frame.

SetDebugMode() void virtual

cpp
void vglx::SpotLight::SetDebugMode(bool is_debug_mode) override
ParameterDescription
is_debug_modeTrue to enable debug mode, false to disable.

Sets debug mode.

Released under the MIT License.