This commit is contained in:
Confideo-IOM
2026-08-04 17:39:07 +01:00
parent d074dc71a5
commit 3e8b8952f7
42 changed files with 228 additions and 94 deletions
@@ -14,6 +14,7 @@
#include "../../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
#include "../../task/buffer/HydraUpdatePartialGPUBufferTask.hpp"
#include "../../task/buffer/HydraCreateUnBoundTextureTask.hpp"
#include "../../task/renderer/HydraCreateCascadeShadowFrameBuffer.hpp"
#include "../../task/renderer/HydraCreateShadowFrameBuffer.hpp"
#include "../../actor/HydraActorManager.h"
@@ -55,6 +56,7 @@ void HydraShadowSourceSystem::InitialiseComponent(HydraID entity_id)
_InitialiseDirectionalLight(entity_id);
break;
}
}
void HydraShadowSourceSystem::UpdateSystem(float delta_t_seconds)
@@ -68,9 +70,9 @@ void HydraShadowSourceSystem::UpdateSystem(float delta_t_seconds)
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
switch (light_comp.light_type)
{
case (int)HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL:
_UpdateDirectionalLight(entity_id);
break;
case (int)HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL:
_UpdateDirectionalLight(entity_id);
break;
}
HydraShadowSourceComponent shad_comp = ecs->GetComponent<HydraShadowSourceComponent>(entity_id);
@@ -123,6 +125,27 @@ void HydraShadowSourceSystem::_UpdateDirectionalLight(HydraID entity_id)
}
}
void HydraShadowSourceSystem::_UpdateSpotLight(HydraID entity_id)
{
// HydraEngine *engine = GetEngine();
// HydraECS *ecs = engine->ECS();
// HydraPositionComponent pos_comp = ecs->GetComponent<HydraPositionComponent>(entity_id);
// HydraShadowSourceComponent &shad_comp = ecs->GetComponent<HydraShadowSourceComponent>(entity_id);
// HydraLightComponent light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
// float view_size = 50.0f;
// float view_near = -100.0f;
// float view_far = 100.0f;
// glm::mat4 view = pos_comp.transform;
// glm::mat4 proj = glm::ortho<float>(-view_size, view_size, view_size, -view_size, view_near, view_far);
// shad_comp.far_plane[0] = view_far;
// shad_comp.near_plane[0] = view_near;
// shad_comp.light_space_proj[0] = proj;
// shad_comp.light_space_view[0] = view;
}
void HydraShadowSourceSystem::_InitialiseDirectionalLight(HydraID entity_id)
{
HydraEngine *engine = GetEngine();
@@ -135,14 +158,32 @@ void HydraShadowSourceSystem::_InitialiseDirectionalLight(HydraID entity_id)
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
uint32_t depth_texture_id = 0;
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateShadowFrameBuffer>(HydraThreadAffinity::Render);
HydraCreateShadowFrameBuffer *fb_task = static_cast<HydraCreateShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCascadeShadowFrameBuffer>(HydraThreadAffinity::Render);
HydraCreateCascadeShadowFrameBuffer *fb_task = static_cast<HydraCreateCascadeShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
task_scheduler->WaitForTask(create_framebuffer_task_id);
shad_comp.shadow_texture_id = depth_texture_id;
}
void HydraShadowSourceSystem::_InitialiseSpotLight(HydraID entity_id)
{
// HydraEngine *engine = GetEngine();
// HydraECS *ecs = engine->ECS();
// HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
// HydraShadowSourceComponent &shad_comp = ecs->GetComponent<HydraShadowSourceComponent>(entity_id);
// shad_comp.entity_id = entity_id;
// shad_comp.cascade_count = 6;
// HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
// uint32_t depth_texture_id = 0;
// HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateShadowFrameBuffer>(HydraThreadAffinity::Render);
// HydraCreateShadowFrameBuffer *fb_task = static_cast<HydraCreateShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
// fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
// task_scheduler->WaitForTask(create_framebuffer_task_id);
// shad_comp.shadow_texture_id = depth_texture_id;
}
void HydraShadowSourceSystem::_WriteToGPU()
{
HydraEngine *engine = GetEngine();
@@ -17,7 +17,9 @@ class HydraShadowSourceSystem : public HydraSystem
void UpdateSystem(float delta_t_seconds) override;
private:
void _UpdateDirectionalLight(HydraID entity_id);
void _UpdateSpotLight(HydraID entity_id);
void _InitialiseDirectionalLight(HydraID entity_id);
void _InitialiseSpotLight(HydraID entity_id);
void _WriteToGPU();
HydraID m_shadow_buffer_id = INVALID_HYDRA_ID;
std::queue<HydraID> m_available_shadows;