CSEngine
Loading...
Searching...
No Matches
LightMgr.cpp
1#include "LightMgr.h"
2#include "../Component/RenderComponent.h"
3#include "../Util/GLProgramHandle.h"
4#include "../Util/Render/SEnvironmentMgr.h"
5
6using namespace CSE;
7
8LightMgr::LightMgr() = default;
9
11 SAFE_DELETE(m_environmentMgr);
12}
13
14
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}
46
47void LightMgr::AttachLightMapToShader(const GLProgramHandle* handle, int textureLayout) const {
48 m_environmentMgr->BindPBREnvironmentMap(handle, textureLayout);
49}
50
52 // Setting PBS Environment
53 m_environmentMgr = new SEnvironmentMgr();
54 m_environmentMgr->RenderPBREnvironment();
55}
56
57void LightMgr::RefreshShadowCount(int shadowCount) const {
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}
void Init() override
Definition LightMgr.cpp:51
void RefreshShadowCount(int shadowCount=-1) const
Definition LightMgr.cpp:57
void AttachLightMapToShader(const GLProgramHandle *handle, int textureLayout) const
Definition LightMgr.cpp:47
void AttachLightToShader(const GLProgramHandle *handle) const
Definition LightMgr.cpp:15
~LightMgr() override
Definition LightMgr.cpp:10