2026-08-16 13:47:11 +01:00
|
|
|
#include "HydraPointShadowSourceSystem.h"
|
|
|
|
|
#include "../../engine/HydraEngine.h"
|
|
|
|
|
#include "../../camera/HydraCamera.h"
|
|
|
|
|
#include "../HydraECS.h"
|
|
|
|
|
#include "../components/HydraPointShadowSourceComponent.h"
|
|
|
|
|
#include "../components/HydraPositionComponent.h"
|
|
|
|
|
#include "../components/HydraLightComponent.h"
|
|
|
|
|
|
|
|
|
|
#include "../../buffer/HydraShadowBuffer.h"
|
|
|
|
|
#include "../../buffer/HydraTextureBufferManager.h"
|
|
|
|
|
#include "../../buffer/HydraShadowBufferManager.h"
|
|
|
|
|
|
|
|
|
|
#include "../../scheduler/HydraTaskScheduler.h"
|
|
|
|
|
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
|
|
|
|
#include "../../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
|
|
|
|
|
#include "../../task/buffer/HydraUpdatePartialGPUBufferTask.hpp"
|
|
|
|
|
#include "../../task/buffer/HydraCreateUnBoundTextureTask.hpp"
|
|
|
|
|
#include "../../task/renderer/HydraCreateCubemapShadowFrameBuffer.hpp"
|
|
|
|
|
#include "../../task/renderer/HydraCreateShadowFrameBuffer.hpp"
|
|
|
|
|
#include "../../actor/HydraActorManager.h"
|
|
|
|
|
|
|
|
|
|
void HydraPointShadowSourceSystem::Initialise()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraPointShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
|
|
|
|
{
|
|
|
|
|
HydraEngine *engine = GetEngine();
|
|
|
|
|
HydraECS *ecs = engine->ECS();
|
|
|
|
|
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
|
|
|
|
|
|
|
|
|
HydraPointShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
|
|
|
|
|
|
|
|
|
HydraID shadow_id = GetEngine()->ShadowBufferManager()->AddPointShadow(shadow_comp);
|
|
|
|
|
assert(shadow_id != INVALID_HYDRA_ID && "Add point Shadow - out of shadows!");
|
|
|
|
|
|
|
|
|
|
light_comp.shadow_map_id = shadow_id;
|
|
|
|
|
light_comp.shadow_caster = 1;
|
2026-08-18 16:23:20 +01:00
|
|
|
shadow_comp.entity_id = entity_id;
|
|
|
|
|
//shadow_comp.shadow_id = shadow_id;
|
|
|
|
|
//_InitialiseShadowMap(entity_id);
|
2026-08-16 13:47:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HydraPointShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
|
|
|
|
{
|
|
|
|
|
for (HydraID entity_id : Entities)
|
|
|
|
|
{
|
|
|
|
|
_UpdateShadowMap(entity_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 21:44:00 +01:00
|
|
|
void HydraPointShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
|
|
|
|
{
|
2026-08-18 16:23:20 +01:00
|
|
|
HydraEngine *engine = GetEngine();
|
2026-08-17 21:44:00 +01:00
|
|
|
HydraECS *ecs = engine->ECS();
|
|
|
|
|
HydraPointShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
|
|
|
|
GetEngine()->ShadowBufferManager()->DeletePointShadow(shadow_comp.shadow_id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-16 13:47:11 +01:00
|
|
|
void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
|
|
|
|
{
|
|
|
|
|
HydraEngine *engine = GetEngine();
|
|
|
|
|
HydraECS *ecs = engine->ECS();
|
|
|
|
|
HydraPositionComponent pos_comp = ecs->GetComponent<HydraPositionComponent>(entity_id);
|
|
|
|
|
HydraPointShadowSourceComponent &shad_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
|
|
|
|
|
|
|
|
|
float view_size = 4.0f;
|
|
|
|
|
float view_near = 0.1f;
|
|
|
|
|
float view_far = 100.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 camera_pos = GetEngine()->Camera()->GetPosition();
|
|
|
|
|
|
2026-08-17 14:12:11 +01:00
|
|
|
float aspect = (float)POINT_SHADOW_MAP_SIZE/(float)POINT_SHADOW_MAP_SIZE;
|
|
|
|
|
float width = POINT_SHADOW_MAP_SIZE;
|
2026-08-16 13:47:11 +01:00
|
|
|
float fov = glm::radians(90.0f);
|
|
|
|
|
|
|
|
|
|
glm::mat4 shadow_proj = glm::perspectiveFovLH<float>(fov, width, width, view_near, view_far);
|
|
|
|
|
//glm::mat4 shadow_proj = glm::perspective<float>(fov, 1.0f, view_near, view_far);
|
|
|
|
|
|
|
|
|
|
glm::vec3 light_pos = pos_comp.position;
|
|
|
|
|
|
|
|
|
|
//GL_TEXTURE_CUBE_MAP_POSITIVE_X - left
|
|
|
|
|
shad_comp.light_space_view[0] = glm::lookAt(light_pos, light_pos + glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
|
|
|
|
|
//GL_TEXTURE_CUBE_MAP_NEGATIVE_X - right
|
|
|
|
|
shad_comp.light_space_view[1] = glm::lookAt(light_pos, light_pos + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
|
|
|
|
|
//GL_TEXTURE_CUBE_MAP_POSITIVE_Y - Up
|
2026-08-18 16:23:20 +01:00
|
|
|
shad_comp.light_space_view[2] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, -1.0));
|
2026-08-16 13:47:11 +01:00
|
|
|
//GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - down
|
|
|
|
|
shad_comp.light_space_view[3] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, 1.0));
|
|
|
|
|
//GL_TEXTURE_CUBE_MAP_POSITIVE_Z - back
|
|
|
|
|
shad_comp.light_space_view[4] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0));
|
|
|
|
|
//GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - forward
|
|
|
|
|
shad_comp.light_space_view[5] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, 1.0, 0.0));
|
|
|
|
|
|
|
|
|
|
shad_comp.light_space_proj = shadow_proj;
|
|
|
|
|
shad_comp.far_plane = view_far;
|
|
|
|
|
GetEngine()->ShadowBufferManager()->UpdatePointShadow(shad_comp.shadow_id, shad_comp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void HydraPointShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
|
|
|
|
{
|
2026-08-18 16:23:20 +01:00
|
|
|
// HydraEngine *engine = GetEngine();
|
|
|
|
|
// HydraECS *ecs = engine->ECS();
|
|
|
|
|
// HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
|
|
|
|
// HydraPointShadowSourceComponent &shad_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
|
|
|
|
// HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
2026-08-16 13:47:11 +01:00
|
|
|
|
2026-08-18 16:23:20 +01:00
|
|
|
// shad_comp.entity_id = entity_id;
|
2026-08-16 13:47:11 +01:00
|
|
|
|
2026-08-18 16:23:20 +01:00
|
|
|
// HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
2026-08-16 13:47:11 +01:00
|
|
|
|
2026-08-18 16:23:20 +01:00
|
|
|
// uint32_t depth_texture_id = 0;
|
|
|
|
|
// HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCubemapShadowFrameBuffer>(HydraThreadAffinity::Render);
|
|
|
|
|
// HydraCreateCubemapShadowFrameBuffer *fb_task = static_cast<HydraCreateCubemapShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
|
|
|
|
// fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
2026-08-16 13:47:11 +01:00
|
|
|
|
2026-08-18 16:23:20 +01:00
|
|
|
// task_scheduler->WaitForTask(create_framebuffer_task_id);
|
|
|
|
|
// shad_comp.shadow_texture_id = depth_texture_id;
|
2026-08-16 13:47:11 +01:00
|
|
|
}
|
|
|
|
|
|