I Stephane,
That is a good suggestion, however we actually have two opaque and two translucent passes and we want it to work on a per object basis and the custom depth buffer is shared between object from what I can tell, so it gets more complex.
Here is what I ended up doing in case it is useful for someone else. I added a material TranslucencyWritesDepth bool parameter with an override on the material instance as well. Then in BasePassRendering.cpp, I modified the
FMeshPassProcessor* CreateTranslucencyAllPassProcessor(…)
To use:
PassDrawRenderState.SetDepthStencilAccess(FExclusiveDepthStencil::DepthWrite_StencilWrite); PassDrawRenderState.SetDepthStencilState(TStaticDepthStencilState<true, CF_DepthNearOrEqual>::GetRHI());Then in
TranslucencyRendering.cpp
in
RenderTranslucencyViewInner()
I added
if (TranslucencyPass == ETranslucencyPass::TPT_AllTranslucency )
{
PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(SceneDepthTexture, ERenderTargetLoadAction::ELoad, ERenderTargetLoadAction::ELoad, FExclusiveDepthStencil::DepthWrite_StencilWrite);
}
Then in
MeshPassProcessor.inl
in
template<typename PassShadersType, typename ShaderElementDataType>void FMeshPassProcessor::BuildMeshDrawCommands(
I added
PipelineState.BlendState = DrawRenderState.GetBlendState();
if (MeshPassType == EMeshPass::TranslucencyAll || MeshPassType == EMeshPass::TranslucencyEnvironment)
{
if (MaterialResource.IsTranslucencyWritingDepth() && DrawRenderState.GetDepthStencilAccess() == FExclusiveDepthStencil::DepthWrite_StencilWrite)
{
PipelineState.DepthStencilState = TStaticDepthStencilState<true, CF_DepthNearOrEqual>::GetRHI();
}
else
{
PipelineState.DepthStencilState = TStaticDepthStencilState<false, CF_DepthNearOrEqual>::GetRHI();
}
}
else
{
PipelineState.DepthStencilState = DrawRenderState.GetDepthStencilState();
}
There were additional modifications but that was the core of it and we can select which translucent meshes we want to behave this way and which continue to behave as before. Thanks for your help.