Skip to content

Fix MSAA resolve of stencil buffer #6251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed rendertarget ColorMask in Forward with virtual texturing and transparent motion vectors.
- Fixed light unit conversion after changing mid gray value.
- Fixed Focus distance in path traced depth of field now takes into account the focus mode setting (volume vs camera).
- Fixed stencil buffer resolve when MSAA is enabled so that OR operator is used instead of picking the last sample.

### Changed
- Use RayTracingAccelerationStructure.CullInstances to filter Renderers and populate the acceleration structure with ray tracing instances for improved CPU performance on the main thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID,
{
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadID.z);

// The best shot at resolving is being overly conservative, hence the OR operator. This is by nature inaccurate.
// 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.
uint resolvedStencil = 0;

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