Skip to content

DirectionalLight

Represents a light that emits in a single direction.

A directional light simulates an infinitely distant light source, such as sunlight. All light rays are considered parallel, and the light has no position in space, only direction. This makes it ideal for large-scale illumination like outdoor or scene-wide lighting.

When the target parameter is set to nullptr, the light will point toward the world origin.

cpp
auto directional = vglx::DirectionalLight::Create({
  .color = 0xFFFFFF,
  .intensity = 1.0f,
  .target = nullptr
});

INFO

Derives from Light and inherits all public properties and methods.

Construction

Constructors


DirectionalLight()

Constructs a directional light.

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

Factories preferred


DirectionalLight::Create() auto

Creates a shared instance of DirectionalLight.

cpp
static auto DirectionalLight::Create(const Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the light.

Types

DirectionalLight::Parameters struct

Parameters for constructing a DirectionalLight object.

ParameterDescription
color ColorLight color.
intensity floatLight intensity multiplier.
target std::shared_ptr<Node>Node the light is directed toward.

Properties

target std::shared_ptr<Node>

Node that the light is oriented toward.

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

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 DirectionalLight::Direction();

GetType() Light::Type virtual

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

cpp
Type vglx::DirectionalLight::GetType() const override;

OnUpdate() void virtual

Called once per frame to update the light state.

Currently used to update the debug geometry when debug mode is enabled.

cpp
void DirectionalLight::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 light’s direction using a line and a unit plane facing the target.

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

Released under the MIT License.