From a523dd41c8cd9be8f75c870819545cea9cd2c5e0 Mon Sep 17 00:00:00 2001 From: Jaswant Panchumarti <jaswant.panchumarti@kitware.com> Date: Fri, 21 Feb 2025 14:21:17 -0500 Subject: [PATCH] Clear the ids attachment in vtkWebGPURenderer::Clear - This commit adds an additional Ids attachment to the render pass and updates the shader program which renders the "background" color to zero-initialize the Ids attachment --- Rendering/WebGPU/vtkWebGPURenderer.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Rendering/WebGPU/vtkWebGPURenderer.cxx b/Rendering/WebGPU/vtkWebGPURenderer.cxx index 60e6b369cb8..713af05a835 100644 --- a/Rendering/WebGPU/vtkWebGPURenderer.cxx +++ b/Rendering/WebGPU/vtkWebGPURenderer.cxx @@ -53,13 +53,15 @@ const char* backgroundShaderSource = R"( @builtin(position) position: vec4<f32> }; struct FragmentOutput { - @location(0) color: vec4<f32> + @location(0) color: vec4<f32>, + @location(1) ids: vec4<u32>, }; @fragment fn fragmentMain() -> FragmentOutput { var output: FragmentOutput; output.color = vec4<f32>(1, 1, 1, 1); + output.ids = vec4<u32>(0u); return output; } )"; @@ -207,6 +209,11 @@ void vtkWebGPURenderer::Clear() blendState->alpha.dstFactor = wgpu::BlendFactor::Zero; } } + // Prepare selection ids output. + bkgPipelineDescriptor.cTargets[1].format = + wgpuRenderWindow->GetPreferredSelectorIdsTextureFormat(); + bkgPipelineDescriptor.cFragment.targetCount++; + bkgPipelineDescriptor.DisableBlending(1); const auto pipelineKey = wgpuPipelineCache->GetPipelineKey(&bkgPipelineDescriptor, backgroundShaderSource); wgpuPipelineCache->CreateRenderPipeline(&bkgPipelineDescriptor, this, backgroundShaderSource); @@ -250,7 +257,8 @@ void vtkWebGPURenderer::RecordRenderCommands() if (auto* wgpuRenderWindow = vtkWebGPURenderWindow::SafeDownCast(this->RenderWindow)) { vtkWebGPURenderPassDescriptorInternals renderPassDescriptor( - { wgpuRenderWindow->GetOffscreenColorAttachmentView() }, + { wgpuRenderWindow->GetOffscreenColorAttachmentView(), + wgpuRenderWindow->GetHardwareSelectorAttachmentView() }, wgpuRenderWindow->GetDepthStencilView(), /*clearColor=*/false, /*clearDepth=*/false, /*clearStencil=*/false); renderPassDescriptor.label = "vtkWebGPURenderer::RecordRenderCommands"; -- GitLab