SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::DirectionalLight Class Reference

#include <DirectionalLight.hpp>

Inheritance diagram for Sleak::DirectionalLight:

Public Member Functions

 DirectionalLight (const std::string &name="DirectionalLight")
 ~DirectionalLight () override=default
RenderEngine::LightGPUEntry BuildGPUData () const override
 Packs this light's parameters into the GPU-side entry used by the lighting constant buffer.
Math::Vector3D GetDirection () const
float GetShadowDistance () const
float GetShadowFarPlane () const
float GetShadowFrustumSize () const
float GetShadowNearPlane () const
void SetDirection (const Math::Vector3D &dir)
void SetShadowDistance (float dist)
void SetShadowFarPlane (float farPlane)
void SetShadowFrustumSize (float size)
void SetShadowNearPlane (float nearPlane)
Public Member Functions inherited from Sleak::Light
 Light (const std::string &name="Light")
 ~Light () override=default
bool GetCastShadows () const
Math::Vector3D GetColor () const
float GetIntensity () const
float GetLightSize () const
float GetShadowBias () const
float GetShadowNormalBias () const
float GetShadowStrength () const
bool IsEnabled () const
bool IsLight () const override
void SetCastShadows (bool cast)
void SetColor (const Math::Color &color)
void SetColor (float r, float g, float b)
void SetEnabled (bool enabled)
void SetIntensity (float intensity)
void SetLightSize (float size)
void SetShadowBias (float bias)
void SetShadowNormalBias (float bias)
void SetShadowStrength (float strength)
Public Member Functions inherited from Sleak::GameObject
 GameObject (const std::string &name="GameObject")
 ~GameObject () override
void AddChild (GameObject *child)
template<typename T, typename... Args>
void AddComponent (Args &&... args)
 Constructs and attaches a component of type T. Warns and no-ops if one already exists.
virtual void FixedUpdate (float fixedDeltaTime)
const List< GameObject * > & GetChildren () const
template<typename T>
T * GetComponent ()
 Finds the first attached component of type T, or nullptr.
GameObjectGetParent () const
const std::string & GetTag () const
bool HasChildren () const
template<typename T>
bool HasComponent ()
 True if a component of type T is attached.
bool HasParent () const
virtual void Initialize ()
 Initializes the object and its components; called once before the first Update.
bool IsActive () const
bool IsPendingDestroy () const
virtual void LateUpdate (float deltaTime)
void MarkForDestroy ()
 Flags the object for deferred destruction on the next scene pass.
void RemoveChild (GameObject *child)
template<typename T>
void RemoveComponent ()
 Destroys and detaches the first component of type T, if present.
void SetActive (bool active)
 Enables or disables the object, firing OnEnable/OnDisable on its components.
void SetParent (GameObject *parent)
 Reparents this object, updating both the old and new parent's child lists.
void SetTag (const std::string &tag)
virtual void Update (float deltaTime)
Public Member Functions inherited from Sleak::Object
 Object (const std::string &name="Object")
virtual ~Object ()=default
const std::string & GetName () const
uint64_t GetUniqueID () const
void SetName (const std::string &value)

Additional Inherited Members

Static Public Member Functions inherited from Sleak::GameObject
static GameObjectCreateCapsule (Math::Vector3D position, int segments=16, int rings=8, float height=1, float radius=0.5)
static GameObjectCreateCube (Math::Vector3D position)
static GameObjectCreateCylinder (Math::Vector3D position, int segments=16, float height=1, float radius=0.5)
static GameObjectCreatePlane (Math::Vector3D position, int width=100, int height=100)
 Built-in primitive factories, mainly for prototyping and debug scenes.
static GameObjectCreateSphere (Math::Vector3D position, int stack=16, int slices=16)
static GameObjectCreateTorus (Math::Vector3D position, int segments=16, int rings=8, float innerRadius=8, float outerRadius=9)
Protected Attributes inherited from Sleak::Light
bool m_castShadows = false
Math::Vector3D m_color {1.0f, 1.0f, 1.0f}
float m_intensity = 1.0f
bool m_lightEnabled = true
float m_lightSize = 1.0f
float m_shadowBias = 0.005f
float m_shadowNormalBias = 0.02f
float m_shadowStrength = 1.0f
Protected Attributes inherited from Sleak::GameObject
bool bIsInitialized

Detailed Description

Parallel-ray light with a directional shadow frustum; typically the sun/moon.

A directional light has a direction but no position: every ray is parallel, so it lights the whole scene evenly. It derives from Light, which derives from GameObject, so you add it to a scene with SceneBase::AddObject() and the scene registers it with the LightManager for you.

A three-light setup covers most scenes: a bright warm key that casts shadows, a dim cool fill from the opposite side that does not, and a rim light from behind to separate silhouettes from the sky. Only the key light needs SetCastShadows(true).

Shadow quality lives or dies on the frustum size. It is the world extent the shadow map covers, so shrinking it to fit the area the player can actually see multiplies your effective texel density. The default covers a very large area, which is right for open terrain and far too coarse for a single figure on a small floor.

auto* key = new Sleak::DirectionalLight("KeyLight");
key->SetDirection(Sleak::Math::Vector3D(-0.55f, -0.80f, -0.25f));
key->SetColor(1.0f, 0.93f, 0.80f);
key->SetIntensity(3.0f);
key->SetCastShadows(true);
key->SetShadowFrustumSize(28.0f); // tight coverage, crisp shadows
key->SetShadowDistance(80.0f);
key->SetShadowNearPlane(0.1f);
key->SetShadowFarPlane(200.0f);
key->SetShadowBias(0.0003f);
key->SetShadowNormalBias(0.012f);
AddObject(key);
auto* fill = new Sleak::DirectionalLight("FillLight");
fill->SetDirection(Sleak::Math::Vector3D(0.70f, -0.35f, 0.25f));
fill->SetColor(0.72f, 0.82f, 1.00f);
fill->SetIntensity(0.9f);
fill->SetCastShadows(false);
AddObject(fill);
See also
Light, LightManager, PointLight, SpotLight, AreaLight

Definition at line 51 of file DirectionalLight.hpp.

Constructor & Destructor Documentation

◆ DirectionalLight()

Sleak::DirectionalLight::DirectionalLight ( const std::string & name = "DirectionalLight")
explicit

Definition at line 6 of file DirectionalLight.cpp.

◆ ~DirectionalLight()

Sleak::DirectionalLight::~DirectionalLight ( )
overridedefault

Member Function Documentation

◆ BuildGPUData()

RenderEngine::LightGPUEntry Sleak::DirectionalLight::BuildGPUData ( ) const
overridevirtual

Packs this light's parameters into the GPU-side entry used by the lighting constant buffer.

Implements Sleak::Light.

Definition at line 9 of file DirectionalLight.cpp.

◆ GetDirection()

Math::Vector3D Sleak::DirectionalLight::GetDirection ( ) const
inline

Definition at line 63 of file DirectionalLight.hpp.

◆ GetShadowDistance()

float Sleak::DirectionalLight::GetShadowDistance ( ) const
inline

Definition at line 70 of file DirectionalLight.hpp.

◆ GetShadowFarPlane()

float Sleak::DirectionalLight::GetShadowFarPlane ( ) const
inline

Definition at line 76 of file DirectionalLight.hpp.

◆ GetShadowFrustumSize()

float Sleak::DirectionalLight::GetShadowFrustumSize ( ) const
inline

Definition at line 67 of file DirectionalLight.hpp.

◆ GetShadowNearPlane()

float Sleak::DirectionalLight::GetShadowNearPlane ( ) const
inline

Definition at line 73 of file DirectionalLight.hpp.

◆ SetDirection()

void Sleak::DirectionalLight::SetDirection ( const Math::Vector3D & dir)
inline

Definition at line 59 of file DirectionalLight.hpp.

◆ SetShadowDistance()

void Sleak::DirectionalLight::SetShadowDistance ( float dist)
inline

Definition at line 69 of file DirectionalLight.hpp.

◆ SetShadowFarPlane()

void Sleak::DirectionalLight::SetShadowFarPlane ( float farPlane)
inline

Definition at line 75 of file DirectionalLight.hpp.

◆ SetShadowFrustumSize()

void Sleak::DirectionalLight::SetShadowFrustumSize ( float size)
inline

Definition at line 66 of file DirectionalLight.hpp.

◆ SetShadowNearPlane()

void Sleak::DirectionalLight::SetShadowNearPlane ( float nearPlane)
inline

Definition at line 72 of file DirectionalLight.hpp.