Name change, but backwards

This commit is contained in:
Confideo-IOM
2026-08-04 18:32:37 +01:00
parent 3e8b8952f7
commit 2b3785e6af
45 changed files with 1079 additions and 498 deletions
@@ -292,7 +292,7 @@ float SampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint
// calculate bias (based on depth map resolution and slope)
float bias = max(0.005 * (1.0 - dot(normal, light_dir)), 0.0001);
float bias = max(0.005 * (1.0 - dot(normal, light_dir)), 0.0005);
// check whether current frag pos is in shadow
@@ -8,7 +8,7 @@
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../ecs/components/HydraShadowSourceComponent.h"
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
#include "../buffer/HydraLightBufferManager.h"
#include "../buffer/HydraLightBuffer.h"
@@ -25,14 +25,15 @@ void HydraDirectionalLightActor::InitialiseComponents()
light_comp.intensity = 10000.0f;
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_DIRECTIONAL);
light_comp.entity_id = GetID();
light_comp.shadow_caster =1;
ecs->AddComponent<HydraLightComponent>(GetID(), light_comp);
HydraPositionComponent position_component = {};
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
HydraShadowSourceComponent shadow_component = {};
ecs->AddComponent<HydraShadowSourceComponent>(GetID(), shadow_component);
HydraDirectionalShadowSourceComponent shadow_component = {};
ecs->AddComponent<HydraDirectionalShadowSourceComponent>(GetID(), shadow_component);
}
void HydraDirectionalLightActor::Destroy()
@@ -8,7 +8,7 @@
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../ecs/components/HydraShadowSourceComponent.h"
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
#include "../buffer/HydraLightBufferManager.h"
#include "../buffer/HydraLightBuffer.h"
@@ -33,8 +33,8 @@ void HydraSpotLightActor::InitialiseComponents()
HydraPositionComponent position_component;
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
HydraShadowSourceComponent shadow_component = {};
ecs->AddComponent<HydraShadowSourceComponent>(GetID(), shadow_component);
HydraDirectionalShadowSourceComponent shadow_component = {};
ecs->AddComponent<HydraDirectionalShadowSourceComponent>(GetID(), shadow_component);
}
void HydraSpotLightActor::Destroy()
@@ -1,9 +1,9 @@
#ifndef HYDRASOURCECOMPONENT
#define HYDRASOURCECOMPONENT
#ifndef HYDRADIRECTIONALSHADOWSOURCECOMPONENT
#define HYDRADIRECTIONALSHADOWSOURCECOMPONENT
#include "../../engine/HydraEngine.h"
struct HydraShadowSourceComponent
struct HydraDirectionalShadowSourceComponent
{
uint32_t entity_id;
uint32_t cascade_count;
@@ -1,8 +1,8 @@
#include "HydraShadowSourceSystem.h"
#include "HydraDirectionalShadowSourceSystem.h"
#include "../../engine/HydraEngine.h"
#include "../../camera/HydraCamera.h"
#include "../HydraECS.h"
#include "../components/HydraShadowSourceComponent.h"
#include "../components/HydraDirectionalShadowSourceComponent.h"
#include "../components/HydraPositionComponent.h"
#include "../components/HydraLightComponent.h"
@@ -18,7 +18,7 @@
#include "../../task/renderer/HydraCreateShadowFrameBuffer.hpp"
#include "../../actor/HydraActorManager.h"
void HydraShadowSourceSystem::Initialise()
void HydraDirectionalShadowSourceSystem::Initialise()
{
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
@@ -31,11 +31,11 @@ void HydraShadowSourceSystem::Initialise()
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(HydraShadowSourceComponent), &m_shadow_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
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 HydraShadowSourceSystem::InitialiseComponent(HydraID entity_id)
void HydraDirectionalShadowSourceSystem::InitialiseComponent(HydraID entity_id)
{
HydraEngine *engine = GetEngine();
HydraECS *ecs = engine->ECS();
@@ -59,11 +59,11 @@ void HydraShadowSourceSystem::InitialiseComponent(HydraID entity_id)
}
void HydraShadowSourceSystem::UpdateSystem(float delta_t_seconds)
void HydraDirectionalShadowSourceSystem::UpdateSystem(float delta_t_seconds)
{
HydraEngine *engine = GetEngine();
HydraECS *ecs = engine->ECS();
std::vector<HydraShadowSourceComponent> shadows;
std::vector<HydraDirectionalShadowSourceComponent> shadows;
for (HydraID entity_id : Entities)
{
@@ -75,18 +75,18 @@ void HydraShadowSourceSystem::UpdateSystem(float delta_t_seconds)
break;
}
HydraShadowSourceComponent shad_comp = ecs->GetComponent<HydraShadowSourceComponent>(entity_id);
HydraDirectionalShadowSourceComponent shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
m_shadows[light_comp.shadow_map_id] = shad_comp;
}
_WriteToGPU();
}
void HydraShadowSourceSystem::_UpdateDirectionalLight(HydraID entity_id)
void HydraDirectionalShadowSourceSystem::_UpdateDirectionalLight(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);
HydraDirectionalShadowSourceComponent &shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
float view_size = 20.0f;
float view_near = -10.0f;
@@ -104,6 +104,7 @@ void HydraShadowSourceSystem::_UpdateDirectionalLight(HydraID entity_id)
light_dir = glm::normalize(light_dir);
glm::vec3 camera_pos = GetEngine()->Camera()->GetPosition();
float light_distance = 2;
for (uint32_t i = 0; i < 6; i++)
{
glm::vec3 light_pos = camera_pos - (light_dir * light_distance);
@@ -125,36 +126,18 @@ 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)
void HydraDirectionalShadowSourceSystem::_InitialiseDirectionalLight(HydraID entity_id)
{
HydraEngine *engine = GetEngine();
HydraECS *ecs = engine->ECS();
HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
HydraShadowSourceComponent &shad_comp = ecs->GetComponent<HydraShadowSourceComponent>(entity_id);
HydraDirectionalShadowSourceComponent &shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
light_comp.shadow_caster = 1;
shad_comp.entity_id = entity_id;
shad_comp.cascade_count = 6;
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
uint32_t depth_texture_id = 0;
@@ -165,26 +148,8 @@ void HydraShadowSourceSystem::_InitialiseDirectionalLight(HydraID entity_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()
void HydraDirectionalShadowSourceSystem::_WriteToGPU()
{
HydraEngine *engine = GetEngine();
HydraECS *ecs = engine->ECS();
@@ -1,14 +1,14 @@
#ifndef HYDRASHADOWSOURCESYSTEM
#define HYDRASHADOWSOURCESYSTEM
#ifndef HYDRADIRECTIONALSHADOWSOURCESYSTEM
#define HYDRADIRECTIONALSHADOWSOURCESYSTEM
#include "../../engine/HydraObject.h"
#include "../HydraSystem.h"
#include "../components/HydraShadowSourceComponent.h"
#include "../components/HydraDirectionalShadowSourceComponent.h"
#include <GLMIncludes.h>
#include <queue>
#include <vector>
#include <mutex>
class HydraShadowSourceSystem : public HydraSystem
class HydraDirectionalShadowSourceSystem : public HydraSystem
{
public:
virtual void Initialise() override;
@@ -17,13 +17,11 @@ 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;
std::vector<HydraShadowSourceComponent> m_shadows;
std::vector<HydraDirectionalShadowSourceComponent> m_shadows;
std::mutex m_mutex;
};
+6 -6
View File
@@ -20,14 +20,14 @@
#include "../ecs/systems/HydraRenderSystem.h"
#include "../ecs/systems/HydraMaterialSystem.h"
#include "../ecs/systems/HydraLightSystem.h"
#include "../ecs/systems/HydraShadowSourceSystem.h"
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
#include "../ecs/components/HydraPositionComponent.h"
#include "../ecs/components/HydraMeshComponent.h"
#include "../ecs/components/HydraRenderableComponent.h"
#include "../ecs/components/HydraTextureComponent.h"
#include "../ecs/components/HydraMaterialComponent.h"
#include "../ecs/components/HydraLightComponent.h"
#include "../ecs/components/HydraShadowSourceComponent.h"
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
#include "../camera/HydraCamera.h"
@@ -215,14 +215,14 @@ void HydraEngine::_InitialiseSystems()
m_ecs->RegisterComponentType<HydraTextureComponent>();
m_ecs->RegisterComponentType<HydraMaterialComponent>();
m_ecs->RegisterComponentType<HydraLightComponent>();
m_ecs->RegisterComponentType<HydraShadowSourceComponent>();
m_ecs->RegisterComponentType<HydraDirectionalShadowSourceComponent>();
m_mesh_system = m_ecs->RegisterSystem<HydraMeshSystem>();
m_transform_system = m_ecs->RegisterSystem<HydraTransformSystem>();
m_render_system = m_ecs->RegisterSystem<HydraRenderSystem>();
m_material_system = m_ecs->RegisterSystem<HydraMaterialSystem>();
m_light_system = m_ecs->RegisterSystem<HydraLightSystem>();
m_shadow_system = m_ecs->RegisterSystem<HydraShadowSourceSystem>();
m_shadow_system = m_ecs->RegisterSystem<HydraDirectionalShadowSourceSystem>();
HydraSignature mesh_sig;
HydraSignature trans_sig;
@@ -241,14 +241,14 @@ void HydraEngine::_InitialiseSystems()
shadow_sig.set(m_ecs->GetComponentType<HydraLightComponent>(), true);
shadow_sig.set(m_ecs->GetComponentType<HydraPositionComponent>(), true);
shadow_sig.set(m_ecs->GetComponentType<HydraShadowSourceComponent>(), true);
shadow_sig.set(m_ecs->GetComponentType<HydraDirectionalShadowSourceComponent>(), true);
m_ecs->SetSystemSignature<HydraMeshSystem>(mesh_sig);
m_ecs->SetSystemSignature<HydraTransformSystem>(trans_sig);
m_ecs->SetSystemSignature<HydraRenderSystem>(render_sig);
m_ecs->SetSystemSignature<HydraMaterialSystem>(material_sig);
m_ecs->SetSystemSignature<HydraLightSystem>(light_sig);
m_ecs->SetSystemSignature<HydraShadowSourceSystem>(shadow_sig);
m_ecs->SetSystemSignature<HydraDirectionalShadowSourceSystem>(shadow_sig);
}
+2 -2
View File
@@ -25,7 +25,7 @@ class HydraTextureBufferManager;
class HydraMaterialBufferManager;
class HydraLightBufferManager;
class HydraLightSystem;
class HydraShadowSourceSystem;
class HydraDirectionalShadowSourceSystem;
class CLASS_DEFINE HydraEngine : public HydraObject
{
@@ -93,7 +93,7 @@ private:
std::shared_ptr<HydraRenderSystem> m_render_system;
std::shared_ptr<HydraMaterialSystem> m_material_system;
std::shared_ptr<HydraLightSystem> m_light_system;
std::shared_ptr<HydraShadowSourceSystem> m_shadow_system;
std::shared_ptr<HydraDirectionalShadowSourceSystem> m_shadow_system;
bool m_running = true;
@@ -11,8 +11,8 @@
#include "../renderer/HydraRenderer.h"
#include "../ecs/HydraECS.h"
#include "../ecs/systems/HydraRenderSystem.h"
#include "../ecs/systems/HydraShadowSourceSystem.h"
#include "../ecs/components/HydraShadowSourceComponent.h"
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
#include "../mesh/StandardVertex.h"
#include "../actor/HydraActorManager.h"
#include "../actor/HydraOutputActor.h"
@@ -95,12 +95,12 @@ void HydraDeferredPipeline::_UpdateUBO()
buffer_manager->UpdateWholeBuffer(m_per_frame_output_ubo, &output_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, m_per_frame_output_ubo);
std::shared_ptr<HydraShadowSourceSystem> sys = GetEngine()->ECS()->GetSystem<HydraShadowSourceSystem>();
std::shared_ptr<HydraDirectionalShadowSourceSystem> sys = GetEngine()->ECS()->GetSystem<HydraDirectionalShadowSourceSystem>();
HydraID texture_id = 0;
if(sys->Entities.size() > 0)
{
auto it = sys->Entities.begin();
HydraShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraShadowSourceComponent>(*it);
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(*it);
texture_id = shad_comp.shadow_texture_id;
}
TextureDebugUBO texture_ubo = {};
@@ -163,7 +163,6 @@ void HydraDeferredPipeline::_CreateFrameBuffer()
tex_buffer_manager->BindTexture(normal_texture.texture_id, GL_TEXTURE_2D);
tex_buffer_manager->BindTexture(position_texture.texture_id, GL_TEXTURE_2D);
HydraBufferManager* buffer_manager = GetEngine()->BufferManager();
buffer_manager->UpdateWholeBuffer(m_output_texture_ubo, &actor->texture_buffers[0]);
glBindBuffer(GL_UNIFORM_BUFFER, m_output_texture_ubo);
@@ -11,7 +11,7 @@
#include "../renderer/HydraRenderer.h"
#include "../ecs/HydraECS.h"
#include "../ecs/systems/HydraRenderSystem.h"
#include "../ecs/systems/HydraShadowSourceSystem.h"
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
#include "../mesh/StandardVertex.h"
#include "../actor/HydraActorManager.h"
#include "../actor/HydraOutputActor.h"
@@ -30,7 +30,7 @@ void HydraShadowPipeline::Render()
{
HydraECS *ecs = GetEngine()->ECS();
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
std::shared_ptr<HydraShadowSourceSystem> shadow_system = ecs->GetSystem<HydraShadowSourceSystem>();
std::shared_ptr<HydraDirectionalShadowSourceSystem> shadow_system = ecs->GetSystem<HydraDirectionalShadowSourceSystem>();
uint32_t shadow_idx = 0;
glViewport(0, 0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
@@ -47,7 +47,7 @@ void HydraShadowPipeline::Render()
{
_UpdateUBO(shadow_idx);
// _BindFrameBufferAttachments(entity_id);
HydraShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraShadowSourceComponent>(entity_id);
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
// HydraTextureBuffer tex_buffer = GetEngine()->TextureBufferManager()->GetTexture(shad_comp.shadow_texture_id);
// glBindTextureUnit(tex_buffer.gl_tex_id, 0);
@@ -66,7 +66,6 @@ void HydraShadowPipeline::Render()
shadow_idx++;
}
// glDisable(GL_POLYGON_OFFSET_FILL);
}
@@ -133,7 +132,7 @@ void HydraShadowPipeline::_UpdateUBO(uint32_t shadow_idx)
void HydraShadowPipeline::_BindFrameBufferAttachments(HydraID entity_id)
{
HydraShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraShadowSourceComponent>(entity_id);
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
glBindFramebuffer(GL_FRAMEBUFFER, shad_comp.frame_buffer_id);
glBindTextureUnit(0, 0);
}