From 0ca90a4bd70b58eab29b3aa26aa9ae9492e51302 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 5 Nov 2023 19:51:23 -0800 Subject: [PATCH] bugfix: resolve ghost particles Signed-off-by: Michael Pollind --- HPL2/include/graphics/DrawPacket.h | 3 --- HPL2/resource/translucency_particle.frag.fsl | 2 +- HPL2/sources/graphics/RendererDeferred.cpp | 18 +++++++----------- HPL2/sources/impl/LegacyVertexBuffer.cpp | 3 ++- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/HPL2/include/graphics/DrawPacket.h b/HPL2/include/graphics/DrawPacket.h index 5332a366d..b89407ad6 100644 --- a/HPL2/include/graphics/DrawPacket.h +++ b/HPL2/include/graphics/DrawPacket.h @@ -47,13 +47,10 @@ namespace hpl { return m_unified.m_numIndices; case DrawPacketType::DrawIndvidualBuffers: return m_indvidual.m_numIndices; - default: - break; } return 0; } - static void cmdBindBuffers(Cmd* cmd, ForgeRenderer::CommandResourcePool* resourcePool, DrawPacket* packet); DrawPacket() diff --git a/HPL2/resource/translucency_particle.frag.fsl b/HPL2/resource/translucency_particle.frag.fsl index 4080996ab..c1d223b5a 100644 --- a/HPL2/resource/translucency_particle.frag.fsl +++ b/HPL2/resource/translucency_particle.frag.fsl @@ -60,7 +60,7 @@ float4 PS_MAIN(PsIn In) } } - if(finalColor.a == 0.0) { + if(finalColor.a < 0.01) { discard; } RETURN(finalColor); diff --git a/HPL2/sources/graphics/RendererDeferred.cpp b/HPL2/sources/graphics/RendererDeferred.cpp index 1acf84a98..f35bd676c 100644 --- a/HPL2/sources/graphics/RendererDeferred.cpp +++ b/HPL2/sources/graphics/RendererDeferred.cpp @@ -2433,8 +2433,6 @@ namespace hpl { std::unique_ptr(loadVertexBufferFromMesh("core_5_5_sphere.dae", lVtxFlag)); m_shapePyramid = std::unique_ptr(loadVertexBufferFromMesh("core_pyramid.dae", lVtxFlag)); m_box = std::unique_ptr(loadVertexBufferFromMesh("core_box.dae", lVtxFlag)); - //////////////////////////////////// - // Batch vertex buffer } cRendererDeferred::~cRendererDeferred() { @@ -4608,17 +4606,12 @@ namespace hpl { switch (pMaterial->Descriptor().m_id) { case MaterialID::Translucent: { - // LegacyVertexBuffer::GeometryBinding binding; DrawPacket drawPacket; if (isParticleEmitter) { std::array targets = { eVertexBufferElement_Position, eVertexBufferElement_Texture0, eVertexBufferElement_Color0 }; drawPacket = translucencyItem->ResolveDrawPacket(frame, targets); - if (drawPacket.m_type == DrawPacket::Unknown && drawPacket.numberOfIndecies() == 0) { - break; - } - } else { std::array targets = { eVertexBufferElement_Position, eVertexBufferElement_Texture0, @@ -4626,11 +4619,13 @@ namespace hpl { eVertexBufferElement_Texture1Tangent, eVertexBufferElement_Color0 }; drawPacket = translucencyItem->ResolveDrawPacket(frame, targets); - if (drawPacket.m_type == DrawPacket::Unknown && drawPacket.numberOfIndecies() == 0) { - break; - } + } + if (drawPacket.m_type == DrawPacket::Unknown || + drawPacket.numberOfIndecies() == 0) { + break; } + uint32_t instance = cmdBindMaterialAndObject( frame.m_cmd, frame, pMaterial, translucencyItem, std::optional{ pMatrix ? *pMatrix : cMatrixf::Identity }); materialConst.objectId = instance; @@ -4657,7 +4652,8 @@ namespace hpl { DrawPacket::cmdBindBuffers(frame.m_cmd, frame.m_resourcePool, &drawPacket); materialConst.m_options = (isFogActive ? TranslucencyFlags::UseFog : 0) | - (isRefraction ? TranslucencyFlags::UseRefractionTrans : 0) | translucencyBlendTable[pMaterial->GetBlendMode()]; + (isRefraction ? TranslucencyFlags::UseRefractionTrans : 0) | + translucencyBlendTable[pMaterial->GetBlendMode()]; cmdBindPushConstants(frame.m_cmd, m_materialRootSignature.m_handle, materialObjectIndex, &materialConst); cmdDrawIndexed(frame.m_cmd, drawPacket.numberOfIndecies(), 0, 0); diff --git a/HPL2/sources/impl/LegacyVertexBuffer.cpp b/HPL2/sources/impl/LegacyVertexBuffer.cpp index 03a7facfd..fe9c3b55f 100644 --- a/HPL2/sources/impl/LegacyVertexBuffer.cpp +++ b/HPL2/sources/impl/LegacyVertexBuffer.cpp @@ -540,7 +540,8 @@ namespace hpl { stream.m_offset = found->m_activeCopy * found->m_shadowData.size(); stream.m_stride = found->Stride(); } - uint32_t numIndecies = (GetRequestNumberIndecies() > 0) ? GetRequestNumberIndecies() : static_cast(m_indices.size()) ; + const int requestNumIndecies = GetRequestNumberIndecies(); + const uint32_t numIndecies = (requestNumIndecies >= 0) ? requestNumIndecies : static_cast(m_indices.size()) ; packet.m_indvidual.m_indexStream.m_offset = m_indexBufferActiveCopy * m_indices.size() * sizeof(uint32_t); packet.m_indvidual.m_numIndices = numIndecies; packet.m_indvidual.m_indexStream.buffer = &m_indexBuffer;