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 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}
46
47int LightMgr::AttachLightMapToShader(const GLProgramHandle* handle, int textureLayout) const {
48 int layout = m_environmentMgr->BindPBREnvironmentMap(handle, textureLayout);
49 layout += m_environmentMgr->BindBRDFLUT(handle, textureLayout + layout);
50 return layout;
51}
52
54 // Setting PBS Environment
55 m_environmentMgr = new SEnvironmentMgr();
56 m_environmentMgr->RenderPBREnvironment();
57 m_environmentMgr->RenderBRDFLUT();
58 m_environmentMgr->ReleaseRenderingResources();
59}
60
61void LightMgr::RefreshShadowCount(int shadowCount) const {
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}
72
73void LightMgr::ExterminateGlobalSettings() {
74 SEnvironmentMgr::ReleaseVAO();
75}
void Init() override
Definition LightMgr.cpp:53
void RefreshShadowCount(int shadowCount=-1) const
Definition LightMgr.cpp:61
~LightMgr() override
Definition LightMgr.cpp:10
int AttachLightMapToShader(const GLProgramHandle *handle, int textureLayout) const
Definition LightMgr.cpp:47
int AttachLightToShader(const GLProgramHandle *handle) const
Definition LightMgr.cpp:15