From a0d5e84516919af71654a988ea51af63155c7dd9 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Mon, 13 Apr 2026 13:38:41 +0800 Subject: [PATCH] Render 3DGS debug splats as quads --- MVS/3DGS-D3D12/shaders/DebugPointsPS.hlsl | 19 +++++++++++++++++-- MVS/3DGS-D3D12/shaders/DebugPointsVS.hlsl | 19 +++++++++++++++---- MVS/3DGS-D3D12/src/App.cpp | 13 +++++++++---- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/MVS/3DGS-D3D12/shaders/DebugPointsPS.hlsl b/MVS/3DGS-D3D12/shaders/DebugPointsPS.hlsl index 170deba0..ab37050e 100644 --- a/MVS/3DGS-D3D12/shaders/DebugPointsPS.hlsl +++ b/MVS/3DGS-D3D12/shaders/DebugPointsPS.hlsl @@ -1,4 +1,19 @@ -float4 MainPS(float4 position : SV_Position, float4 color : COLOR0) : SV_Target0 +struct PixelInput { - return color; + float4 position : SV_Position; + float4 color : COLOR0; + float2 localPosition : TEXCOORD0; +}; + +float4 MainPS(PixelInput input) : SV_Target0 +{ + float alpha = exp(-dot(input.localPosition, input.localPosition)); + alpha = saturate(alpha * input.color.a); + + if (alpha < (1.0 / 255.0)) + { + discard; + } + + return float4(input.color.rgb * alpha, alpha); } diff --git a/MVS/3DGS-D3D12/shaders/DebugPointsVS.hlsl b/MVS/3DGS-D3D12/shaders/DebugPointsVS.hlsl index 2a33db89..359fa4c5 100644 --- a/MVS/3DGS-D3D12/shaders/DebugPointsVS.hlsl +++ b/MVS/3DGS-D3D12/shaders/DebugPointsVS.hlsl @@ -17,23 +17,34 @@ struct VertexOutput { float4 position : SV_Position; float4 color : COLOR0; + float2 localPosition : TEXCOORD0; }; VertexOutput MainVS(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID) { - VertexOutput output; + VertexOutput output = (VertexOutput)0; uint splatIndex = gOrderBuffer[instanceId]; PreparedSplatView view = gPreparedViews[splatIndex]; float4 color = UnpackPreparedColor(view); if (view.clipPosition.w <= 0.0) { - output.position = float4(2.0, 2.0, 2.0, 1.0); - output.color = 0.0; + const float nanValue = asfloat(0x7fc00000); + output.position = float4(nanValue, nanValue, nanValue, nanValue); return output; } + float2 quadPosition = float2(vertexId & 1, (vertexId >> 1) & 1) * 2.0 - 1.0; + quadPosition *= 2.0; + + float2 scaledAxis1 = view.axis1 * gSettings.w; + float2 scaledAxis2 = view.axis2 * gSettings.w; + float2 deltaScreenPosition = + (quadPosition.x * scaledAxis1 + quadPosition.y * scaledAxis2) * 2.0 / gScreenParams.xy; + output.position = view.clipPosition; - output.color = float4(color.rgb, 1.0); + output.position.xy += deltaScreenPosition * view.clipPosition.w; + output.color = color; + output.localPosition = quadPosition; return output; } diff --git a/MVS/3DGS-D3D12/src/App.cpp b/MVS/3DGS-D3D12/src/App.cpp index a93f2ec7..b2bc451a 100644 --- a/MVS/3DGS-D3D12/src/App.cpp +++ b/MVS/3DGS-D3D12/src/App.cpp @@ -209,7 +209,7 @@ FrameConstants BuildFrameConstants(uint32_t width, uint32_t height, uint32_t spl constants.settings[0] = static_cast(splatCount); constants.settings[1] = 1.0f; // opacity scale constants.settings[2] = 3.0f; // SH order - constants.settings[3] = 1.0f; + constants.settings[3] = 0.9f; return constants; } @@ -1108,7 +1108,7 @@ bool App::InitializeDebugDrawResources() { GraphicsPipelineDesc pipelineDesc = {}; pipelineDesc.pipelineLayout = m_debugPipelineLayout; - pipelineDesc.topologyType = static_cast(PrimitiveTopologyType::Point); + pipelineDesc.topologyType = static_cast(PrimitiveTopologyType::Triangle); pipelineDesc.renderTargetCount = 1; pipelineDesc.renderTargetFormats[0] = static_cast(Format::R8G8B8A8_UNorm); pipelineDesc.depthStencilFormat = static_cast(Format::D24_UNorm_S8_UInt); @@ -1117,6 +1117,11 @@ bool App::InitializeDebugDrawResources() { pipelineDesc.rasterizerState.cullMode = static_cast(CullMode::None); pipelineDesc.depthStencilState.depthTestEnable = false; pipelineDesc.depthStencilState.depthWriteEnable = false; + pipelineDesc.blendState.blendEnable = true; + pipelineDesc.blendState.srcBlend = static_cast(BlendFactor::One); + pipelineDesc.blendState.dstBlend = static_cast(BlendFactor::InvSrcAlpha); + pipelineDesc.blendState.srcBlendAlpha = static_cast(BlendFactor::One); + pipelineDesc.blendState.dstBlendAlpha = static_cast(BlendFactor::InvSrcAlpha); pipelineDesc.vertexShader.fileName = ResolveShaderPath(L"DebugPointsVS.hlsl").wstring(); pipelineDesc.vertexShader.entryPoint = L"MainVS"; @@ -1908,8 +1913,8 @@ void App::RenderFrame(bool captureScreenshot) { m_commandList.SetPipelineState(m_debugPipelineState); RHIDescriptorSet* debugSets[] = { m_debugDescriptorSet }; m_commandList.SetGraphicsDescriptorSets(0, 1, debugSets, m_debugPipelineLayout); - m_commandList.SetPrimitiveTopology(PrimitiveTopology::PointList); - m_commandList.Draw(1u, m_gaussianSceneData.splatCount, 0u, 0u); + m_commandList.SetPrimitiveTopology(PrimitiveTopology::TriangleStrip); + m_commandList.Draw(4u, m_gaussianSceneData.splatCount, 0u, 0u); if (captureScreenshot) { AppendTrace("RenderFrame: close+execute capture pre-screenshot");