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

#include <LightManager.hpp>

Public Member Functions

 LightManager ()
 ~LightManager ()
float GetAmbientIntensity () const
float GetFogEnd () const
float GetFogStart () const
float GetHeightFogDensity () const
float GetHeightFogFalloff () const
float GetHeightFogTop () const
size_t GetLightCount () const
void Initialize ()
 Allocates the GPU light buffer; call once before the first UpdateAndBind.
bool IsFogEnabled () const
bool IsHeightFogEnabled () const
void RegisterLight (Light *light)
void SetAmbientColor (float r, float g, float b)
void SetAmbientIntensity (float intensity)
void SetFogColor (float r, float g, float b)
void SetFogDistances (float start, float end)
void SetFogEnabled (bool enabled)
void SetFogZenithColor (float r, float g, float b)
void SetHeightFogDensity (float d)
void SetHeightFogEnabled (bool enabled)
void SetHeightFogFalloff (float f)
void SetHeightFogTop (float worldY)
void UnregisterLight (Light *light)
void UpdateAndBind ()
 Packs every registered light and the fog/ambient parameters into the light buffer and binds it.
void UpdateDeferredCB ()
 Refreshes the deferred-pass constant buffer (fog, ambient) independent of the per-light data.
void UpdateShadowData ()
 Picks the active shadow-casting light and refreshes its shadow-space matrices.

Detailed Description

Owns the registered light list and the GPU-side light/fog constant buffers; one instance per scene.

Each Scene owns one, reachable through SceneBase::GetLightManager(). Lights register themselves when their GameObject is added to the scene, so you almost never call RegisterLight() directly. What you do use it for is the scene-wide atmosphere that is not attached to any single light: ambient color and intensity, distance fog, and height fog.

Ambient light is the floor value that keeps shadow-side surfaces from going flat black. Tinting it toward the sky color, then keeping the intensity low, reads as sky bounce without washing out the directional lights doing the real work.

Fog has two layers that stack. Distance fog blends between a horizon color and a zenith color as the view tilts upward, fading in between the start and end distances. Height fog adds exponential density below a world height, which is what grounds figures on a floor plane and pools haze in valleys.

if (auto* lm = GetLightManager()) {
lm->SetAmbientColor(0.30f, 0.34f, 0.40f);
lm->SetAmbientIntensity(0.75f);
lm->SetFogColor(0.62f, 0.70f, 0.82f); // horizon
lm->SetFogZenithColor(0.42f, 0.55f, 0.80f); // straight up
lm->SetFogDistances(60.0f, 220.0f);
lm->SetFogEnabled(true);
lm->SetHeightFogEnabled(true);
lm->SetHeightFogTop(4.0f);
lm->SetHeightFogDensity(0.15f);
lm->SetHeightFogFalloff(0.25f);
}
See also
Light, DirectionalLight, PointLight, SpotLight, SceneBase

Definition at line 57 of file LightManager.hpp.

Constructor & Destructor Documentation

◆ LightManager()

Sleak::LightManager::LightManager ( )
default

◆ ~LightManager()

Sleak::LightManager::~LightManager ( )
default

Member Function Documentation

◆ GetAmbientIntensity()

float Sleak::LightManager::GetAmbientIntensity ( ) const
inline

Definition at line 80 of file LightManager.hpp.

◆ GetFogEnd()

float Sleak::LightManager::GetFogEnd ( ) const
inline

Definition at line 97 of file LightManager.hpp.

◆ GetFogStart()

float Sleak::LightManager::GetFogStart ( ) const
inline

Definition at line 96 of file LightManager.hpp.

◆ GetHeightFogDensity()

float Sleak::LightManager::GetHeightFogDensity ( ) const
inline

Definition at line 114 of file LightManager.hpp.

◆ GetHeightFogFalloff()

float Sleak::LightManager::GetHeightFogFalloff ( ) const
inline

Definition at line 115 of file LightManager.hpp.

◆ GetHeightFogTop()

float Sleak::LightManager::GetHeightFogTop ( ) const
inline

Definition at line 113 of file LightManager.hpp.

◆ GetLightCount()

size_t Sleak::LightManager::GetLightCount ( ) const
inline

Definition at line 84 of file LightManager.hpp.

◆ Initialize()

void Sleak::LightManager::Initialize ( )

Allocates the GPU light buffer; call once before the first UpdateAndBind.

Definition at line 62 of file LightManager.cpp.

◆ IsFogEnabled()

bool Sleak::LightManager::IsFogEnabled ( ) const
inline

Definition at line 95 of file LightManager.hpp.

◆ IsHeightFogEnabled()

bool Sleak::LightManager::IsHeightFogEnabled ( ) const
inline

Definition at line 112 of file LightManager.hpp.

◆ RegisterLight()

void Sleak::LightManager::RegisterLight ( Light * light)

Definition at line 73 of file LightManager.cpp.

◆ SetAmbientColor()

void Sleak::LightManager::SetAmbientColor ( float r,
float g,
float b )

Definition at line 428 of file LightManager.cpp.

◆ SetAmbientIntensity()

void Sleak::LightManager::SetAmbientIntensity ( float intensity)
inline

Definition at line 76 of file LightManager.hpp.

◆ SetFogColor()

void Sleak::LightManager::SetFogColor ( float r,
float g,
float b )
inline

Definition at line 88 of file LightManager.hpp.

◆ SetFogDistances()

void Sleak::LightManager::SetFogDistances ( float start,
float end )
inline

Definition at line 91 of file LightManager.hpp.

◆ SetFogEnabled()

void Sleak::LightManager::SetFogEnabled ( bool enabled)
inline

Definition at line 94 of file LightManager.hpp.

◆ SetFogZenithColor()

void Sleak::LightManager::SetFogZenithColor ( float r,
float g,
float b )
inline

Two-color sky-matched fog gradient. SetFogColor(r,g,b) above sets the horizon color; the zenith color blends in as the view direction tilts upward.

Definition at line 102 of file LightManager.hpp.

◆ SetHeightFogDensity()

void Sleak::LightManager::SetHeightFogDensity ( float d)
inline

Definition at line 110 of file LightManager.hpp.

◆ SetHeightFogEnabled()

void Sleak::LightManager::SetHeightFogEnabled ( bool enabled)
inline

Height fog: exponential density that thickens below HeightFogTop. density(y) = HeightFogDensity * exp(-max(0, y - HeightFogTop) * HeightFogFalloff)

Definition at line 108 of file LightManager.hpp.

◆ SetHeightFogFalloff()

void Sleak::LightManager::SetHeightFogFalloff ( float f)
inline

Definition at line 111 of file LightManager.hpp.

◆ SetHeightFogTop()

void Sleak::LightManager::SetHeightFogTop ( float worldY)
inline

Definition at line 109 of file LightManager.hpp.

◆ UnregisterLight()

void Sleak::LightManager::UnregisterLight ( Light * light)

Definition at line 88 of file LightManager.cpp.

◆ UpdateAndBind()

void Sleak::LightManager::UpdateAndBind ( )

Packs every registered light and the fog/ambient parameters into the light buffer and binds it.

Definition at line 96 of file LightManager.cpp.

◆ UpdateDeferredCB()

void Sleak::LightManager::UpdateDeferredCB ( )

Refreshes the deferred-pass constant buffer (fog, ambient) independent of the per-light data.

Definition at line 434 of file LightManager.cpp.

◆ UpdateShadowData()

void Sleak::LightManager::UpdateShadowData ( )

Picks the active shadow-casting light and refreshes its shadow-space matrices.

Definition at line 164 of file LightManager.cpp.