-
Notifications
You must be signed in to change notification settings - Fork 840
Distortion optimizations #1961
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
Distortion optimizations #1961
Conversation
It appears that you made a non-draft PR! |
com.unity.render-pipelines.high-definition/Runtime/Material/GGXConvolution/IBLFilterGGX.cs
Outdated
Show resolved
Hide resolved
...nity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seem to be an implementation mistake in the render graph path.
Fixed both @JulienIgnace-Unity |
58e7c4d
to
c13117e
Compare
// because the output texture is imported from outside of render graph (as it is persistent) | ||
// and in this case the pass is considered as having side effect and cannot be culled. | ||
if (isPreRefraction) | ||
if (!isPreRefraction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic here is becoming too complicated IMO.
We have logic outside the function (cf above RenderDistorsion) and also insde the function.
In term of RenderGraph logic, GenerateColorPyramid should do just what it says it does and all logic calling it or not should be outside. I think this would make things much clearer here (both on caller side, and inside the function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
else | ||
{ | ||
distortionColorPyramid = currentColorPyramid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I get it. Here we use the previous pyramid and just read mip 0 for smooth disto right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if smooth, we do not read the previous color pyramid, we copy the color buffer into an other buffer to use it as an input and an output
}); | ||
GenerateColorPyramid(m_RenderGraph, hdCamera, colorBuffer, distortionColorPyramid, false); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't ever use currentColorPyramid after this code so we could just skip the else statement and store result of first branch in currentColorPyramid if needed by rough disto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
TextureHandle distortionColorPyramid; | ||
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Distortion) && hdCamera.frameSettings.IsEnabled(FrameSettingsField.RoughDistortion)) | ||
{ | ||
distortionColorPyramid = m_RenderGraph.CreateTexture( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to note here.
Before those changes, I think we'd just use a double buffered history pyramid from the hdCamera.
Here we create a new one. Since we have no other (I think) textures with mips in the pipeline, this will actually allocate more memory than before. Can't we just reuse one of the history buffers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed, not relevant in this case
@@ -12,6 +12,8 @@ Shader "Hidden/HDRP/ApplyDistortion" | |||
#pragma only_renderers d3d11 playstation xboxone vulkan metal switch | |||
#pragma editor_sync_compilation | |||
|
|||
#pragma multi_compile _ SMOOTH_DISTORTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change for a dynamic branch , no need for more variant here given the cost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue that this is a pretty simple shader here. Compilation cost is probably meaningless and maintenance complexity is very low so might as well have the most performant code (even if it's just a tiny bit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no perf improvement here, but I think the
CoreUtils.SetKeyword(context.cmd, "SMOOTH_DISTORTION", data.smoothDistortion);
could easily pollute the global space, so better so keep everything simple for such cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side note: use saturate (free) and not clamp (min / max ALU) for clamp(distortionBlur, 0.0, 1.0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and if you want to avoid branch at all you can do
float mip = (_ColorPyramidLodCount - 1) * clamp(distortionBlur, 0.0, 1.0);
=> float mip = (_ColorPyramidLodCount - 1) * saturate(distortionBlur) * RoughDistortion;
with RoughDistortion == 0 if smooth
it cost just an extra mul
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All done, relaunching the tests locally and pushing
0af937f
to
b74efdb
Compare
8def4b3
to
e07a704
Compare
… materials. Proper support for the migration process Chaging the default value for rough distortion frame setting SSR now uses the pre-refraction color pyramid.
df17c3c
to
cc24358
Compare
com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md
Outdated
Show resolved
Hide resolved
@@ -205,6 +205,14 @@ HDRP, being a high-end modern renderer, contains a lot of compute shader passes. | |||
|
|||
Planar reflection probe filtering is a process that combines the result of planar reflection and surfaces smoothness. Up until this version, the implementation for planar reflection probe filtering did not always produce results of fantastic quality. This version of HDRP includes a new implementation that is closer to being physically-based and improves on the image quality significantly. | |||
|
|||
### Screen space reflection | |||
|
|||
[Screen Space Reflection](Override-Screen-Space-Reflection.md) effect always use the color pyramid generate after the Before Refraction transparent pass. Thus the color buffer only includes transparent GameObjects that use the **BeforeRefraction** [Rendering Pass](Surface-Type.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Screen Space Reflection now uses the color pyramid HDRP generates after the Before Refraction transparent pass. This means the color buffer only includes transparent GameObjects that use the BeforeRefraction Rendering Pass.
com.unity.render-pipelines.high-definition/Documentation~/whats-new-10-0.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded a few bits
Did the rendergraph support.
Tested locally, all the test were green except an unrelated one.
I added one new tests to cover the feature.
Made sure that the rough distortion was unchked by default.
Made sure that the info message only displayed when distortion was checked.
Made sure when checked the distortion only did the offset part.
Made sure when unchked, the other color pyramid was not built