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

#include <LightMgr.h>

Inheritance diagram for CSE::LightMgr:
CSE::SContainerList< LightComponent * > CSE::CoreBase CSE::SIContainer< S, T, M >

Public Member Functions

 LightMgr ()
 
 ~LightMgr () override
 
void AttachLightToShader (const GLProgramHandle *handle) const
 
void 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< S, T, M >
virtual void Register (T object)=0
 
virtual void Remove (T object)=0
 
virtual T Get (M index) const =0
 
virtual M GetID (T object) const =0
 
- Public Member Functions inherited from CSE::CoreBase
virtual void Update (float elapsedTime)
 

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 = 10.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()

void 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 m_environmentMgr->BindPBREnvironmentMap(handle, textureLayout);
49}

Referenced by CSE::DeferredRenderGroup::RenderGbuffer().

◆ AttachLightToShader()

void 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;
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 light->BindShadow(*handle, index, shadow_index);
38 if (isShadow) ++shadow_index;
39 ++index;
40 }
41
42 if (index <= 0) return;
43
44 glUniform1i(handle->Uniforms.LightSize, (int)m_objects.size());
45}

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

◆ 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 }

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

◆ 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 }

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

◆ Init()

void LightMgr::Init ( )
overridevirtual

Initialize the LightMgr.

Implements CSE::CoreBase.

Definition at line 51 of file LightMgr.cpp.

51 {
52 // Setting PBS Environment
53 m_environmentMgr = new SEnvironmentMgr();
54 m_environmentMgr->RenderPBREnvironment();
55}

◆ RefreshShadowCount()

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

Refresh the shadow count.

Parameters
shadowCountShadow count to refresh. Default is -1.

Definition at line 57 of file LightMgr.cpp.

57 {
58 if(shadowCount < 0) {
59 int tempCount = 0;
60 for (const auto& light : m_objects) {
61 ++tempCount;
62 }
63 m_shadowCount = tempCount;
64 return;
65 }
66 m_shadowCount = shadowCount;
67}

Member Data Documentation

◆ SHADOW_DISTANCE

constexpr float CSE::LightMgr::SHADOW_DISTANCE = 10.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: