Search Issue Tracker
By Design
Votes
3
Found in [Package]
7.5.1
Issue ID
1321988
Regression
No
[URP] Overlay Stack Camera causes all stencil tests to pass when custom post effects are used
Reproduction steps:
1. Open the attached project ("stencilPostEffectTest.zip")
2. Open the "SampleScene" scene
3. Select StackCamera Game object and enable Camera component
4. Open the Game window
Expected result: Only the left cube is red
Actual result: Everything in the game window is red
Reproducible with: URP 7.5.1, 12.0.0 (2019.4.24f1, 2020.3.4f1, 2021.1.3f1, 2021.2.0a12)
Could not test with: 2018.4.33f1 (URP not available)
-
Jar_Coding
Aug 07, 2023 06:29
Can you please add an working example here or to the documentation. Because noone but the author has access to the stencilPostEffectTest.zip and therefore its hard to follow.
We currently have a similar problem and the issue here is almost the same.
-
MasayaTakahashiDayo
Jun 29, 2021 06:25
Thank you for telling me the detailed solution.
I appreciate it very much.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- "Problem detected while importing the Prefab file" errors on Learning Templates import
- Crash on RaiseException during Socket.BeginConnect in Player when application connection is blocked through commercial firewall
- Decal Projector produces artifacts when the normal and decal are projected in negative z-direction and Normal Blend is set to 1
- Undoing slider field change only resets slider position, doesn't undo the value change
- Precision changes when a tangent is added to a Vertex node
Resolution Note:
First off, blit should not be used with the same target for both source and destination. But the actual issue here is depth not getting bound properly. This happens because using an overlay camera causes URP to create a depth texture rather than using one that is implicitly created with the backbuffer, and that makes it incompatible with Blit. This is because Blit has no way to specify a separate depth texture, but will only use one if it's implicitly created with the source texture.
In this case, the supplied StencilTestShader doesn't read from the source, and so it does not have to use Blit. Instead, you can draw a full-screen triangle like this:
var camera = renderingData.cameraData.camera;
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, stencilTestMaterial);
cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
This doesn't touch the currently bound render targets, so the stencil buffer stays bound, and makes the post-process effect work correctly.