CSEngine
Loading...
Searching...
No Matches
CSE::LightMgr Class Reference

#include <LightMgr.h>

Inheritance diagram for CSE::LightMgr:
CSE::SContainerList< LightComponent * > CSE::CoreBase CSE::SIContainer< std::list< LightComponent * >, LightComponent *, int >

Public Member Functions

 LightMgr ()
 
 ~LightMgr () override
 
int AttachLightToShader (const GLProgramHandle *handle) const
 
int AttachLightMapToShader (const GLProgramHandle *handle, int textureLayout) const
 
void Init () override
 
int GetShadowCount () const
 
int GetLightMapCount () const
 
void RefreshShadowCount (int shadowCount=-1) const
 
- Public Member Functions inherited from CSE::SContainerList< LightComponent * >
void Register (LightComponent *object) override
 
void Remove (LightComponent *object) override
 
LightComponentGet (int index) const override
 
std::list< LightComponent * > GetAll () const override
 
int GetID (LightComponent *object) const override
 
int GetSize () const override
 
- Public Member Functions inherited from CSE::SIContainer< std::list< LightComponent * >, LightComponent *, int >
- Public Member Functions inherited from CSE::CoreBase
virtual void Update (float elapsedTime)
 

Static Public Member Functions

static void ExterminateGlobalSettings ()
 

Public Attributes

const int SHADOW_WIDTH = 1024
 Width of the shadow map.
 
const int SHADOW_HEIGHT = 1024
 Height of the shadow map.
 

Static Public Attributes

static constexpr float SHADOW_DISTANCE = 100.f
 Distance of the shadow map.
 

Additional Inherited Members

- Protected Attributes inherited from CSE::SContainerList< LightComponent * >
std::list< LightComponent * > m_objects
 
int m_size
 

Detailed Description

LightMgr class is a manager of Light components. This class also manages ShadowMap for giving shadow effects to objects in the scene.

Definition at line 17 of file LightMgr.h.

Constructor & Destructor Documentation

◆ LightMgr()

LightMgr::LightMgr ( )
explicitdefault

Constructor of LightMgr.

◆ ~LightMgr()

LightMgr::~LightMgr ( )
override

Destructor of LightMgr.

Definition at line 10 of file LightMgr.cpp.

10 {
11 SAFE_DELETE(m_environmentMgr);
12}

Member Function Documentation

◆ AttachLightMapToShader()

int LightMgr::AttachLightMapToShader ( const GLProgramHandle * handle,
int textureLayout ) const

Attach the light map to the shader.

Parameters
handleShader handle
textureLayoutLayout of the texture

Definition at line 47 of file LightMgr.cpp.

47 {
48 int layout = m_environmentMgr->BindPBREnvironmentMap(handle, textureLayout);
49 layout += m_environmentMgr->BindBRDFLUT(handle, textureLayout + layout);
50 return layout;
51}

Referenced by CSE::ForwardRenderGroup::RenderAll(), and CSE::DeferredRenderGroup::RenderGbuffer().

◆ AttachLightToShader()

int LightMgr::AttachLightToShader ( const GLProgramHandle * handle) const

Attach the light components to the shader.

Parameters
handleShader handle

Definition at line 15 of file LightMgr.cpp.

15 {
16 if (handle == nullptr) return 0;
17
18 int index = 0;
19 int shadow_index = 0;
20 for (const auto& light : m_objects) {
21 if (light == nullptr || !light->GetIsEnable()) continue;
22
23 const auto& lightObject = light->GetLight();
24 const auto& position = (light->m_type == LightComponent::DIRECTIONAL)
25 ? lightObject->direction
26 : vec4(*lightObject->position, 1.0f);
27
28 glUniform4f(handle->Uniforms.LightPosition + index,
29 position.x, position.y, position.z, (light->m_type == LightComponent::DIRECTIONAL) ? 0.0f : 1.0f);
30 glUniform3f(handle->Uniforms.LightColor + index, lightObject->color.x, lightObject->color.y, lightObject->color.z);
31 glUniform1i(handle->Uniforms.LightType + index, light->m_type);
32 if (handle->Uniforms.LightRadius >= 0)
33 glUniform1f(handle->Uniforms.LightRadius + index, lightObject->radius);
34 // Shadow
35 auto isShadow = light->IsShadow();
36 glUniform1i(handle->Uniforms.LightShadowMode + index, isShadow ? 1 : 0);
37 shadow_index += light->BindShadow(*handle, index, shadow_index);
38 ++index;
39 }
40
41 if (index <= 0) return shadow_index;
42
43 glUniform1i(handle->Uniforms.LightSize, (int)m_objects.size());
44 return shadow_index;
45}

Referenced by CSE::ForwardRenderGroup::RenderAll(), and CSE::DeferredRenderGroup::RenderGbuffer().

◆ ExterminateGlobalSettings()

void LightMgr::ExterminateGlobalSettings ( )
static

Definition at line 73 of file LightMgr.cpp.

73 {
74 SEnvironmentMgr::ReleaseVAO();
75}

◆ GetLightMapCount()

int CSE::LightMgr::GetLightMapCount ( ) const
inline

Get the light map count.

Returns
Light map count

Definition at line 64 of file LightMgr.h.

64 {
65 return m_lightMapCount;
66 }

◆ GetShadowCount()

int CSE::LightMgr::GetShadowCount ( ) const
inline

Get the shadow count.

Returns
Shadow count

Definition at line 56 of file LightMgr.h.

56 {
57 return m_shadowCount;
58 }

◆ Init()

void LightMgr::Init ( )
overridevirtual

Initialize the LightMgr.

Implements CSE::CoreBase.

Definition at line 53 of file LightMgr.cpp.

53 {
54 // Setting PBS Environment
55 m_environmentMgr = new SEnvironmentMgr();
56 m_environmentMgr->RenderPBREnvironment();
57 m_environmentMgr->RenderBRDFLUT();
58 m_environmentMgr->ReleaseRenderingResources();
59}

◆ RefreshShadowCount()

void LightMgr::RefreshShadowCount ( int shadowCount = -1) const

Refresh the shadow count.

Parameters
shadowCountShadow count to refresh. Default is -1.

Definition at line 61 of file LightMgr.cpp.

61 {
62 if(shadowCount < 0) {
63 int tempCount = 0;
64 for (const auto& light : m_objects) {
65 ++tempCount;
66 }
67 m_shadowCount = tempCount;
68 return;
69 }
70 m_shadowCount = shadowCount;
71}

Member Data Documentation

◆ SHADOW_DISTANCE

float CSE::LightMgr::SHADOW_DISTANCE = 100.f
staticconstexpr

Distance of the shadow map.

Definition at line 21 of file LightMgr.h.

Referenced by CSE::DepthOnlyRenderGroup::RenderAll().

◆ SHADOW_HEIGHT

const int CSE::LightMgr::SHADOW_HEIGHT = 1024

Height of the shadow map.

Definition at line 20 of file LightMgr.h.

◆ SHADOW_WIDTH

const int CSE::LightMgr::SHADOW_WIDTH = 1024

Width of the shadow map.

Definition at line 19 of file LightMgr.h.


The documentation for this class was generated from the following files: