Skip to content

Commit 3b8dcf3

Browse files
Fix MSAA resolve of stencil buffer (#6251)
* Fix resolve * changelog Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent cb7d441 commit 3b8dcf3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3030
- Fixed rendertarget ColorMask in Forward with virtual texturing and transparent motion vectors.
3131
- Fixed light unit conversion after changing mid gray value.
3232
- Fixed Focus distance in path traced depth of field now takes into account the focus mode setting (volume vs camera).
33+
- Fixed stencil buffer resolve when MSAA is enabled so that OR operator is used instead of picking the last sample.
3334

3435
### Changed
3536
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.

com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ResolveStencilBuffer.compute

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID,
4747
{
4848
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadID.z);
4949

50-
// The best shot at resolving is being overly conservative, hence the OR operator. This is by nature inaccurate.
50+
// The best shot at resolving is being overly conservative, hence the OR operator. This is by nature inaccurate, but there is no way to blend MSAA sub-samples properly and we need to pick the lesser evil.
5151
uint resolvedStencil = 0;
5252

5353
if (dispatchThreadID.x < (uint)_ScreenSize.x && dispatchThreadID.y < (uint)_ScreenSize.y)
@@ -61,7 +61,7 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID,
6161
#else
6262
sampledStencil = LOAD_TEXTURE2D_X_MSAA(_StencilTexture, dispatchThreadID.xy, i);
6363
#endif
64-
resolvedStencil = GetStencilValue(sampledStencil);
64+
resolvedStencil |= GetStencilValue(sampledStencil); // In not MSAA cases the | is the same as assigning given that NUM_SAMPLES is 1
6565
}
6666
}
6767
#ifdef RESOLVE

0 commit comments

Comments
 (0)