diff --git a/Hydrogent/include/HnRendererImpl.hpp b/Hydrogent/include/HnRendererImpl.hpp index 63d3a00a..88b0b053 100644 --- a/Hydrogent/include/HnRendererImpl.hpp +++ b/Hydrogent/include/HnRendererImpl.hpp @@ -106,6 +106,7 @@ class HnRendererImpl final : public ObjectBase pxr::HdRenderPassSharedPtr m_GeometryPass; RefCntAutoPtr m_MeshIdTexture; + RefCntAutoPtr m_DepthBuffer; GPUCompletionAwaitQueue> m_MeshIdReadBackQueue; }; diff --git a/Hydrogent/src/HnRendererImpl.cpp b/Hydrogent/src/HnRendererImpl.cpp index 887f0eea..8cb9891f 100644 --- a/Hydrogent/src/HnRendererImpl.cpp +++ b/Hydrogent/src/HnRendererImpl.cpp @@ -381,12 +381,26 @@ void HnRendererImpl::RenderPrimId(IDeviceContext* pContext, ITextureView* pDepth TexDesc.MipLevels = 1; m_MeshIdTexture = m_Device.CreateTexture(TexDesc, nullptr); + + if (m_Device.GetDeviceInfo().IsGLDevice()) + { + // We can't use the default framebuffer's depth buffer with our own render target, + // so we have to create a copy. + m_DepthBuffer.Release(); + auto DepthDescCopy = DepthDesc; + DepthDescCopy.Name = "Depth buffer copy"; + m_DepthBuffer = m_Device.CreateTexture(DepthDescCopy, nullptr); + } } + if (m_DepthBuffer) + pDepthBuffer = m_DepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); ITextureView* pRTVs[] = {m_MeshIdTexture->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET)}; pContext->SetRenderTargets(_countof(pRTVs), pRTVs, pDepthBuffer, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); float ClearColor[] = {0, 0, 0, 0}; pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + if (m_DepthBuffer) + pContext->ClearDepthStencil(pDepthBuffer, CLEAR_DEPTH_FLAG, 1.f, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); const auto& Meshes = m_RenderDelegate->GetMeshes(); if (Meshes.empty()) diff --git a/PBR/src/PBR_Renderer.cpp b/PBR/src/PBR_Renderer.cpp index 9e965b47..08ec9df0 100644 --- a/PBR/src/PBR_Renderer.cpp +++ b/PBR/src/PBR_Renderer.cpp @@ -768,11 +768,11 @@ void PBR_Renderer::CreatePSO(IRenderDevice* pDevice, IRenderStateCache* pStateCa } PSOCreateInfo.pPS = pMeshIdPS; - PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE; + PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; m_MeshIdPSO[0] = Device.CreateGraphicsPipelineState(PSOCreateInfo); - PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_BACK; + PSOCreateInfo.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE; m_MeshIdPSO[1] = Device.CreateGraphicsPipelineState(PSOCreateInfo); }