Trajectory Rendering WIP

- Trajectory rendering system is all in place. Just requires testing through the component. 
- Component needs to be reflected in editor
- Shaders for trajectory rendering is also in place
This commit is contained in:
Brandon Mak 2023-02-17 13:48:14 +08:00
parent cee45863fa
commit f1217cc20b
12 changed files with 86 additions and 33 deletions

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Trajectory_FS
ID: 45635685
Type: 2

View File

@ -2,9 +2,9 @@
#extension GL_KHR_vulkan_glsl : enable
// vertex inputs
layout(location = 0) in vec4 aPos;
layout(location = 0) in vec3 aPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec2 aColor;
layout(location = 2) in vec4 aColor;
layout(location = 3) in mat4 aTransform;
// between shader stages

Binary file not shown.

View File

@ -0,0 +1,3 @@
Name: Trajectory_VS
ID: 41042628
Type: 2

View File

@ -64,6 +64,17 @@ namespace SHADE
/***************************************************************************/
static constexpr std::string_view DEFERRED_COMPOSITE_PASS = "Deferred Comp Pass";
/***************************************************************************/
/*!
\brief
Name of vfx render graph node.
*/
/***************************************************************************/
static constexpr std::string_view VFX_PASS = "Vfx Pass";
/***************************************************************************/
/*!
@ -117,6 +128,7 @@ namespace SHADE
static constexpr std::string_view GBUFFER_WRITE_SUBPASS = "G-Buffer Write";
static constexpr std::string_view UI_SUBPASS = "UI";
static constexpr std::string_view VFX_SUBPASS = "VFX";
static constexpr std::array USABLE_SUBPASSES =
{

View File

@ -138,7 +138,8 @@ namespace SHADE
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/Trajectory_VS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/Trajectory_FS.glsl", false);
// Load Built In Shaders
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
@ -154,8 +155,10 @@ 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);
static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(SHADOW_MAP_FS);
static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(SHADOW_MAP_VS);
static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(SHADOW_MAP_FS);
static constexpr AssetID TRAJECTORY_VS = 41042628; trajectoryVS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TRAJECTORY_VS);
static constexpr AssetID TRAJECTORY_FS = 45635685; trajectoryFS = SHResourceManager::LoadOrGet<SHVkShaderModule>(TRAJECTORY_FS);
}
@ -308,13 +311,24 @@ namespace SHADE
lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer);
});
/*-----------------------------------------------------------------------*/
/* VFX PASS */
/*-----------------------------------------------------------------------*/
auto vfxPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data(), { "Scene", "Depth Buffer" }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data() });
auto vfxSubpass = vfxPass->AddSubpass("Vfx Subpass", worldViewport, worldRenderer);
vfxSubpass->AddColorOutput("Scene");
vfxSubpass->AddDepthOutput("Depth Buffer");
vfxSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
{
trajectoryRenderingSubSystem->Render(cmdBuffer, renderer, frameIndex);
});
/*-----------------------------------------------------------------------*/
/* DEBUG DRAW PASS INIT */
/*-----------------------------------------------------------------------*/
// Set up Debug Draw Passes
// - Depth Tested
auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, {SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data()});
auto debugDrawNodeDepth = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::DEBUG_DRAW_DEPTH_PASS.data(), {"Scene", "Depth Buffer"}, { SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()/*, SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data()*/});
auto debugDrawDepthSubpass = debugDrawNodeDepth->AddSubpass("Debug Draw with Depth", worldViewport, worldRenderer);
debugDrawDepthSubpass->AddColorOutput("Scene");
debugDrawDepthSubpass->AddDepthOutput("Depth Buffer");
@ -435,8 +449,8 @@ namespace SHADE
trajectoryRenderingSubSystem = resourceManager.Create<SHTrajectoryRenderingSubSystem>();
//auto gBufferNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data());
//trajectoryRenderingSubSystem->Init(device, )
auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data());
trajectoryRenderingSubSystem->Init(device, vfxNode->GetRenderpass(), vfxNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS), trajectoryVS, trajectoryFS);
SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem);
@ -572,6 +586,7 @@ namespace SHADE
}
textRenderingSubSystem->Run(frameIndex);
trajectoryRenderingSubSystem->Run(frameIndex);
for (auto renderer : renderers)

View File

@ -471,6 +471,8 @@ namespace SHADE
Handle<SHVkShaderModule> renderToSwapchainFS;
Handle<SHVkShaderModule> shadowMapVS;
Handle<SHVkShaderModule> shadowMapFS;
Handle<SHVkShaderModule> trajectoryVS;
Handle<SHVkShaderModule> trajectoryFS;
// Fonts
Handle<SHFont> testFont;

View File

@ -62,6 +62,11 @@ namespace SHADE
mesh = newMesh;
}
void SHTrajectoryRenderableComponent::SetPositions(std::vector<SHVec3> const& inPositions) noexcept
{
positions = inPositions;
}
void SHTrajectoryRenderableComponent::SetStartColor(SHVec4 color) noexcept
{
startColor = color;

View File

@ -26,7 +26,7 @@ namespace SHADE
//! Color the trajectory should evolve to the longer it is
SHVec4 endColor;
//! evolving rate of the color (with respect to dt)
//! evolving rate of the color
float colorEvolveRate;
public:
@ -34,6 +34,7 @@ namespace SHADE
/* PRIVATE MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/
void SetMesh(Handle<SHMesh> newMesh) noexcept;
void SetPositions (std::vector<SHVec3> const& inPositions) noexcept;
void SetStartColor(SHVec4 startColor) noexcept;
void SetEndColor (SHVec4 endColor) noexcept;
void SetColorEvolveRate (float rate) noexcept;

View File

@ -70,11 +70,17 @@ namespace SHADE
pipeline->GetPipelineState().SetColorBlenState(colorBlendState);
}
void SHTrajectoryRenderingSubSystem::Run(uint32_t frameIndex, float dt) noexcept
void SHTrajectoryRenderingSubSystem::Run(uint32_t frameIndex) noexcept
{
auto& comps = SHComponentManager::GetDense<SHTrajectoryRenderableComponent>();
for (auto& comp : comps)
{
comp.SetPositions(std::vector
{
SHVec3 {},
SHVec3 {}
});
// If has positions, feed data to buffer.
if (comp.HasPositions())
{
@ -115,7 +121,7 @@ namespace SHADE
currentColor = SHVec4::Lerp(startColor, endColor, lerpValue);
// evolve lerp value and clamp to 1
lerpValue = std::max (1.0f, lerpValue + (colorEvolveRate * dt));
lerpValue = std::max (1.0f, lerpValue + colorEvolveRate);
}
// add draw data for this trajectory
@ -134,40 +140,46 @@ namespace SHADE
comp.ClearPositions();
}
// read transform data to buffer
// read draw data to buffer
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, transformBuffer, transformData.data(), sizeof (SHMatrix) * transformData.size(), vk::BufferUsageFlagBits::eVertexBuffer, "Trajectory System Transform Buffer");
if (!transformData.empty())
{
// read transform data to buffer
// read draw data to buffer
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, transformBuffer, transformData.data(), sizeof (SHMatrix) * transformData.size(), vk::BufferUsageFlagBits::eVertexBuffer, "Trajectory System Transform Buffer");
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, drawDataBuffer, drawData.data(), sizeof(vk::DrawIndexedIndirectCommand) * drawData.size(), vk::BufferUsageFlagBits::eIndirectBuffer, "Trajectory System Draw Data Buffer");
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, drawDataBuffer, drawData.data(), sizeof(vk::DrawIndexedIndirectCommand) * drawData.size(), vk::BufferUsageFlagBits::eIndirectBuffer, "Trajectory System Draw Data Buffer");
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, colorBuffer, colorData.data(), sizeof(SHVec4) * colorData.size(), vk::BufferUsageFlagBits::eVertexBuffer, "Trajectory System Color Data Buffer");
SHVkUtil::EnsureBufferAndCopyHostVisibleData(logicalDevice, colorBuffer, colorData.data(), sizeof(SHVec4) * colorData.size(), vk::BufferUsageFlagBits::eVertexBuffer, "Trajectory System Color Data Buffer");
}
}
void SHTrajectoryRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex) noexcept
{
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::TRAJECTORY_RENDERING);
uint32_t staticGlobalSetIndex = mappings.at(SHPredefinedDescriptorTypes::STATIC_DATA);
uint32_t cameraSetIndex = mappings.at(SHPredefinedDescriptorTypes::CAMERA);
if (!transformData.empty())
{
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::TRAJECTORY_RENDERING);
uint32_t staticGlobalSetIndex = mappings.at(SHPredefinedDescriptorTypes::STATIC_DATA);
uint32_t cameraSetIndex = mappings.at(SHPredefinedDescriptorTypes::CAMERA);
cmdBuffer->BindPipeline(pipeline);
cmdBuffer->BindPipeline(pipeline);
// Bind global data
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, staticGlobalSetIndex);
// Bind global data
SHGlobalDescriptorSets::BindStaticGlobalData(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, staticGlobalSetIndex);
// Bind camera data
renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex);
// Bind camera data
renderer->BindDescriptorSet(cmdBuffer, SH_PIPELINE_TYPE::GRAPHICS, cameraSetIndex, frameIndex);
// Bind color vertex buffer
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRAJECTORY_COLOR, colorBuffer, 0);
// Bind color vertex buffer
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRAJECTORY_COLOR, colorBuffer, 0);
// call draw call
cmdBuffer->DrawMultiIndirect(drawDataBuffer, drawData.size());
// call draw call
cmdBuffer->DrawMultiIndirect(drawDataBuffer, drawData.size());
// clear CPU transform and draw data
transformData.clear();
drawData.clear();
colorData.clear();
// clear CPU transform and draw data
transformData.clear();
drawData.clear();
colorData.clear();
}
}

View File

@ -57,7 +57,7 @@ namespace SHADE
public:
void Init (Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept;
void Run(uint32_t frameIndex, float dt) noexcept;
void Run(uint32_t frameIndex) noexcept;
void Render(Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex) noexcept;
void Exit(void) noexcept;