Particles WIP
This commit is contained in:
parent
070f01bf67
commit
69fc997361
|
@ -135,7 +135,7 @@ void main()
|
||||||
|
|
||||||
// Set size of particle
|
// Set size of particle
|
||||||
particle.scaleAndDecay.x = emitterParams.data.lifeAndSizeRange.z;
|
particle.scaleAndDecay.x = emitterParams.data.lifeAndSizeRange.z;
|
||||||
particle.scaleAndDecay.y = emitterParams.data.lifeAndSizeRange.z;
|
particle.scaleAndDecay.z = emitterParams.data.lifeAndSizeRange.z;
|
||||||
|
|
||||||
particle.rotation = vec4 (5.0f);
|
particle.rotation = vec4 (5.0f);
|
||||||
particle.acceleration = vec4 (0.01f);
|
particle.acceleration = vec4 (0.01f);
|
||||||
|
|
Binary file not shown.
|
@ -132,5 +132,7 @@ void main()
|
||||||
outputParticles.data[index] = particle;
|
outputParticles.data[index] = particle;
|
||||||
uint drawIndex = atomicAdd (indirectArgs.instanceCount, 1);
|
uint drawIndex = atomicAdd (indirectArgs.instanceCount, 1);
|
||||||
indices[drawIndex] = index;
|
indices[drawIndex] = index;
|
||||||
|
|
||||||
|
// indirectArgs.instanceCount = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -78,16 +78,17 @@ void main()
|
||||||
vec2 particleScaleData = particle.scaleAndDecay.xz; // x and y
|
vec2 particleScaleData = particle.scaleAndDecay.xz; // x and y
|
||||||
|
|
||||||
mat4 localModel = mat4 (1.0f);
|
mat4 localModel = mat4 (1.0f);
|
||||||
localModel[0][0] = particleScaleData.x;
|
localModel[0][0] = 1.0f;
|
||||||
localModel[1][1] = particleScaleData.y;
|
localModel[1][1] = 1.0f;
|
||||||
|
|
||||||
mat4 rotate = mat4(1.0f);
|
mat4 rotate = mat4(1.0f);
|
||||||
rotate[0][0] = cos(angle);
|
rotate[0][0] = cos(angle);
|
||||||
rotate[0][1] = sin(angle);
|
rotate[0][1] = sin(angle);
|
||||||
rotate[1][0] = -sin(angle);
|
rotate[1][0] = -sin(angle);
|
||||||
rotate[1][1] = cos(angle);
|
rotate[1][1] = cos(angle);
|
||||||
localModel = rotate * localModel;
|
// localModel = rotate * localModel;
|
||||||
|
|
||||||
localModel[3] = vec4 (particle.position.xyz, 1.0f);
|
localModel[3] = vec4 (particle.position.xyz, 1.0f);
|
||||||
gl_Position = cameraData.vpMat * localModel * vec4(vertexPos, 1.0f);
|
gl_Position = cameraData.vpMat * localModel * vec4(vertexPos, 1.0f);
|
||||||
|
// gl_Position = vec4(vertexPos, 1.0f);
|
||||||
}
|
}
|
Binary file not shown.
|
@ -462,7 +462,7 @@ namespace SHADE
|
||||||
vkCommandBuffer.drawIndexedIndirect(indirectDrawData->GetVkBuffer(), 0, drawCount, sizeof(vk::DrawIndexedIndirectCommand));
|
vkCommandBuffer.drawIndexedIndirect(indirectDrawData->GetVkBuffer(), 0, drawCount, sizeof(vk::DrawIndexedIndirectCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHVkCommandBuffer::DrawMultiIndirect(Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount)
|
void SHVkCommandBuffer::DrawMultiIndirect(Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount, uint32_t offset/* = 0*/)
|
||||||
{
|
{
|
||||||
if (cmdBufferState != SH_CMD_BUFFER_STATE::RECORDING)
|
if (cmdBufferState != SH_CMD_BUFFER_STATE::RECORDING)
|
||||||
{
|
{
|
||||||
|
@ -471,7 +471,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indirectDrawData)
|
if (indirectDrawData)
|
||||||
vkCommandBuffer.drawIndirect(indirectDrawData->GetVkBuffer(), 0, drawCount, sizeof(vk::DrawIndexedIndirectCommand));
|
vkCommandBuffer.drawIndirect(indirectDrawData->GetVkBuffer(), offset, drawCount, sizeof(vk::DrawIndirectCommand));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ namespace SHADE
|
||||||
void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept;
|
void DrawArrays (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) const noexcept;
|
||||||
void DrawIndexed (uint32_t indexCount, uint32_t firstIndex, uint32_t vertexOffset) const noexcept;
|
void DrawIndexed (uint32_t indexCount, uint32_t firstIndex, uint32_t vertexOffset) const noexcept;
|
||||||
void DrawMultiIndirectIndexed (Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount);
|
void DrawMultiIndirectIndexed (Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount);
|
||||||
void DrawMultiIndirect (Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount);
|
void DrawMultiIndirect (Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount, uint32_t offset = 0);
|
||||||
|
|
||||||
// Compute Commands
|
// Compute Commands
|
||||||
void ComputeDispatch (uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) noexcept;
|
void ComputeDispatch (uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) noexcept;
|
||||||
|
|
|
@ -352,10 +352,10 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
auto vfxPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data(), { "Scene", "Depth Buffer" }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data() });
|
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(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS.data(), worldViewport, worldRenderer);
|
auto vfxSubpass = vfxPass->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS.data(), worldViewport, worldRenderer);
|
||||||
vfxPass->AddPreBeginFunction([=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
//vfxPass->AddPreBeginFunction([=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
||||||
{
|
// {
|
||||||
particleSubSystem->Run(cmdBuffer, frameIndex);
|
// particleSubSystem->Run(cmdBuffer, frameIndex);
|
||||||
});
|
// });
|
||||||
vfxSubpass->AddColorOutput("Scene");
|
vfxSubpass->AddColorOutput("Scene");
|
||||||
vfxSubpass->AddDepthOutput("Depth Buffer");
|
vfxSubpass->AddDepthOutput("Depth Buffer");
|
||||||
vfxSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
vfxSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
|
||||||
|
@ -689,7 +689,6 @@ namespace SHADE
|
||||||
textRenderingSubSystem->Run(frameIndex);
|
textRenderingSubSystem->Run(frameIndex);
|
||||||
trajectoryRenderingSubSystem->Run(frameIndex);
|
trajectoryRenderingSubSystem->Run(frameIndex);
|
||||||
|
|
||||||
|
|
||||||
for (auto renderer : renderers)
|
for (auto renderer : renderers)
|
||||||
{
|
{
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
|
@ -711,6 +710,7 @@ namespace SHADE
|
||||||
renderGraph->Begin(frameIndex);
|
renderGraph->Begin(frameIndex);
|
||||||
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
|
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
|
||||||
|
|
||||||
|
particleSubSystem->Run(cmdBuffer, frameIndex);
|
||||||
|
|
||||||
renderGraph->Execute(frameIndex, descPool, MESH_DATA);
|
renderGraph->Execute(frameIndex, descPool, MESH_DATA);
|
||||||
renderGraph->End(frameIndex);
|
renderGraph->End(frameIndex);
|
||||||
|
|
|
@ -166,7 +166,8 @@ namespace SHADE
|
||||||
|
|
||||||
void SHParticleSubSystem::RenderComponent(Handle<SHVkCommandBuffer> cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept
|
void SHParticleSubSystem::RenderComponent(Handle<SHVkCommandBuffer> cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
cmdBuffer->DrawMultiIndirect(comp.drawCallData, 1);
|
cmdBuffer->DrawMultiIndirect(comp.drawCallData, 1, static_cast<uint32_t>(sizeof(vk::DrawIndirectCommand)) * frameIndex);
|
||||||
|
//cmdBuffer->DrawArrays(4, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHParticleSubSystem::PreparePrePostUpdateBarriers(std::vector<vk::BufferMemoryBarrier>& preUpdateBarriers, std::vector<vk::BufferMemoryBarrier>& postUpdateBarriers, SHParticleEmitterComponent const& emitter, uint32_t const EMITTER_INDEX, uint32_t const FRAME_INDEX) noexcept
|
void SHParticleSubSystem::PreparePrePostUpdateBarriers(std::vector<vk::BufferMemoryBarrier>& preUpdateBarriers, std::vector<vk::BufferMemoryBarrier>& postUpdateBarriers, SHParticleEmitterComponent const& emitter, uint32_t const EMITTER_INDEX, uint32_t const FRAME_INDEX) noexcept
|
||||||
|
@ -215,10 +216,20 @@ namespace SHADE
|
||||||
.size = static_cast<uint32_t>(sizeof(uint32_t)) * emitter.maxParticles
|
.size = static_cast<uint32_t>(sizeof(uint32_t)) * emitter.maxParticles
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// make new barrier on stack...
|
||||||
|
vk::BufferMemoryBarrier drawDataBarrier
|
||||||
|
{
|
||||||
|
.srcAccessMask = vk::AccessFlagBits::eShaderWrite,
|
||||||
|
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
|
||||||
|
.buffer = emitter.drawCallData->GetVkBuffer(),
|
||||||
|
.offset = emitter.dynamicOffsets[FRAME_INDEX][DYOFF_INDEX_DRAW_DATA],
|
||||||
|
.size = static_cast<uint32_t>(sizeof(vk::DrawIndirectCommand))
|
||||||
|
};
|
||||||
|
|
||||||
// ...copy assign barriers on heap
|
// ...copy assign barriers on heap
|
||||||
postUpdateBarriers[EMITTER_INDEX * 2] = particleDataBarrierPost;
|
postUpdateBarriers[EMITTER_INDEX * 3] = particleDataBarrierPost;
|
||||||
postUpdateBarriers[(EMITTER_INDEX * 2) + 1] = indicesDataBarrier;
|
postUpdateBarriers[(EMITTER_INDEX * 3) + 1] = indicesDataBarrier;
|
||||||
|
postUpdateBarriers[(EMITTER_INDEX * 3) + 2] = drawDataBarrier;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +275,13 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
renderingPipelineData.pipeline->GetPipelineState().SetColorBlenState(colorBlendState);
|
renderingPipelineData.pipeline->GetPipelineState().SetColorBlenState(colorBlendState);
|
||||||
|
|
||||||
|
// Sets the input assembly state for rendering particles
|
||||||
|
SHInputAssemblyState inputAssemblyState{};
|
||||||
|
inputAssemblyState.topology = vk::PrimitiveTopology::eTriangleFan;
|
||||||
|
renderingPipelineData.pipeline->GetPipelineState().SetInputAssemblyState(inputAssemblyState);
|
||||||
|
|
||||||
|
|
||||||
renderingPipelineData.pipeline->ConstructPipeline();
|
renderingPipelineData.pipeline->ConstructPipeline();
|
||||||
|
|
||||||
SHPipelineLayoutParams emitPlParams
|
SHPipelineLayoutParams emitPlParams
|
||||||
|
@ -314,7 +332,7 @@ namespace SHADE
|
||||||
// After we invoke the updates for the emitters, we need to make sure all particles and indices data are done updating
|
// After we invoke the updates for the emitters, we need to make sure all particles and indices data are done updating
|
||||||
// before we issue them for rendering.
|
// before we issue them for rendering.
|
||||||
std::vector<vk::BufferMemoryBarrier> postUpdateBarriers{};
|
std::vector<vk::BufferMemoryBarrier> postUpdateBarriers{};
|
||||||
postUpdateBarriers.resize(emitters.size() * 2);
|
postUpdateBarriers.resize(emitters.size() * 3);
|
||||||
|
|
||||||
// If we wanted to be VERY safe, a barrier would be good here to make sure output particles have finish reading input particles in
|
// If we wanted to be VERY safe, a barrier would be good here to make sure output particles have finish reading input particles in
|
||||||
// the update compute. HOWEVER since a NUM_FRAME_BUFFERS frames would have passed by then, we will not insert 1 here.
|
// the update compute. HOWEVER since a NUM_FRAME_BUFFERS frames would have passed by then, we will not insert 1 here.
|
||||||
|
|
Loading…
Reference in New Issue