Implemented Shadow maps (still needs improvement) #314

Merged
Xenosas1337 merged 22 commits from SP3-1-Rendering into main 2023-01-16 15:40:30 +08:00
11 changed files with 35 additions and 13 deletions
Showing only changes of commit 77a5829fc9 - Show all commits

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 97158628 Starting Scene ID: 86098106
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

View File

@ -6,6 +6,7 @@ struct DirectionalLightStruct
uint isActive; uint isActive;
uint cullingMask; uint cullingMask;
vec4 diffuseColor; vec4 diffuseColor;
mat4 pvMatrix;
}; };
struct AmbientLightStruct struct AmbientLightStruct
@ -24,6 +25,8 @@ layout(set = 3, binding = 3, r32ui) uniform uimage2D lightLayerData;
layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage; layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage;
layout(set = 3, binding = 5, rgba8) uniform image2D targetImage; layout(set = 3, binding = 5, rgba8) uniform image2D targetImage;
layout (set = 4, binding = 0) uniform sampler2D shadowMaps[]; // for textures (global)
layout(set = 1, binding = 0) uniform LightCounts layout(set = 1, binding = 0) uniform LightCounts
{ {
uint directionalLights; uint directionalLights;

View File

@ -158,7 +158,7 @@ namespace SHADE
.Type = vk::DescriptorType::eCombinedImageSampler, .Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute, .Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::IMAGE_AND_SAMPLERS_DATA,
.DescriptorCount = 200, // we can have up to 2000 textures for now .DescriptorCount = 200, // we can have up to 200 textures for now
.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount, .flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount,
}; };

View File

@ -13,7 +13,7 @@ namespace SHADE
CAMERA, CAMERA,
MATERIALS, MATERIALS,
FONT, FONT,
RENDER_GRAPH_RESOURCE,
RENDER_GRAPH_NODE_COMPUTE_RESOURCE, RENDER_GRAPH_NODE_COMPUTE_RESOURCE,
RENDER_GRAPH_RESOURCE,
}; };
} }

View File

@ -127,7 +127,10 @@ namespace SHADE
SHFreetypeInstance::Init(); SHFreetypeInstance::Init();
SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_VS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false);
// Load Built In Shaders // Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT); static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
@ -288,7 +291,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* DEFERRED COMPOSITE SUBPASS INIT */ /* DEFERRED COMPOSITE SUBPASS INIT */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }); auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute("Deferred Composite", deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene" }, {}/*SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::SHADOW)[0]*/);
deferredCompositeCompute->AddPreComputeFunction([=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) deferredCompositeCompute->AddPreComputeFunction([=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
{ {
lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer);

View File

@ -122,4 +122,9 @@ namespace SHADE
return cameraDirector; return cameraDirector;
} }
SHShaderCameraData SHRenderer::GetCPUCameraData(void) const noexcept
{
return cpuCameraData;
}
} }

View File

@ -93,6 +93,7 @@ namespace SHADE
/* Setters and Getters */ /* Setters and Getters */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<SHCameraDirector> GetCameraDirector (void) const noexcept; Handle<SHCameraDirector> GetCameraDirector (void) const noexcept;
SHShaderCameraData GetCPUCameraData (void) const noexcept;
private: private:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -56,6 +56,11 @@ namespace SHADE
//lightPtr->direction = lightData.direction; //lightPtr->direction = lightData.direction;
lightPtr->diffuseColor = lightData.color; lightPtr->diffuseColor = lightData.color;
lightPtr->active = lightComp->isActive; lightPtr->active = lightComp->isActive;
// write view projection matrix if renderer is available
auto lightRenderer = lightComp->GetRenderer();
if (lightRenderer)
lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix;
break; break;
} }
case SH_LIGHT_TYPE::POINT: case SH_LIGHT_TYPE::POINT:
@ -499,6 +504,12 @@ namespace SHADE
for (auto& light : lightComps) for (auto& light : lightComps)
{ {
if (auto renderer = light.GetRenderer())
{
//SHMatrix orthoMatrix = SHMatrix::OrthographicRH()
renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f));
}
auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type);
// First we want to make sure the light is already bound to the system. if it // First we want to make sure the light is already bound to the system. if it
@ -520,14 +531,6 @@ namespace SHADE
// Light is now updated in the container // Light is now updated in the container
//light.ClearDirtyFlag(); //light.ClearDirtyFlag();
} }
if (auto renderer = light.GetRenderer())
{
//SHMatrix orthoMatrix = SHMatrix::OrthographicRH()
renderer->UpdateDataManual (frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(12.0f, 12.0f, 0.1f, 20.0f));
}
} }
// Write data to GPU // Write data to GPU

View File

@ -3,12 +3,14 @@
#include "Resource/SHHandle.h" #include "Resource/SHHandle.h"
#include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec4.h" #include "Math/Vector/SHVec4.h"
#include "Math/SHMatrix.h"
#include "SHLightData.h" #include "SHLightData.h"
#include <array> #include <array>
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
#include "Graphics/RenderGraph/SHRenderGraphResource.h" #include "Graphics/RenderGraph/SHRenderGraphResource.h"
#include "ECS_Base/SHECSMacros.h" #include "ECS_Base/SHECSMacros.h"
namespace SHADE namespace SHADE
{ {
class SHVkLogicalDevice; class SHVkLogicalDevice;
@ -39,6 +41,9 @@ namespace SHADE
//! Diffuse color emitted by the light //! Diffuse color emitted by the light
alignas (16) SHVec4 diffuseColor; alignas (16) SHVec4 diffuseColor;
//! Matrix for world to projection from light's perspective
SHMatrix pvMatrix;
}; };
// Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU.

View File

@ -208,7 +208,9 @@ namespace SHADE
newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount; newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount;
} }
else else
{
SHLOG_ERROR("Variable size binding is detected, but the binding is not the last binding of the set and is therefore invalid. "); SHLOG_ERROR("Variable size binding is detected, but the binding is not the last binding of the set and is therefore invalid. ");
}
} }
setsWithBindings[CURRENT_SET].emplace_back(newBinding); setsWithBindings[CURRENT_SET].emplace_back(newBinding);