Skip to content

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

Merged
merged 11 commits into from
Oct 20, 2020
Merged

Conversation

anisunity
Copy link
Contributor

@anisunity anisunity commented Sep 22, 2020

  • Added a rough distortion frame setting and and info box on distortion materials (On the Frame settings, disabled by default)
  • Added tests to cover the new feature.
    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

@github-actions
Copy link

It appears that you made a non-draft PR!
Please convert your PR to draft (button on the right side of the page)
and cancel any jobs that started on Yamato.
See the PR template for more information.
Thank you!

Copy link
Contributor

@JulienIgnace-Unity JulienIgnace-Unity left a 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.

@anisunity
Copy link
Contributor Author

Fixed both @JulienIgnace-Unity

@sebastienlagarde sebastienlagarde changed the title Planar and Distortion optimizations Distortion optimizations [Thinking] Oct 6, 2020
@sebastienlagarde sebastienlagarde removed the request for review from a team October 6, 2020 13:40
@anisunity anisunity force-pushed the HDRP/SmoothDistortionSmoothPlanar branch from 58e7c4d to c13117e Compare October 13, 2020 10:43
// 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)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
else
{
distortionColorPyramid = currentColorPyramid;
Copy link
Contributor

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?

Copy link
Contributor Author

@anisunity anisunity Oct 13, 2020

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
Copy link
Contributor

@JulienIgnace-Unity JulienIgnace-Unity Oct 13, 2020

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.

Copy link
Contributor Author

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor

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).

Copy link
Contributor

@sebastienlagarde sebastienlagarde Oct 14, 2020

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.

Copy link
Contributor

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);

Copy link
Contributor

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

Copy link
Contributor Author

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

@anisunity anisunity force-pushed the HDRP/SmoothDistortionSmoothPlanar branch from 0af937f to b74efdb Compare October 14, 2020 08:55
@sebastienlagarde sebastienlagarde changed the title Distortion optimizations [Thinking] Distortion optimizations Oct 14, 2020
@anisunity anisunity force-pushed the HDRP/SmoothDistortionSmoothPlanar branch from 8def4b3 to e07a704 Compare October 15, 2020 13:32
… materials.

Proper support for the migration process
Chaging the default value for rough distortion frame setting
SSR now uses the pre-refraction color pyramid.
@anisunity anisunity force-pushed the HDRP/SmoothDistortionSmoothPlanar branch from df17c3c to cc24358 Compare October 15, 2020 16:37
@sebastienlagarde sebastienlagarde changed the base branch from HDRP/staging to master October 19, 2020 22:13
@@ -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).
Copy link
Contributor

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.

Copy link
Contributor

@JordanL8 JordanL8 left a 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

@sebastienlagarde sebastienlagarde merged commit ccdccef into master Oct 20, 2020
@sebastienlagarde sebastienlagarde deleted the HDRP/SmoothDistortionSmoothPlanar branch October 20, 2020 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants