Skip to content

Improve MSAA color resolve when very different samples are merged together #1839

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 9 commits into from
Sep 25, 2020
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -125,6 +125,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Optimized Grain and sRGB Dithering.
- On platforms that allow it skip the first mip of the depth pyramid and compute it alongside the depth buffer used for low res transparents.
- When trying to install the local configuration package, if another one is already present the user is now asked whether they want to keep it or not.
- Improved MSAA color resolve to fix issues when very bright and very dark samples are resolved together.

## [10.0.0] - 2019-06-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,41 @@ Shader "Hidden/HDRP/ColorResolve"
return output;
}

float ResolveWeight(float4 color, float totalSampleCount)
{
const float boxFilterWeight = rcp(totalSampleCount);
float toneMapWeight = rcp(1.0f + Luminance(color.xyz));

return boxFilterWeight * toneMapWeight;
}

float InverseToneMapWeight(float4 color)
{
return rcp(1.0f - Luminance(color.xyz));
}

float4 LoadColorTextureMS(float2 pixelCoords, uint sampleIndex)
{
return LOAD_TEXTURE2D_X_MSAA(_ColorTextureMS, pixelCoords, sampleIndex);
}

float4 Resolve(Varyings input, uint sampleCount)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
int2 pixelCoords = int2(input.texcoord);

float4 finalVal = 0;
for (int i = 0; i < sampleCount; ++i)
{
float4 currSample = (LoadColorTextureMS(pixelCoords, i));
finalVal += currSample * ResolveWeight(currSample, sampleCount);
}

finalVal.xyz *= InverseToneMapWeight(finalVal);

return float4(finalVal.rgb, 1.0f);
}

float4 Frag1X(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
Expand All @@ -47,28 +77,19 @@ Shader "Hidden/HDRP/ColorResolve"

float4 Frag2X(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
int2 pixelCoords = int2(input.texcoord);
return FastTonemapInvert((FastTonemap(LoadColorTextureMS(pixelCoords, 0)) + FastTonemap(LoadColorTextureMS(pixelCoords, 1))) * 0.5f);
return Resolve(input, 2);
}

float4 Frag4X(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
int2 pixelCoords = int2(input.texcoord);
return FastTonemapInvert((FastTonemap(LoadColorTextureMS(pixelCoords, 0)) + FastTonemap(LoadColorTextureMS(pixelCoords, 1))
+ FastTonemap(LoadColorTextureMS(pixelCoords, 2)) + FastTonemap(LoadColorTextureMS(pixelCoords, 3))) * 0.25f);
return Resolve(input, 4);
}

float4 Frag8X(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
int2 pixelCoords = int2(input.texcoord);
return FastTonemapInvert((FastTonemap(LoadColorTextureMS(pixelCoords, 0)) + FastTonemap(LoadColorTextureMS(pixelCoords, 1))
+ FastTonemap(LoadColorTextureMS(pixelCoords, 2)) + FastTonemap(LoadColorTextureMS(pixelCoords, 3))
+ FastTonemap(LoadColorTextureMS(pixelCoords, 4)) + FastTonemap(LoadColorTextureMS(pixelCoords, 5))
+ FastTonemap(LoadColorTextureMS(pixelCoords, 6)) + FastTonemap(LoadColorTextureMS(pixelCoords, 7))) * 0.125f);
return Resolve(input, 8);
}

ENDHLSL
SubShader
{
Expand Down