Spot works
This commit is contained in:
@@ -41,7 +41,8 @@ const uint32_t MAX_MATERIALS = 1000;
|
||||
const uint32_t MAX_TEXTURES = 1000;
|
||||
const uint32_t MAX_ACTORS = 10000;
|
||||
const uint32_t MAX_LIGHTS = 500;
|
||||
const uint32_t MAX_SHADOWS = 10;
|
||||
const uint32_t MAX_DIRECTIONAL_SHADOWS = 10;
|
||||
const uint32_t MAX_SPOT_SHADOWS = 10;
|
||||
const uint32_t SHADOW_MAP_SIZE = 4096;
|
||||
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ struct LightStructure
|
||||
uint padding1;
|
||||
};
|
||||
|
||||
struct ShadowMapSet
|
||||
struct DirectionalShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint cascade_count;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float near_plane[8];
|
||||
@@ -47,6 +47,17 @@ struct ShadowMapSet
|
||||
mat4 light_space_view[6];
|
||||
};
|
||||
|
||||
struct SpotShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float far_plane;
|
||||
uint padding[3];
|
||||
mat4 light_space_proj;
|
||||
mat4 light_space_view;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform uniform_per_frame
|
||||
{
|
||||
@@ -76,12 +87,15 @@ layout (std430, binding = 4) readonly buffer light_buffer
|
||||
LightStructure lights[500];
|
||||
};
|
||||
|
||||
layout (std430, binding = 5) readonly buffer shadow_map_sets
|
||||
layout (std430, binding = 5) readonly buffer directional_shadow_map_sets
|
||||
{
|
||||
ShadowMapSet shadows[10];
|
||||
DirectionalShadowMapSet directional_shadows[];
|
||||
};
|
||||
|
||||
|
||||
layout (std430, binding = 6) readonly buffer spot_shadow_map_sets
|
||||
{
|
||||
SpotShadowMapSet spot_shadows[];
|
||||
};
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
@@ -235,28 +249,27 @@ vec3 SpotShading(vec3 normal,
|
||||
float light_linear,
|
||||
float light_quadratic,
|
||||
vec3 world_pos,
|
||||
vec3 view_pos)
|
||||
vec3 view_pos,
|
||||
float shadow_val)
|
||||
{
|
||||
|
||||
vec3 direction_to_light = normalize(light_pos - world_pos);
|
||||
float theta = dot(direction_to_light, light_dir);
|
||||
float falloff = 0.0f;
|
||||
// if(theta > cutoff)
|
||||
// {
|
||||
float epsilon = cutoff - cutoff_outer;
|
||||
falloff = clamp((theta - cutoff_outer) / epsilon, 0.0, 1.0);
|
||||
float epsilon = cutoff - cutoff_outer;
|
||||
|
||||
//}
|
||||
falloff = clamp((theta - cutoff_outer) / epsilon, 0.0, 1.0);
|
||||
|
||||
float distance = length(light_pos - world_pos);
|
||||
float attenuation = 1.0;
|
||||
|
||||
attenuation = light_intensity / (light_constant + (light_linear * distance) + (light_quadratic * distance * distance));
|
||||
vec3 radiance = diffuse * attenuation * falloff;
|
||||
|
||||
vec3 radiance = diffuse * attenuation * falloff * (1.0-shadow_val);
|
||||
|
||||
vec3 Lo = CalculatePBR(normal, view_pos, world_pos, direction_to_light, diffuse, radiance, roughness, metallic);
|
||||
|
||||
return Lo;
|
||||
return Lo;// * shadow;
|
||||
}
|
||||
|
||||
mat3 GetRotationOnlyMatrix(mat4 model_mat)
|
||||
@@ -284,7 +297,7 @@ float SimpleSampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map
|
||||
return 1;
|
||||
}
|
||||
|
||||
float SampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint shadow_trans_idx, vec3 normal, vec3 light_dir)
|
||||
float SampleCascadeShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint shadow_trans_idx, vec3 normal, vec3 light_dir)
|
||||
{
|
||||
vec3 frag_light_space = frag_clip_space.xyz / frag_clip_space.w;
|
||||
frag_light_space = (frag_light_space * 0.5) + 0.5;
|
||||
@@ -319,6 +332,41 @@ float SampleShadow(vec4 frag_clip_space, sampler2DArray sampler_shadow_map, uint
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
float SampleSingleShadow(vec4 frag_clip_space, sampler2D sampler_shadow_map, vec3 normal, vec3 light_dir)
|
||||
{
|
||||
vec3 frag_light_space = frag_clip_space.xyz / frag_clip_space.w;
|
||||
frag_light_space = (frag_light_space * 0.5) + 0.5;
|
||||
|
||||
float shadow_map_depth = texture(sampler_shadow_map, frag_light_space.xy).r;
|
||||
// calculate bias (based on depth map resolution and slope)
|
||||
|
||||
float bias = max(0.00005 * (1.0 - dot(normal, light_dir)), 0.000005);
|
||||
// check whether current frag pos is in shadow
|
||||
// float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||
// PCF
|
||||
//bias = 0;
|
||||
float shadow = 0.0;
|
||||
vec2 texel_size = 1.0 / textureSize(sampler_shadow_map, 0).xy;
|
||||
if((frag_light_space.x >= 0.0)&&(frag_light_space.y >= 0.0)
|
||||
&&(frag_light_space.x <= 1.0)&&(frag_light_space.y <= 1.0))
|
||||
{
|
||||
for(int x = -1; x <= 1; ++x)
|
||||
{
|
||||
for(int y = -1; y <= 1; ++y)
|
||||
{
|
||||
shadow_map_depth = texture(sampler_shadow_map, frag_light_space.xy + vec2(x, y) * texel_size).r;
|
||||
shadow += frag_light_space.z - bias > shadow_map_depth ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
shadow /= 9.0;
|
||||
}
|
||||
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
|
||||
if(frag_light_space.z > 1.0)
|
||||
shadow = 0.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
vec3 CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, vec3 light_dir, vec3 viewer_pos)
|
||||
{
|
||||
float shadow = 1;
|
||||
@@ -326,12 +374,12 @@ vec3 CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, ve
|
||||
//measure the distance of the fragment from the light
|
||||
float frag_distance = abs(length(viewer_pos - world_pos.xyz));
|
||||
|
||||
uint shadow_trans_idx = 6;
|
||||
uint shadow_trans_idx = 5;
|
||||
uint ignore_shadow = 0;
|
||||
//Work out which shadowmap is appropriate for this distance
|
||||
for(uint i = 0; i < 6; i++)
|
||||
{
|
||||
if(frag_distance <= shadows[shadow_idx].far_plane[i])
|
||||
if(frag_distance <= directional_shadows[shadow_idx].far_plane[i])
|
||||
{
|
||||
//record the shadow map level
|
||||
shadow_trans_idx = i;
|
||||
@@ -343,39 +391,30 @@ vec3 CalculateDirectionalShadow(vec4 world_pos, uint shadow_idx, vec3 normal, ve
|
||||
|
||||
if(ignore_shadow == 1)
|
||||
{
|
||||
vec4 translated_pixel = shadows[shadow_idx].light_space_proj[shadow_trans_idx] *
|
||||
shadows[shadow_idx].light_space_view[shadow_trans_idx] *
|
||||
vec4 translated_pixel = directional_shadows[shadow_idx].light_space_proj[shadow_trans_idx] *
|
||||
directional_shadows[shadow_idx].light_space_view[shadow_trans_idx] *
|
||||
world_pos;
|
||||
uvec2 shadow_handle = textures[shadows[shadow_idx].shadow_texture_id];
|
||||
shadow = 1.0 - SampleShadow(translated_pixel, sampler2DArray(shadow_handle), shadow_trans_idx, normal, light_dir);
|
||||
uvec2 shadow_handle = textures[directional_shadows[shadow_idx].shadow_texture_id];
|
||||
shadow = 1.0 - SampleCascadeShadow(translated_pixel, sampler2DArray(shadow_handle), shadow_trans_idx, normal, light_dir);
|
||||
}
|
||||
|
||||
return vec3(shadow);
|
||||
|
||||
if(shadow_trans_idx == 0)
|
||||
{
|
||||
return vec3(1,0,0) * shadow;
|
||||
}
|
||||
if(shadow_trans_idx == 1)
|
||||
{
|
||||
return vec3(1,1,0) * shadow;
|
||||
}
|
||||
if(shadow_trans_idx == 2)
|
||||
{
|
||||
return vec3(0.5,0.5,1) * shadow;
|
||||
}
|
||||
if(shadow_trans_idx == 3)
|
||||
{
|
||||
return vec3(1,0,1) * shadow;
|
||||
}
|
||||
if(shadow_trans_idx == 4)
|
||||
{
|
||||
return vec3(1,1,1) * shadow;
|
||||
}
|
||||
return vec3(0,1,1) * shadow;
|
||||
}
|
||||
float CalculateSpotShadow(vec4 world_pos, uint shadow_idx, vec3 normal, vec3 light_dir, vec3 viewer_pos)
|
||||
{
|
||||
|
||||
|
||||
vec4 translated_pixel = spot_shadows[shadow_idx].light_space_proj *
|
||||
spot_shadows[shadow_idx].light_space_view *
|
||||
world_pos;
|
||||
|
||||
uvec2 shadow_handle = textures[spot_shadows[shadow_idx].shadow_texture_id];
|
||||
|
||||
float shadow =(SampleSingleShadow(translated_pixel, sampler2D(shadow_handle), normal, light_dir));
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
uvec2 diffuse_handle = textures[texture_ids[DIFFUSE_TEXTURE_ID]];
|
||||
@@ -431,6 +470,16 @@ void main()
|
||||
}
|
||||
else if(lights[i].light_type == HYDRA_LIGHT_SPOT)
|
||||
{
|
||||
float shadow = 0;
|
||||
if(lights[i].shadow_caster == 1)
|
||||
{
|
||||
float distance = length(light_pos - world_pos);
|
||||
shadow = CalculateSpotShadow(vec4(world_pos, 1.0),
|
||||
lights[i].shadow_map_id,
|
||||
normal,
|
||||
light_direction,
|
||||
ubo_per_frame.viewer_pos);
|
||||
}
|
||||
Lo += SpotShading(normal,
|
||||
diffuse.xyz,
|
||||
rough,
|
||||
@@ -444,16 +493,15 @@ void main()
|
||||
lights[i].linear,
|
||||
lights[i].quadratic,
|
||||
world_pos,
|
||||
ubo_per_frame.viewer_pos);
|
||||
ubo_per_frame.viewer_pos,
|
||||
shadow);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float lighting = 0;
|
||||
// ambient lighting (note that the next IBL tutorial will replace
|
||||
// this ambient lighting with environment lighting).
|
||||
|
||||
|
||||
vec3 output_color = Lo;
|
||||
|
||||
// HDR tonemapping
|
||||
|
||||
@@ -59,8 +59,5 @@ void main()
|
||||
discard;
|
||||
output_colour = vec4(0,1,1,1);
|
||||
}
|
||||
// Calculate the accurate, unclamped distance from the light source
|
||||
// output_colour = diffuse_val;
|
||||
// output_colour = vec4(geom_out.vsUV, 1,1);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
layout(triangles, invocations = 6) in;
|
||||
layout(triangle_strip, max_vertices = 3) out;
|
||||
|
||||
struct ShadowMapSet
|
||||
struct DirectionalShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint cascade_count;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float near_plane[8];
|
||||
@@ -14,7 +14,8 @@ struct ShadowMapSet
|
||||
mat4 light_space_proj[6];
|
||||
mat4 light_space_view[6];
|
||||
};
|
||||
|
||||
|
||||
|
||||
//Push constants updated for each light
|
||||
layout(binding = 0) uniform shadow_per_frame
|
||||
{
|
||||
@@ -22,12 +23,13 @@ layout(binding = 0) uniform shadow_per_frame
|
||||
uint shadow_idxs;
|
||||
};
|
||||
|
||||
layout(std430, binding = 5) readonly buffer shadow_map_sets
|
||||
layout (std430, binding = 5) readonly buffer directional_shadow_map_sets
|
||||
{
|
||||
ShadowMapSet shadows[10];
|
||||
DirectionalShadowMapSet directional_shadows[];
|
||||
};
|
||||
|
||||
|
||||
|
||||
layout (location=0) in VS_OUT
|
||||
{
|
||||
vec2 vsUV;
|
||||
@@ -42,8 +44,8 @@ layout (location=0) out GEOM_OUT
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 view = shadows[shadow_idxs].light_space_view[gl_InvocationID];
|
||||
mat4 proj = shadows[shadow_idxs].light_space_proj[gl_InvocationID];
|
||||
mat4 view = directional_shadows[shadow_idxs].light_space_view[gl_InvocationID];
|
||||
mat4 proj = directional_shadows[shadow_idxs].light_space_proj[gl_InvocationID];
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,37 @@
|
||||
//*VERTEX*
|
||||
#version 460
|
||||
|
||||
struct ShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float near_plane[8];
|
||||
float far_plane[8];
|
||||
mat4 light_space_proj[6];
|
||||
mat4 light_space_view[6];
|
||||
};
|
||||
|
||||
struct SpotShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float far_plane;
|
||||
uint padding[3];
|
||||
mat4 light_space_proj;
|
||||
mat4 light_space_view;
|
||||
};
|
||||
|
||||
layout(binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
|
||||
|
||||
layout (location = 0) in vec3 inPos; //12 bytes : 0
|
||||
layout (location = 1) in vec2 inUV; //8 Bytes : 12
|
||||
layout (location = 2) in uvec3 inChunkID; //12 Bytes : 20
|
||||
|
||||
@@ -2,11 +2,34 @@
|
||||
#version 460
|
||||
|
||||
|
||||
struct SpotShadowMapSet
|
||||
{
|
||||
uint entity_id;
|
||||
uint shadow_id;
|
||||
uint shadow_texture_id;
|
||||
uint frame_buffer_id;
|
||||
float far_plane;
|
||||
uint padding[3];
|
||||
mat4 light_space_proj;
|
||||
mat4 light_space_view;
|
||||
};
|
||||
|
||||
layout(binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
mat4 model_matrix[];
|
||||
};
|
||||
|
||||
layout (std430, binding = 6) readonly buffer spot_shadow_map_sets
|
||||
{
|
||||
SpotShadowMapSet spot_shadows[];
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform shadow_per_frame
|
||||
{
|
||||
vec3 camera_pos;
|
||||
uint shadow_idxs;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec3 inPos; //12 bytes : 0
|
||||
layout (location = 1) in vec2 inUV; //8 Bytes : 12
|
||||
layout (location = 2) in uvec3 inChunkID; //12 Bytes : 20
|
||||
@@ -24,7 +47,11 @@ void main()
|
||||
{
|
||||
uint chunkid = inChunkID[0];
|
||||
mat4 model = model_matrix[chunkid];
|
||||
gl_Position = model * vec4(inPos, 1.0);
|
||||
mat4 proj = spot_shadows[shadow_idxs].light_space_proj;
|
||||
mat4 view = spot_shadows[shadow_idxs].light_space_view;
|
||||
//view = mat4(1);
|
||||
//proj = mat4(1);
|
||||
gl_Position = proj * view * model * vec4(inPos, 1.0);
|
||||
vs_out.vsUV = inUV;
|
||||
vs_out.vsMaterialID = inChunkID[1];
|
||||
}
|
||||
@@ -21,7 +21,7 @@ void HydraPointLightActor::InitialiseComponents()
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
light_comp.diffuse = glm::vec4(1,1,1,1);
|
||||
light_comp.intensity = 100.0f;
|
||||
light_comp.intensity = 1000.0f;
|
||||
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_POINT);
|
||||
light_comp.entity_id = GetID();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ void HydraSpotLightActor::InitialiseComponents()
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
light_comp.diffuse = glm::vec4(1,1,1,1);
|
||||
light_comp.intensity = 1000.0f;
|
||||
light_comp.intensity = 10000.0f;
|
||||
light_comp.light_type = static_cast<uint32_t>(HYDRA_LIGHT_TYPE::HYDRA_LIGHT_SPOT);
|
||||
light_comp.cutoff = glm::cos(glm::radians(10.0f));
|
||||
light_comp.cutoff_outer = glm::cos(glm::radians(25.0f));
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
|
||||
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
|
||||
#include "../ecs/components/HydraSpotShadowSourceComponent.h"
|
||||
|
||||
struct HydraShadowBuffer
|
||||
{
|
||||
uint32_t entity_id;
|
||||
uint32_t cascade_count;
|
||||
uint32_t shadow_texture_id;
|
||||
uint32_t padding0;
|
||||
float near_plane[8];
|
||||
float far_plane[8];
|
||||
glm::mat4 light_space_proj[6];
|
||||
glm::mat4 light_space_view[6];
|
||||
HydraDirectionalShadowSourceComponent directional_shadows[MAX_DIRECTIONAL_SHADOWS];
|
||||
HydraSpotShadowSourceComponent spot_shadows[MAX_SPOT_SHADOWS];
|
||||
};
|
||||
#endif /* HYDRASHADOWBUFFER */
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "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/HydraCreateCascadeShadowFrameBuffer.hpp"
|
||||
#include "../task/renderer/HydraCreateShadowFrameBuffer.hpp"
|
||||
|
||||
void HydraShadowBufferManager::Initialise()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
for(uint32_t i = 0; i < MAX_DIRECTIONAL_SHADOWS; i++)
|
||||
{
|
||||
m_available_dir.push(i);
|
||||
}
|
||||
for(uint32_t i = 0; i < MAX_SPOT_SHADOWS; i++)
|
||||
{
|
||||
m_available_spot.push(i);
|
||||
}
|
||||
m_directional_shadow_buffer.resize(MAX_DIRECTIONAL_SHADOWS);
|
||||
m_spot_shadow_buffer.resize(MAX_SPOT_SHADOWS);
|
||||
|
||||
|
||||
uint32_t buffer_size = (MAX_DIRECTIONAL_SHADOWS * sizeof(HydraDirectionalShadowSourceComponent));
|
||||
|
||||
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("DirectionalShadowBuffer", 1, buffer_size, &m_directional_shadow_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
|
||||
buffer_size = (MAX_SPOT_SHADOWS * sizeof(HydraSpotShadowSourceComponent));
|
||||
|
||||
create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraCreateGPUBufferTask *spot_task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
|
||||
spot_task->Intialise("SpotShadowBuffer", 1, buffer_size, &m_spot_shadow_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
}
|
||||
void HydraShadowBufferManager::Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
HydraID HydraShadowBufferManager::AddDirectionalShadow(HydraDirectionalShadowSourceComponent shadow)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(m_available_dir.size() == 0)
|
||||
{
|
||||
return INVALID_HYDRA_ID;
|
||||
}
|
||||
|
||||
HydraID shadow_id = m_available_dir.front();
|
||||
shadow.shadow_id = shadow_id;
|
||||
m_directional_shadow_buffer[shadow_id] = shadow;
|
||||
return shadow_id;
|
||||
}
|
||||
HydraID HydraShadowBufferManager::AddSpotShadow(HydraSpotShadowSourceComponent shadow)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(m_available_spot.size() == 0)
|
||||
{
|
||||
return INVALID_HYDRA_ID;
|
||||
}
|
||||
|
||||
HydraID shadow_id = m_available_spot.front();
|
||||
m_spot_shadow_buffer[shadow_id] = shadow;
|
||||
return shadow_id;
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::UpdateDirectionalShadow(HydraID shadow_id, HydraDirectionalShadowSourceComponent shadow)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(shadow_id < MAX_DIRECTIONAL_SHADOWS)
|
||||
{
|
||||
m_directional_shadow_buffer[shadow_id] = shadow;
|
||||
}
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::UpdateSpotShadow(HydraID shadow_id, HydraSpotShadowSourceComponent shadow)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(shadow_id < MAX_SPOT_SHADOWS)
|
||||
{
|
||||
m_spot_shadow_buffer[shadow_id] = shadow;
|
||||
}
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::RemoveDirectionalShadow(HydraID shadow_id)
|
||||
{
|
||||
|
||||
}
|
||||
void HydraShadowBufferManager::RemoveSpotShadow(HydraID shadow_id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::UpdateShadowBuffer()
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
void *buffer = static_cast<void *>(m_directional_shadow_buffer.data());
|
||||
|
||||
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_directional_shadow_buffer_id, buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
|
||||
void *spot_buffer = static_cast<void *>(m_spot_shadow_buffer.data());
|
||||
|
||||
update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraUpdateWholeGPUBufferTask *spot_task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
spot_task->Intialise(m_spot_shadow_buffer_id, spot_buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef HYDRASHADOWBUFFERMANAGER
|
||||
#define HYDRASHADOWBUFFERMANAGER
|
||||
|
||||
#include "../engine/HydraObject.h"
|
||||
#include "HydraShadowBuffer.h"
|
||||
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
|
||||
#include "../ecs/components/HydraSpotShadowSourceComponent.h"
|
||||
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
class HydraShadowBufferManager : public HydraObject
|
||||
{
|
||||
public:
|
||||
void Initialise();
|
||||
void Shutdown();
|
||||
HydraID AddDirectionalShadow(HydraDirectionalShadowSourceComponent shadow);
|
||||
HydraID AddSpotShadow(HydraSpotShadowSourceComponent shadow);
|
||||
void UpdateDirectionalShadow(HydraID shadow_id, HydraDirectionalShadowSourceComponent shadow);
|
||||
void UpdateSpotShadow(HydraID shadow_id, HydraSpotShadowSourceComponent shadow);
|
||||
void RemoveDirectionalShadow(HydraID shadow_id);
|
||||
void RemoveSpotShadow(HydraID shadow_id);
|
||||
void UpdateShadowBuffer();
|
||||
private:
|
||||
std::vector<HydraDirectionalShadowSourceComponent> m_directional_shadow_buffer;
|
||||
std::vector<HydraSpotShadowSourceComponent> m_spot_shadow_buffer;
|
||||
std::queue<HydraID> m_available_dir;
|
||||
std::queue<HydraID> m_available_spot;
|
||||
uint32_t m_directional_shadow_buffer_id;
|
||||
uint32_t m_spot_shadow_buffer_id;
|
||||
std::mutex m_mutex;
|
||||
|
||||
};
|
||||
#endif /* HYDRASHADOWBUFFERMANAGER */
|
||||
@@ -6,13 +6,13 @@
|
||||
struct HydraDirectionalShadowSourceComponent
|
||||
{
|
||||
uint32_t entity_id;
|
||||
uint32_t cascade_count;
|
||||
uint32_t shadow_id;
|
||||
uint32_t shadow_texture_id;
|
||||
uint32_t frame_buffer_id;
|
||||
float near_plane[8];
|
||||
float far_plane[8];
|
||||
glm::mat4 light_space_proj[6];
|
||||
glm::mat4 light_space_view[6];
|
||||
alignas(16) glm::mat4 light_space_proj[6];
|
||||
alignas(16) glm::mat4 light_space_view[6];
|
||||
};
|
||||
|
||||
#endif /* HYDRACASTERCOMPONENT */
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
struct HydraSpotShadowSourceComponent
|
||||
{
|
||||
uint32_t entity_id;
|
||||
uint32_t shadow_id;
|
||||
uint32_t shadow_texture_id;
|
||||
uint32_t frame_buffer_id;
|
||||
float far_plane;
|
||||
glm::mat4 light_space_proj;
|
||||
glm::mat4 light_space_view;
|
||||
uint32_t padding[3];
|
||||
alignas(16) glm::mat4 light_space_proj;
|
||||
alignas(16) glm::mat4 light_space_view;
|
||||
};
|
||||
|
||||
#endif /* HYDRASPOTSHADOWCOMPONENT */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -18,10 +18,6 @@ class HydraDirectionalShadowSourceSystem : public HydraSystem
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
void _WriteToGPU();
|
||||
HydraID m_shadow_buffer_id = INVALID_HYDRA_ID;
|
||||
std::queue<HydraID> m_available_shadows;
|
||||
std::vector<HydraDirectionalShadowSourceComponent> m_shadows;
|
||||
std::mutex m_mutex;
|
||||
|
||||
};
|
||||
|
||||
@@ -8,31 +8,21 @@
|
||||
|
||||
#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/HydraCreateCascadeShadowFrameBuffer.hpp"
|
||||
#include "../../task/renderer/HydraCreateShadowFrameBuffer.hpp"
|
||||
#include "../../actor/HydraActorManager.h"
|
||||
|
||||
void HydraSpotShadowSourceSystem::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(HydraSpotShadowSourceComponent), &m_shadow_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraSpotShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
@@ -41,14 +31,15 @@ void HydraSpotShadowSourceSystem::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;
|
||||
}
|
||||
|
||||
HydraSpotShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
|
||||
HydraID shadow_id = GetEngine()->ShadowBufferManager()->AddSpotShadow(shadow_comp);
|
||||
assert(shadow_id != INVALID_HYDRA_ID && "Add Spot 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);
|
||||
|
||||
}
|
||||
@@ -60,15 +51,9 @@ void HydraSpotShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
|
||||
for (HydraID entity_id : Entities)
|
||||
{
|
||||
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
_UpdateShadowMap(entity_id);
|
||||
|
||||
HydraSpotShadowSourceComponent shad_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
m_shadows[light_comp.shadow_map_id] = shad_comp;
|
||||
}
|
||||
_WriteToGPU();
|
||||
|
||||
}
|
||||
|
||||
void HydraSpotShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
@@ -77,20 +62,16 @@ void HydraSpotShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraPositionComponent pos_comp = ecs->GetComponent<HydraPositionComponent>(entity_id);
|
||||
HydraSpotShadowSourceComponent &shad_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
float view_size = 50.0f;
|
||||
float view_near = 0.1f;
|
||||
float view_near = 0.3f;
|
||||
float view_far = 50.0f;
|
||||
|
||||
float PI = 3.1415927;
|
||||
float TWO_PI = 6.2831854;
|
||||
|
||||
glm::mat4 light_rot = glm::eulerAngleXYZ(pos_comp.orientation.x, pos_comp.orientation.y, pos_comp.orientation.z);
|
||||
glm::vec3 light_dir = glm::normalize(glm::vec3(light_rot * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f)));
|
||||
|
||||
glm::vec3 camera_pos = GetEngine()->Camera()->GetPosition();
|
||||
|
||||
glm::vec3 light_pos = pos_comp.position;
|
||||
glm::vec3 light_pos = pos_comp.position;
|
||||
glm::vec3 target_pos = light_pos + light_dir;
|
||||
glm::vec3 up_vector = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
@@ -100,12 +81,15 @@ void HydraSpotShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
}
|
||||
|
||||
glm::mat4 view = glm::lookAt(light_pos, target_pos, up_vector);
|
||||
glm::mat4 proj = glm::ortho(-view_size, view_size, -view_size, view_size, view_near, view_far);
|
||||
|
||||
float fovRad = glm::radians(55.0f);
|
||||
glm::mat4 proj = glm::perspectiveFovRH<float>(fovRad, view_size, view_size, view_near, view_far);
|
||||
|
||||
// Save data to component
|
||||
shad_comp.far_plane = view_far;
|
||||
shad_comp.light_space_proj = proj;
|
||||
shad_comp.light_space_view = view;
|
||||
shad_comp.light_space_view = view;
|
||||
GetEngine()->ShadowBufferManager()->UpdateSpotShadow(shad_comp.shadow_id, shad_comp);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,11 +100,9 @@ void HydraSpotShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
HydraSpotShadowSourceComponent &shad_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
|
||||
shad_comp.entity_id = entity_id;
|
||||
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
uint32_t depth_texture_id = 0;
|
||||
@@ -132,16 +114,3 @@ void HydraSpotShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
void HydraSpotShadowSourceSystem::_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);
|
||||
}
|
||||
@@ -20,10 +20,10 @@ class HydraSpotShadowSourceSystem : public HydraSystem
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
void _WriteToGPU();
|
||||
HydraID m_shadow_buffer_id = INVALID_HYDRA_ID;
|
||||
std::queue<HydraID> m_available_shadows;
|
||||
std::vector<HydraSpotShadowSourceComponent> m_shadows;
|
||||
|
||||
|
||||
|
||||
|
||||
std::mutex m_mutex;
|
||||
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../buffer/HydraTextureBufferManager.h"
|
||||
#include "../buffer/HydraMaterialBufferManager.h"
|
||||
#include "../buffer/HydraLightBufferManager.h"
|
||||
#include "../buffer/HydraShadowBufferManager.h"
|
||||
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/systems/HydraTransformSystem.h"
|
||||
@@ -54,6 +55,7 @@
|
||||
#include "../task/ecs/HydraInitialiseComponentsTask.hpp"
|
||||
#include "../task/buffer/HydraShutdownBufferManagerTask.hpp"
|
||||
#include "../task/buffer/HydraInitialiseTextureManagerTask.hpp"
|
||||
#include "../task/buffer/HydraInitialiseShadowBufferTask.hpp"
|
||||
#include "../task/actor/HydraUpdatePlayerTask.h"
|
||||
|
||||
#include "../task/renderer/HydraEndRenderTask.hpp"
|
||||
@@ -149,6 +151,11 @@ HydraLightBufferManager *const HydraEngine::LightBufferManager()
|
||||
return m_light_buffer_manager;
|
||||
}
|
||||
|
||||
HydraShadowBufferManager *const HydraEngine::ShadowBufferManager()
|
||||
{
|
||||
return m_shadow_buffer_manager;
|
||||
}
|
||||
|
||||
void HydraEngine::PossessPlayer(HydraID actor_id)
|
||||
{
|
||||
m_possessed_actor_id = actor_id;
|
||||
@@ -187,6 +194,7 @@ void HydraEngine::_CreateManagers()
|
||||
m_texture_buffer_manager = new HydraTextureBufferManager();
|
||||
m_material_buffer_manager = new HydraMaterialBufferManager();
|
||||
m_light_buffer_manager = new HydraLightBufferManager();
|
||||
m_shadow_buffer_manager = new HydraShadowBufferManager();
|
||||
}
|
||||
|
||||
void HydraEngine::_InitialiseManagers()
|
||||
@@ -208,6 +216,9 @@ void HydraEngine::_InitialiseManagers()
|
||||
m_material_buffer_manager->Intialise();
|
||||
m_light_buffer_manager->Initialise();
|
||||
|
||||
HydraID create_shadow_buffer_task_id = m_task_scheduler->CreateTask<HydraInitialiseShadowBufferTask>(HydraThreadAffinity::Render);
|
||||
m_task_scheduler->WaitForTask(create_shadow_buffer_task_id);
|
||||
|
||||
}
|
||||
|
||||
void HydraEngine::_InitialiseSystems()
|
||||
@@ -277,7 +288,6 @@ void HydraEngine::_InitialiseSystems()
|
||||
|
||||
m_task_scheduler->StartTask(update_trans_id);
|
||||
m_task_scheduler->StartTask(update_mat_id);
|
||||
|
||||
m_task_scheduler->WaitForBarrier(posUpdateBarrierID);
|
||||
|
||||
HydraID update_light_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General);
|
||||
@@ -285,16 +295,22 @@ void HydraEngine::_InitialiseSystems()
|
||||
update_light_task->Initialise(m_delta_t, m_light_system);
|
||||
m_task_scheduler->WaitForTask(update_light_id);
|
||||
|
||||
HydraID update_shadow_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General);
|
||||
HydraID shadow_barrier = m_task_scheduler->CreateBarrier();
|
||||
|
||||
HydraID update_shadow_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General, shadow_barrier);
|
||||
HydraUpdateSystemTask* update_shadow_task = static_cast<HydraUpdateSystemTask*>(m_task_scheduler->GetTask(update_shadow_id));
|
||||
update_shadow_task->Initialise(m_delta_t, m_directional_shadow_system);
|
||||
m_task_scheduler->WaitForTask(update_shadow_id);
|
||||
|
||||
|
||||
HydraID update_spot_shadow_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General);
|
||||
HydraID update_spot_shadow_id = m_task_scheduler->CreateTask<HydraUpdateSystemTask>(HydraThreadAffinity::General, shadow_barrier);
|
||||
HydraUpdateSystemTask* update_spot_shadow_task = static_cast<HydraUpdateSystemTask*>(m_task_scheduler->GetTask(update_spot_shadow_id));
|
||||
update_spot_shadow_task->Initialise(m_delta_t, m_spot_shadow_system);
|
||||
m_task_scheduler->WaitForTask(update_spot_shadow_id);
|
||||
|
||||
m_task_scheduler->StartTask(update_shadow_id);
|
||||
m_task_scheduler->StartTask(update_spot_shadow_id);
|
||||
m_task_scheduler->WaitForBarrier(shadow_barrier);
|
||||
|
||||
m_shadow_buffer_manager->UpdateShadowBuffer();
|
||||
}
|
||||
|
||||
void HydraEngine::_GameLoop()
|
||||
|
||||
@@ -27,6 +27,7 @@ class HydraLightBufferManager;
|
||||
class HydraLightSystem;
|
||||
class HydraDirectionalShadowSourceSystem;
|
||||
class HydraSpotShadowSourceSystem;
|
||||
class HydraShadowBufferManager;
|
||||
|
||||
class CLASS_DEFINE HydraEngine : public HydraObject
|
||||
{
|
||||
@@ -58,6 +59,7 @@ public:
|
||||
HydraTextureBufferManager* const TextureBufferManager();
|
||||
HydraMaterialBufferManager* const MaterialBufferManager();
|
||||
HydraLightBufferManager* const LightBufferManager();
|
||||
HydraShadowBufferManager* const ShadowBufferManager();
|
||||
void PossessPlayer(HydraID actor_id);
|
||||
HydraID GetPossessedPlayer();
|
||||
float GetDeltaT();
|
||||
@@ -88,7 +90,7 @@ private:
|
||||
HydraTextureBufferManager* m_texture_buffer_manager = nullptr;
|
||||
HydraMaterialBufferManager* m_material_buffer_manager = nullptr;
|
||||
HydraLightBufferManager* m_light_buffer_manager = nullptr;
|
||||
|
||||
HydraShadowBufferManager* m_shadow_buffer_manager = nullptr;
|
||||
std::shared_ptr<HydraMeshSystem> m_mesh_system;
|
||||
std::shared_ptr<HydraTransformSystem> m_transform_system;
|
||||
std::shared_ptr<HydraRenderSystem> m_render_system;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "../ecs/systems/HydraRenderSystem.h"
|
||||
#include "../ecs/systems/HydraDirectionalShadowSourceSystem.h"
|
||||
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
|
||||
#include "../ecs/systems/HydraSpotShadowSourceSystem.h"
|
||||
#include "../ecs/components/HydraSpotShadowSourceComponent.h"
|
||||
#include "../mesh/StandardVertex.h"
|
||||
#include "../actor/HydraActorManager.h"
|
||||
#include "../actor/HydraOutputActor.h"
|
||||
@@ -95,12 +97,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<HydraDirectionalShadowSourceSystem> sys = GetEngine()->ECS()->GetSystem<HydraDirectionalShadowSourceSystem>();
|
||||
std::shared_ptr<HydraSpotShadowSourceSystem> sys = GetEngine()->ECS()->GetSystem<HydraSpotShadowSourceSystem>();
|
||||
HydraID texture_id = 0;
|
||||
if(sys->Entities.size() > 0)
|
||||
{
|
||||
auto it = sys->Entities.begin();
|
||||
HydraDirectionalShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraDirectionalShadowSourceComponent>(*it);
|
||||
HydraSpotShadowSourceComponent shad_comp = GetEngine()->ECS()->GetComponent<HydraSpotShadowSourceComponent>(*it);
|
||||
texture_id = shad_comp.shadow_texture_id;
|
||||
}
|
||||
TextureDebugUBO texture_ubo = {};
|
||||
@@ -233,6 +235,8 @@ void HydraDeferredPipeline::_CreateOutputRenderStage()
|
||||
HydraID tex_buffer_id = buffer_manager->FindBuffer("TextureBuffer");
|
||||
HydraID output_texture_buffer_id = buffer_manager->FindBuffer("DeferredOutputTextureUBO");
|
||||
HydraID light_buffer_id = buffer_manager->FindBuffer("LightBuffer");
|
||||
HydraID directional_shadow_buffer_id = buffer_manager->FindBuffer("DirectionalShadowBuffer");
|
||||
HydraID spot_shadow_buffer_id = buffer_manager->FindBuffer("SpotShadowBuffer");
|
||||
|
||||
HydraShaderBinding shader_binding = {};
|
||||
shader_binding.block_name.push_back("position_buffer");
|
||||
@@ -240,7 +244,6 @@ void HydraDeferredPipeline::_CreateOutputRenderStage()
|
||||
shader_binding.buffer_id.push_back(pos_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
|
||||
shader_binding.block_name.push_back("texture_buffer");
|
||||
shader_binding.binding_point.push_back(3);
|
||||
shader_binding.buffer_id.push_back(tex_buffer_id);
|
||||
@@ -260,7 +263,17 @@ void HydraDeferredPipeline::_CreateOutputRenderStage()
|
||||
shader_binding.binding_point.push_back(4);
|
||||
shader_binding.buffer_id.push_back(light_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
shader_binding.block_name.push_back("directional_shadow_buffer");
|
||||
shader_binding.binding_point.push_back(5);
|
||||
shader_binding.buffer_id.push_back(directional_shadow_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
shader_binding.block_name.push_back("spot_shadow_buffer");
|
||||
shader_binding.binding_point.push_back(6);
|
||||
shader_binding.buffer_id.push_back(spot_shadow_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
render_stage->Initialise(shader_path + "deferred_output_shader.vert",
|
||||
shader_path + "deferred_output_shader.frag", "",
|
||||
shader_binding,
|
||||
|
||||
@@ -85,7 +85,7 @@ void HydraShadowPipeline::_RenderSpotShadowMaps()
|
||||
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_DEPTH, 0, &depth_value);
|
||||
glClearNamedFramebufferfv(shad_comp.frame_buffer_id, GL_COLOR, 0, clear_colour);
|
||||
m_render_stages[SPOT_RENDER_STAGE]->Render(render_system->Entities, INVALID_HYDRA_ID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ void HydraShadowPipeline::_CreateDirectionalRenderStage()
|
||||
HydraID pos_buffer_id = buffer_manager->FindBuffer("PositionsBuffer");
|
||||
HydraID mat_buffer_id = buffer_manager->FindBuffer("MaterialBuffer");
|
||||
HydraID tex_buffer_id = buffer_manager->FindBuffer("TextureBuffer");
|
||||
HydraID shadow_buffer_id = buffer_manager->FindBuffer("ShadowBuffer");
|
||||
HydraID shadow_buffer_id = buffer_manager->FindBuffer("DirectionalShadowBuffer");
|
||||
HydraID per_frame_buffer_id = buffer_manager->FindBuffer("ShadowPerFrameUBO");
|
||||
|
||||
HydraShaderBinding shader_binding = {};
|
||||
@@ -118,7 +118,7 @@ void HydraShadowPipeline::_CreateDirectionalRenderStage()
|
||||
shader_binding.buffer_id.push_back(tex_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
shader_binding.block_name.push_back("shadow_map_sets");
|
||||
shader_binding.block_name.push_back("directional_shadow_map_sets");
|
||||
shader_binding.binding_point.push_back(5);
|
||||
shader_binding.buffer_id.push_back(shadow_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
@@ -152,7 +152,7 @@ void HydraShadowPipeline::_CreateSpotRenderStage()
|
||||
HydraID pos_buffer_id = buffer_manager->FindBuffer("PositionsBuffer");
|
||||
HydraID mat_buffer_id = buffer_manager->FindBuffer("MaterialBuffer");
|
||||
HydraID tex_buffer_id = buffer_manager->FindBuffer("TextureBuffer");
|
||||
HydraID shadow_buffer_id = buffer_manager->FindBuffer("ShadowBuffer");
|
||||
HydraID shadow_buffer_id = buffer_manager->FindBuffer("SpotShadowBuffer");
|
||||
HydraID per_frame_buffer_id = buffer_manager->FindBuffer("ShadowPerFrameUBO");
|
||||
|
||||
HydraShaderBinding shader_binding = {};
|
||||
@@ -172,8 +172,8 @@ void HydraShadowPipeline::_CreateSpotRenderStage()
|
||||
shader_binding.buffer_id.push_back(tex_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
shader_binding.block_name.push_back("shadow_map_sets");
|
||||
shader_binding.binding_point.push_back(5);
|
||||
shader_binding.block_name.push_back("spot_shadow_map_sets");
|
||||
shader_binding.binding_point.push_back(6);
|
||||
shader_binding.buffer_id.push_back(shadow_buffer_id);
|
||||
shader_binding.buffer_type.push_back(HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef HYDRAINITIALISESHADOWBUFFERTASK
|
||||
#define HYDRAINITIALISESHADOWBUFFERTASK
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../buffer/HydraShadowBufferManager.h"
|
||||
|
||||
class HydraInitialiseShadowBufferTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
public:
|
||||
virtual void Process() override
|
||||
{
|
||||
GetEngine()->ShadowBufferManager()->Initialise();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HYDRAINITIALISESHADOWBUFFERTASK */
|
||||
Reference in New Issue
Block a user