Implemented Shadow maps (still needs improvement) #314
|
@ -262,7 +262,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
// Shadow map pass will have no resources bound at first. Lighting system will add resources to the node.
|
// Shadow map pass will have no resources bound at first. Lighting system will add resources to the node.
|
||||||
// It will initially also not have any subpasses since they will be added for each light that casts shadows.
|
// It will initially also not have any subpasses since they will be added for each light that casts shadows.
|
||||||
auto shadowMapPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {});
|
auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {});
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* DEFERRED COMPOSITE NODE */
|
/* DEFERRED COMPOSITE NODE */
|
||||||
|
@ -279,17 +279,16 @@ namespace SHADE
|
||||||
},
|
},
|
||||||
{ SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()});
|
{ SHGraphicsConstants::RenderGraphNodeNames::GBUFFER_PASS .data()});
|
||||||
|
|
||||||
// Add subpass with exterior draw call to transition shadow maps
|
|
||||||
//auto shadowMapTransitionSubpass = deferredCompositeNode->AddSubpass("Shadow Map Transition", {}, {});
|
|
||||||
//shadowMapTransitionSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
|
||||||
// {
|
|
||||||
// lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer);
|
|
||||||
// });
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* DEFERRED COMPOSITE SUBPASS INIT */
|
/* DEFERRED COMPOSITE SUBPASS INIT */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
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" });
|
||||||
|
deferredCompositeCompute->AddPreComputeFunction([=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
||||||
|
{
|
||||||
|
lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* DEBUG DRAW PASS INIT */
|
/* DEBUG DRAW PASS INIT */
|
||||||
|
|
|
@ -129,20 +129,25 @@ namespace SHADE
|
||||||
if (subpasses.empty())
|
if (subpasses.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
uint32_t numValidSubpasses = std::count_if(subpasses.begin(), subpasses.end(), [](Handle<SHSubpass> subpass) {return !subpass->HasNoAttachments();});
|
||||||
|
|
||||||
// Create subpass description and dependencies based on number of subpasses
|
// Create subpass description and dependencies based on number of subpasses
|
||||||
spDescs.resize(subpasses.size());
|
spDescs.resize(numValidSubpasses);
|
||||||
spDeps.resize(subpasses.size());
|
spDeps.resize(numValidSubpasses);
|
||||||
|
|
||||||
// Now we want to loop through all attachments in all subpasses in the node and query
|
// Now we want to loop through all attachments in all subpasses in the node and query
|
||||||
// the resources being used. For each resource we want to query the type and record it
|
// the resources being used. For each resource we want to query the type and record it
|
||||||
// in bit fields (1 bit for each subpass).
|
// in bit fields (1 bit for each subpass).
|
||||||
uint32_t colorRead = 0, colorWrite = 0, depthRead = 0, depthWrite = 0, inputDependencies = 0;
|
uint32_t colorRead = 0, colorWrite = 0, depthRead = 0, depthWrite = 0, inputDependencies = 0;
|
||||||
|
|
||||||
uint32_t i = 0;
|
|
||||||
|
|
||||||
// For all subpasses (see above description about bit field for this).
|
// For all subpasses (see above description about bit field for this).
|
||||||
for (auto& subpass : subpasses)
|
for (uint32_t i = 0; auto& subpass : subpasses)
|
||||||
{
|
{
|
||||||
|
// skip if subpass is not valid
|
||||||
|
if (subpass->HasNoAttachments())
|
||||||
|
continue;
|
||||||
|
|
||||||
// Configure subpass description
|
// Configure subpass description
|
||||||
auto& desc = spDescs[i];
|
auto& desc = spDescs[i];
|
||||||
desc.pColorAttachments = subpass->colorReferences.data();
|
desc.pColorAttachments = subpass->colorReferences.data();
|
||||||
|
@ -198,8 +203,11 @@ namespace SHADE
|
||||||
|
|
||||||
// Loop through all subpasses again but this time we use the bit field to initialize
|
// Loop through all subpasses again but this time we use the bit field to initialize
|
||||||
// the dependencies.
|
// the dependencies.
|
||||||
for (i = 0; i < subpasses.size(); ++i)
|
for (uint32_t i = 0; auto & subpass : subpasses)
|
||||||
{
|
{
|
||||||
|
if (subpass->HasNoAttachments())
|
||||||
|
continue;
|
||||||
|
|
||||||
vk::PipelineStageFlags srcStage;
|
vk::PipelineStageFlags srcStage;
|
||||||
vk::PipelineStageFlags dstStage;
|
vk::PipelineStageFlags dstStage;
|
||||||
vk::AccessFlags srcAccess;
|
vk::AccessFlags srcAccess;
|
||||||
|
@ -257,6 +265,8 @@ namespace SHADE
|
||||||
|
|
||||||
// initialize input descriptors
|
// initialize input descriptors
|
||||||
subpasses[i]->CreateInputDescriptors();
|
subpasses[i]->CreateInputDescriptors();
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +649,7 @@ namespace SHADE
|
||||||
subpasses[i]->Execute(commandBuffer, descPool, frameIndex);
|
subpasses[i]->Execute(commandBuffer, descPool, frameIndex);
|
||||||
|
|
||||||
// Go to next subpass if not last subpass
|
// Go to next subpass if not last subpass
|
||||||
if (i != static_cast<uint32_t>(subpasses.size()) - 1u)
|
if (i != static_cast<uint32_t>(subpasses.size()) - 1u && !subpasses[i]->HasNoAttachments())
|
||||||
commandBuffer->NextSubpass();
|
commandBuffer->NextSubpass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,11 @@ namespace SHADE
|
||||||
|
|
||||||
void SHRenderGraphNodeCompute::Execute(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
void SHRenderGraphNodeCompute::Execute(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
|
for (auto& fn : preComputeFunctions)
|
||||||
|
{
|
||||||
|
fn (cmdBuffer, frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
// bind the compute pipeline
|
// bind the compute pipeline
|
||||||
cmdBuffer->BindPipeline(computePipeline);
|
cmdBuffer->BindPipeline(computePipeline);
|
||||||
|
|
||||||
|
@ -252,4 +257,9 @@ namespace SHADE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHRenderGraphNodeCompute::AddPreComputeFunction(PreComputeFunction const& fn) noexcept
|
||||||
|
{
|
||||||
|
preComputeFunctions.push_back(fn);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ namespace SHADE
|
||||||
|
|
||||||
class SHRenderGraphNodeCompute
|
class SHRenderGraphNodeCompute
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
using PreComputeFunction = std::function<void(Handle<SHVkCommandBuffer>, uint32_t)>;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Binding of set SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE
|
// Binding of set SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE
|
||||||
struct ComputeResource
|
struct ComputeResource
|
||||||
|
@ -73,6 +77,9 @@ namespace SHADE
|
||||||
//! Name of this node
|
//! Name of this node
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
std::vector<PreComputeFunction> preComputeFunctions;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* PRIVATE MEMBER FUNCTIONS */
|
/* PRIVATE MEMBER FUNCTIONS */
|
||||||
|
@ -97,6 +104,7 @@ namespace SHADE
|
||||||
void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span<Handle<SHVkBuffer>> const& buffers, uint32_t offset, uint32_t range) noexcept;
|
void ModifyWriteDescBufferComputeResource (uint32_t binding, std::span<Handle<SHVkBuffer>> const& buffers, uint32_t offset, uint32_t range) noexcept;
|
||||||
void ModifyWriteDescImageComputeResource(uint32_t binding, std::span<SHVkDescriptorSetGroup::viewSamplerLayout> const& viewSamplerLayouts) noexcept;
|
void ModifyWriteDescImageComputeResource(uint32_t binding, std::span<SHVkDescriptorSetGroup::viewSamplerLayout> const& viewSamplerLayouts) noexcept;
|
||||||
|
|
||||||
|
void AddPreComputeFunction (PreComputeFunction const& fn) noexcept;
|
||||||
|
|
||||||
friend class SHRenderGraph;
|
friend class SHRenderGraph;
|
||||||
friend class SHRenderGraphNode;
|
friend class SHRenderGraphNode;
|
||||||
|
|
|
@ -211,6 +211,8 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
commandBuffer->BeginLabeledSegment(name);
|
commandBuffer->BeginLabeledSegment(name);
|
||||||
|
|
||||||
|
if (!HasNoAttachments())
|
||||||
|
{
|
||||||
// Ensure correct transforms are provided
|
// Ensure correct transforms are provided
|
||||||
superBatch->UpdateBuffers(frameIndex, descPool);
|
superBatch->UpdateBuffers(frameIndex, descPool);
|
||||||
|
|
||||||
|
@ -229,6 +231,7 @@ namespace SHADE
|
||||||
|
|
||||||
// Draw all the batches
|
// Draw all the batches
|
||||||
superBatch->Draw(commandBuffer, frameIndex);
|
superBatch->Draw(commandBuffer, frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw all the exterior draw calls
|
// Draw all the exterior draw calls
|
||||||
for (auto& drawCall : exteriorDrawCalls)
|
for (auto& drawCall : exteriorDrawCalls)
|
||||||
|
|
Loading…
Reference in New Issue