Spot works
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../../buffer/HydraShadowBuffer.h"
|
||||
#include "../../buffer/HydraTextureBufferManager.h"
|
||||
#include "../../buffer/HydraShadowBufferManager.h"
|
||||
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
@@ -20,19 +21,7 @@
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::Initialise()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
for(uint32_t i = 0; i < MAX_SHADOWS; i++)
|
||||
{
|
||||
m_available_shadows.push(i);
|
||||
}
|
||||
|
||||
m_shadows.resize(MAX_SHADOWS);
|
||||
|
||||
HydraID create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraCreateGPUBufferTask *task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
task->Intialise("ShadowBuffer", 1, MAX_SHADOWS * sizeof(HydraDirectionalShadowSourceComponent), &m_shadow_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
@@ -41,36 +30,25 @@ void HydraDirectionalShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
assert(m_available_shadows.size() > 0 && "Run out of shadows");
|
||||
uint32_t shad_id = m_available_shadows.front();
|
||||
m_available_shadows.pop();
|
||||
light_comp.shadow_map_id = shad_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
}
|
||||
|
||||
HydraDirectionalShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
|
||||
HydraID shadow_id = GetEngine()->ShadowBufferManager()->AddDirectionalShadow(shadow_comp);
|
||||
assert(shadow_id != INVALID_HYDRA_ID && "Add directional Shadow - out of shadows!");
|
||||
|
||||
light_comp.shadow_map_id = shadow_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
shadow_comp.shadow_id = shadow_id;
|
||||
_InitialiseShadowMap(entity_id);
|
||||
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
std::vector<HydraDirectionalShadowSourceComponent> shadows;
|
||||
for (HydraID entity_id : Entities)
|
||||
{
|
||||
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
_UpdateShadowMap(entity_id);
|
||||
|
||||
HydraDirectionalShadowSourceComponent shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
m_shadows[light_comp.shadow_map_id] = shad_comp;
|
||||
}
|
||||
_WriteToGPU();
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
@@ -113,6 +91,7 @@ void HydraDirectionalShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
view_size *= 3.0f;
|
||||
view_far *= 3.0f;
|
||||
}
|
||||
GetEngine()->ShadowBufferManager()->UpdateDirectionalShadow(shad_comp.shadow_id, shad_comp);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,8 +103,7 @@ void HydraDirectionalShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
HydraDirectionalShadowSourceComponent &shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
shad_comp.entity_id = entity_id;
|
||||
shad_comp.cascade_count = 6;
|
||||
shad_comp.entity_id = entity_id;
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
@@ -138,16 +116,3 @@ void HydraDirectionalShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::_WriteToGPU()
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
|
||||
void *buffer = static_cast<void *>(m_shadows.data());
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraUpdateWholeGPUBufferTask *task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_shadow_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
}
|
||||
Reference in New Issue
Block a user