Implemented Shadow maps (still needs improvement) #314
|
@ -5,6 +5,7 @@
|
|||
|
||||
|
||||
layout(location = 0) in vec3 aVertexPos;
|
||||
layout(location = 4) in mat4 worldTransform;
|
||||
|
||||
layout(set = 1, binding = 0) uniform CameraData
|
||||
{
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: ShadowMap_VS
|
||||
ID: 44646107
|
||||
Type: 2
|
|
@ -551,7 +551,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHBatch - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
||||
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline/* = true*/)
|
||||
{
|
||||
if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS)
|
||||
{
|
||||
|
@ -566,7 +566,10 @@ namespace SHADE
|
|||
// Bind all required objects before drawing
|
||||
static std::array<uint32_t, 1> dynamicOffset{ 0 };
|
||||
cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index));
|
||||
|
||||
if (bindBatchPipeline)
|
||||
cmdBuffer->BindPipeline(pipeline);
|
||||
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
||||
if (matPropsDescSet[frameIndex])
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace SHADE
|
|||
void UpdateTransformBuffer(uint32_t frameIndex);
|
||||
void UpdateInstancedIntegerBuffer(uint32_t frameIndex);
|
||||
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) ;
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex);
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
|
|
|
@ -107,12 +107,12 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHSuperBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
||||
void SHSuperBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline /*= true*/) noexcept
|
||||
{
|
||||
// Build all batches
|
||||
for (auto& batch : batches)
|
||||
{
|
||||
batch.Draw(cmdBuffer, frameIndex);
|
||||
batch.Draw(cmdBuffer, frameIndex, bindBatchPipeline);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace SHADE
|
|||
void Clear() noexcept;
|
||||
void UpdateBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
|
|
|
@ -127,6 +127,8 @@ namespace SHADE
|
|||
|
||||
SHFreetypeInstance::Init();
|
||||
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_VS.glsl", false);
|
||||
|
||||
// Load Built In Shaders
|
||||
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
|
||||
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
|
||||
|
@ -140,6 +142,8 @@ namespace SHADE
|
|||
static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TEXT_FS);
|
||||
static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(RENDER_SC_VS);
|
||||
static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(RENDER_SC_FS);
|
||||
static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(SHADOW_MAP_VS);
|
||||
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitRenderGraph(void) noexcept
|
||||
|
@ -755,6 +759,17 @@ namespace SHADE
|
|||
auto const& EVENT_DATA = reinterpret_cast<const SHEventSpec<SHLightEnableShadowEvent>*>(eventPtr.get())->data;
|
||||
auto* lightComp = SHComponentManager::GetComponent<SHLightComponent>(EVENT_DATA->lightEntity);
|
||||
std::string resourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity);
|
||||
Handle<SHSubpass> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write");
|
||||
|
||||
if (!shadowMapPipeline)
|
||||
{
|
||||
SHPipelineLibrary tempLibrary{};
|
||||
Handle<SHRenderGraphNode> rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data());
|
||||
|
||||
tempLibrary.Init(device);
|
||||
tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, rgNode->GetRenderpass(), companionSubpass);
|
||||
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} });
|
||||
}
|
||||
|
||||
if (EVENT_DATA->generateRenderer)
|
||||
{
|
||||
|
@ -773,6 +788,7 @@ namespace SHADE
|
|||
// Add a subpass to render to that shadow map
|
||||
auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer());
|
||||
newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH_STENCIL);
|
||||
newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline
|
||||
|
||||
// regenerate the node
|
||||
shadowMapNode->RuntimeStandaloneRegenerate();
|
||||
|
|
|
@ -464,6 +464,7 @@ namespace SHADE
|
|||
Handle<SHVkShaderModule> textFS;
|
||||
Handle<SHVkShaderModule> renderToSwapchainVS;
|
||||
Handle<SHVkShaderModule> renderToSwapchainFS;
|
||||
Handle<SHVkShaderModule> shadowMapVS;
|
||||
|
||||
// Fonts
|
||||
Handle<SHFont> testFont;
|
||||
|
@ -478,6 +479,7 @@ namespace SHADE
|
|||
Handle<SHVkPipeline> debugDrawWireMeshDepthPipeline;
|
||||
Handle<SHVkPipeline> debugDrawFilledPipeline;
|
||||
Handle<SHVkPipeline> debugDrawFilledDepthPipeline;
|
||||
Handle<SHVkPipeline> shadowMapPipeline; // initialized only when a shadow map is needed
|
||||
|
||||
// Built-In Textures
|
||||
Handle<SHTexture> defaultTexture;
|
||||
|
|
|
@ -378,11 +378,10 @@ namespace SHADE
|
|||
|
||||
SHMatrix SHLightingSubSystem::GetViewMatrix(SHLightComponent* lightComp) noexcept
|
||||
{
|
||||
SHTransformComponent* transform = SHComponentManager::GetComponent<SHTransformComponent>(lightComp->GetEID());
|
||||
switch (lightComp->GetLightData().type)
|
||||
{
|
||||
case SH_LIGHT_TYPE::DIRECTIONAL:
|
||||
return SHMatrix::LookAtRH(transform->GetLocalPosition(), lightComp->GetLightData().position, SHVec3(0.0f, 1.0f, 0.0f));
|
||||
return SHMatrix::LookAtRH(lightComp->GetLightData().position, lightComp->GetLightData().position + lightComp->GetLightData().direction, SHVec3(0.0f, 1.0f, 0.0f));
|
||||
case SH_LIGHT_TYPE::POINT:
|
||||
return {};
|
||||
case SH_LIGHT_TYPE::SPOT:
|
||||
|
|
|
@ -10,9 +10,15 @@ namespace SHADE
|
|||
|
||||
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass) noexcept
|
||||
{
|
||||
std::vector<Handle<SHVkShaderModule>> modules{};
|
||||
if (vsFsPair.first)
|
||||
modules.push_back(vsFsPair.first);
|
||||
if (vsFsPair.second)
|
||||
modules.push_back(vsFsPair.second);
|
||||
|
||||
SHPipelineLayoutParams params
|
||||
{
|
||||
.shaderModules = {vsFsPair.first, vsFsPair.second},
|
||||
.shaderModules = std::move (modules),
|
||||
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ namespace SHADE
|
|||
vk::ShaderStageFlags stageFlags;
|
||||
|
||||
for (auto& shaderModule : shaderModules)
|
||||
{
|
||||
if (shaderModule)
|
||||
{
|
||||
// References for convenience
|
||||
auto const& reflectedData = shaderModule->GetReflectedData();
|
||||
|
@ -81,7 +83,7 @@ namespace SHADE
|
|||
|
||||
stageFlags |= shaderModule->GetShaderStageFlagBits();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// After all the sizes of the push constant blocks have been added, record the size in the interface
|
||||
|
@ -132,6 +134,9 @@ namespace SHADE
|
|||
//! Now we take descriptor set info from all shaders and prepare some bindings for the descriptor set
|
||||
for (auto& shaderModule : shaderModules)
|
||||
{
|
||||
if (!shaderModule)
|
||||
continue;
|
||||
|
||||
auto const& descBindingInfo = shaderModule->GetReflectedData().GetDescriptorBindingInfo();
|
||||
auto const& reflectedSets = descBindingInfo.GetReflectedSets();
|
||||
|
||||
|
@ -326,11 +331,10 @@ namespace SHADE
|
|||
{
|
||||
for (auto& mod : shaderModules)
|
||||
{
|
||||
mod->AddCallback([this]()
|
||||
if (mod)
|
||||
{
|
||||
RecreateIfNeeded();
|
||||
mod->AddCallback([this]() { RecreateIfNeeded(); });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
RecreateIfNeeded ();
|
||||
|
|
|
@ -229,9 +229,18 @@ namespace SHADE
|
|||
if (renderer)
|
||||
renderer->BindDescriptorSet(commandBuffer, SH_PIPELINE_TYPE::GRAPHICS, descMappings.at(SHPredefinedDescriptorTypes::CAMERA), frameIndex);
|
||||
|
||||
// If companion subpass is not a valid handle, render super batch normally
|
||||
if (!companionSubpass.companion)
|
||||
{
|
||||
// Draw all the batches
|
||||
superBatch->Draw(commandBuffer, frameIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandBuffer->BindPipeline(companionSubpass.pipeline);
|
||||
companionSubpass.companion->superBatch->Draw(commandBuffer, frameIndex, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw all the exterior draw calls
|
||||
for (auto& drawCall : exteriorDrawCalls)
|
||||
|
|
Loading…
Reference in New Issue