SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
DirectionalLight.hpp
Go to the documentation of this file.
1
#ifndef _DIRECTIONAL_LIGHT_HPP_
2
#define _DIRECTIONAL_LIGHT_HPP_
3
4
#include <
Lighting/Light.hpp
>
5
6
namespace
Sleak
{
7
8
/// Parallel-ray light with a directional shadow frustum; typically the sun/moon.
9
///
10
/// A directional light has a direction but no position: every ray is
11
/// parallel, so it lights the whole scene evenly. It derives from
12
/// Light, which derives from GameObject, so you add it to a scene with
13
/// SceneBase::AddObject() and the scene registers it with the
14
/// LightManager for you.
15
///
16
/// A three-light setup covers most scenes: a bright warm key that casts
17
/// shadows, a dim cool fill from the opposite side that does not, and a
18
/// rim light from behind to separate silhouettes from the sky. Only the
19
/// key light needs SetCastShadows(true).
20
///
21
/// Shadow quality lives or dies on the frustum size. It is the world
22
/// extent the shadow map covers, so shrinking it to fit the area the
23
/// player can actually see multiplies your effective texel density.
24
/// The default covers a very large area, which is right for open
25
/// terrain and far too coarse for a single figure on a small floor.
26
///
27
/// @code{.cpp}
28
/// auto* key = new Sleak::DirectionalLight("KeyLight");
29
/// key->SetDirection(Sleak::Math::Vector3D(-0.55f, -0.80f, -0.25f));
30
/// key->SetColor(1.0f, 0.93f, 0.80f);
31
/// key->SetIntensity(3.0f);
32
/// key->SetCastShadows(true);
33
/// key->SetShadowFrustumSize(28.0f); // tight coverage, crisp shadows
34
/// key->SetShadowDistance(80.0f);
35
/// key->SetShadowNearPlane(0.1f);
36
/// key->SetShadowFarPlane(200.0f);
37
/// key->SetShadowBias(0.0003f);
38
/// key->SetShadowNormalBias(0.012f);
39
/// AddObject(key);
40
///
41
/// auto* fill = new Sleak::DirectionalLight("FillLight");
42
/// fill->SetDirection(Sleak::Math::Vector3D(0.70f, -0.35f, 0.25f));
43
/// fill->SetColor(0.72f, 0.82f, 1.00f);
44
/// fill->SetIntensity(0.9f);
45
/// fill->SetCastShadows(false);
46
/// AddObject(fill);
47
/// @endcode
48
///
49
/// @see Light, LightManager, PointLight, SpotLight, AreaLight
50
/// @ingroup lighting
51
class
ENGINE_API
DirectionalLight
:
public
Light
{
52
public
:
53
explicit
DirectionalLight
(
54
const
std::string& name =
"DirectionalLight"
);
55
~DirectionalLight
()
override
=
default
;
56
57
RenderEngine::LightGPUEntry
BuildGPUData
()
const override
;
58
59
void
SetDirection
(
const
Math::Vector3D
& dir) {
60
m_direction = dir;
61
m_direction.
Normalize
();
62
}
63
Math::Vector3D
GetDirection
()
const
{
return
m_direction; }
64
65
// Shadow frustum configuration
66
void
SetShadowFrustumSize
(
float
size) { m_shadowFrustumSize = size; }
67
float
GetShadowFrustumSize
()
const
{
return
m_shadowFrustumSize; }
68
69
void
SetShadowDistance
(
float
dist) { m_shadowDistance = dist; }
70
float
GetShadowDistance
()
const
{
return
m_shadowDistance; }
71
72
void
SetShadowNearPlane
(
float
nearPlane) { m_shadowNear = nearPlane; }
73
float
GetShadowNearPlane
()
const
{
return
m_shadowNear; }
74
75
void
SetShadowFarPlane
(
float
farPlane) { m_shadowFar = farPlane; }
76
float
GetShadowFarPlane
()
const
{
return
m_shadowFar; }
77
78
private
:
79
Math::Vector3D
m_direction{0.0f, -1.0f, 0.0f};
80
float
m_shadowFrustumSize = 160.0f;
81
float
m_shadowDistance = 160.0f;
82
float
m_shadowNear = 0.1f;
83
float
m_shadowFar = 500.0f;
84
};
85
86
}
// namespace Sleak
87
88
#endif
// _DIRECTIONAL_LIGHT_HPP_
Light.hpp
Sleak::DirectionalLight::SetShadowFrustumSize
void SetShadowFrustumSize(float size)
Definition
DirectionalLight.hpp:66
Sleak::DirectionalLight::SetDirection
void SetDirection(const Math::Vector3D &dir)
Definition
DirectionalLight.hpp:59
Sleak::DirectionalLight::GetShadowNearPlane
float GetShadowNearPlane() const
Definition
DirectionalLight.hpp:73
Sleak::DirectionalLight::BuildGPUData
RenderEngine::LightGPUEntry BuildGPUData() const override
Packs this light's parameters into the GPU-side entry used by the lighting constant buffer.
Definition
DirectionalLight.cpp:9
Sleak::DirectionalLight::GetShadowFarPlane
float GetShadowFarPlane() const
Definition
DirectionalLight.hpp:76
Sleak::DirectionalLight::SetShadowFarPlane
void SetShadowFarPlane(float farPlane)
Definition
DirectionalLight.hpp:75
Sleak::DirectionalLight::SetShadowDistance
void SetShadowDistance(float dist)
Definition
DirectionalLight.hpp:69
Sleak::DirectionalLight::GetDirection
Math::Vector3D GetDirection() const
Definition
DirectionalLight.hpp:63
Sleak::DirectionalLight::DirectionalLight
DirectionalLight(const std::string &name="DirectionalLight")
Definition
DirectionalLight.cpp:6
Sleak::DirectionalLight::GetShadowDistance
float GetShadowDistance() const
Definition
DirectionalLight.hpp:70
Sleak::DirectionalLight::~DirectionalLight
~DirectionalLight() override=default
Sleak::DirectionalLight::GetShadowFrustumSize
float GetShadowFrustumSize() const
Definition
DirectionalLight.hpp:67
Sleak::DirectionalLight::SetShadowNearPlane
void SetShadowNearPlane(float nearPlane)
Definition
DirectionalLight.hpp:72
Sleak::Light::Light
Light(const std::string &name="Light")
Definition
Light.cpp:5
Sleak::Math::Vector3D
Definition
Vector.hpp:354
Sleak::Math::Vector3D::Normalize
Vector3D & Normalize()
Definition
Vector.hpp:436
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
Sleak::RenderEngine::LightGPUEntry
One light's packed GPU representation, laid out for std140/cbuffer alignment.
Definition
ConstantBuffer.hpp:20
include
public
Lighting
DirectionalLight.hpp
Generated on
for SleakEngine by
1.18.0