Point lights

This commit is contained in:
Confideo-IOM
2026-08-28 16:36:25 +01:00
parent 30538ae7ab
commit e3d37e3f8a
60 changed files with 458 additions and 184 deletions
@@ -14,7 +14,9 @@
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
#include "../ecs/systems/HydraSpotShadowSourceSystem.h"
#include "../ecs/systems/HydraPointShadowSourceSystem.h"
#include "../ecs/systems/HydraShadowCasterSystem.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../mesh/StandardVertex.h"
#include "../actor/HydraActorManager.h"
#include "../actor/HydraOutputActor.h"
@@ -34,74 +36,75 @@ void HydraShadowPipeline::Shutdown()
void HydraShadowPipeline::Render()
{
glEnable(GL_DEPTH_TEST); // Depth testing must be active
glDepthMask(GL_TRUE); // Depth buffer must be writable
glDepthFunc(GL_LESS);
_RenderDirectionalShadowMaps();
_RenderSpotShadowMaps();
_RenderPointShadowMaps();
}
void HydraShadowPipeline::_RenderPointShadowMaps()
{
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
std::shared_ptr<HydraPointShadowSourceSystem> shadow_system = ecs->GetSystem<HydraPointShadowSourceSystem>();
glViewport(0, 0, POINT_SHADOW_MAP_SIZE, POINT_SHADOW_MAP_SIZE);
for (HydraID entity_id : shadow_system->Entities)
{
HydraPointShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraPointShadowSourceComponent>(entity_id);
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
_UpdateUBO(light_comp.shadow_map_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
HydraPointShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraPointShadowSourceComponent>(entity_id);
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
float depth_value = 1.0f;
glClear(GL_DEPTH_BUFFER_BIT);
_UpdateUBO(light_comp.shadow_map_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
m_render_stages[POINT_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
float depth_value = 1.0f;
glClear(GL_DEPTH_BUFFER_BIT);
m_render_stages[POINT_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}
void HydraShadowPipeline::_RenderDirectionalShadowMaps()
{
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
std::shared_ptr<HydraDirectionalShadowSourceSystem> shadow_system = ecs->GetSystem<HydraDirectionalShadowSourceSystem>();
glViewport(0, 0, DIRECTIONAL_SHADOW_MAP_SIZE, DIRECTIONAL_SHADOW_MAP_SIZE);
for (HydraID entity_id : shadow_system->Entities)
{
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
_UpdateUBO(light_comp.shadow_map_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
_UpdateUBO(light_comp.shadow_map_id);
float depth_value = 1.0f;
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_DEPTH, 0, &depth_value);
m_render_stages[DIRECTIONAL_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
float depth_value = 1.0f;
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_DEPTH, 0, &depth_value);
m_render_stages[DIRECTIONAL_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}
void HydraShadowPipeline::_RenderSpotShadowMaps()
{
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraShadowCasterSystem> render_system = ecs->GetSystem<HydraShadowCasterSystem>();
std::shared_ptr<HydraSpotShadowSourceSystem> shadow_system = ecs->GetSystem<HydraSpotShadowSourceSystem>();
glViewport(0, 0, SPOT_SHADOW_MAP_SIZE, SPOT_SHADOW_MAP_SIZE);
for (HydraID entity_id : shadow_system->Entities)
{
HydraSpotShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
HydraLightComponent light_comp = GetEngine()->ECS()->GetComponent<HydraLightComponent>(entity_id);
_UpdateUBO(light_comp.shadow_map_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
float depth_value = 1.0f;
@@ -273,7 +276,6 @@ void HydraShadowPipeline::_CreateSpotRenderStage()
m_render_stages[SPOT_RENDER_STAGE] = render_stage;
}
void HydraShadowPipeline::_UpdateUBO(uint32_t shadow_idx)
{
HydraBufferManager *buffer_manager = GetEngine()->BufferManager();
@@ -288,7 +290,6 @@ void HydraShadowPipeline::_BindFrameBufferAttachments(HydraID entity_id)
glBindTextureUnit(0, 0);
}
void HydraShadowPipeline::_CreateUBOs()
{
HydraBufferManager *buffer_manager = GetEngine()->BufferManager();