Stencil no longer works when using Depth PrePass

Hello,

I’m using a Depth PrePass to render all my opaque objects by drawing only the depth before the opaque pass and setting “ZTest” to “Equal” in the shader. However, I’ve encountered an issue where the stencil buffer no longer works properly in this setup because the depth is already written before the stencil operations can occur. Although the hidden objects no longer write to the color buffer, I’m left with an undesired black shadow due to the “ZTest Equal”.

To make the stencil buffer work, I need to write stencil before the Depth PrePass, which results in additional draw calls. Is there a more efficient way to handle both Depth PrePass and stencil operations?

Thank you!