Skip to content
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

[HDRP][Path Tracing] Added proper support for interleaved tiling #5953

Merged
merged 10 commits into from
Oct 20, 2021

Conversation

eturquin
Copy link
Contributor

@eturquin eturquin commented Oct 7, 2021

Modified camera ray generation slightly to accomodate interleaved tiling, following an internal request from Verticals.

@github-actions
Copy link

github-actions bot commented Oct 7, 2021

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://unity-ci.cds.internal.unity3d.com/project/902/
Search for your PR branch using the search bar at the top, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

HDRP
/jobDefinition/.yamato%2Fall-hdrp.yml%23HDRP_trunk
With changes to HDRP packages, you should also run
/jobDefinition/.yamato%252Fall-lightmapper.yml%2523PR_LightMapper_trunk

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@eturquin eturquin changed the title [HDRP][Path Tracing] Added support for interleaved tiling [HDRP][Path Tracing] Added proper support for interleaved tiling Oct 7, 2021
@github-actions
Copy link

github-actions bot commented Oct 7, 2021

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

@eturquin
Copy link
Contributor Author

eturquin commented Oct 8, 2021

Btw, @patrickp-unity3d: I'd be tempted to include the pixel offset directly into the code, so that you don't have to shift the viewproj matrix for each tile, the way you do in raster. This way, it'd actually become a ready-to-use solution for anyone to render ultra-high res images, where you just render the exact same image several times, only changing the path-tracer tiling parameters. And we could add support for it in the recorder too (@pmavridis). Would it be a huge deal to add a condition in your code, so that the matrix modifications would only be applied in raster mode?

@patrickp-unity3d
Copy link
Contributor

patrickp-unity3d commented Oct 8, 2021

Btw, @patrickp-unity3d: I'd be tempted to include the pixel offset directly into the code, so that you don't have to shift the viewproj matrix for each tile, the way you do in raster. This way, it'd actually become a ready-to-use solution for anyone to render ultra-high res images, where you just render the exact same image several times, only changing the path-tracer tiling parameters. And we could add support for it in the recorder too (@pmavridis). Would it be a huge deal to add a condition in your code, so that the matrix modifications would only be applied in raster mode?

I think as long as we keep tileindex and tilecount as our agreed interface, and as long as I can still offset the viewproj in raster, I I can have a condition in the code to fork between both logic. I already have a LOT of branching for all the various HDRP features that we're trying to support under a single roof. ;)

I honestly prefer what is best for HDRP. And if this improves HDRP, I'm happy we're contributing.

If anyone wants my output pixel reordering shader that we run after rendering let me know.

@eturquin
Copy link
Contributor Author

eturquin commented Oct 8, 2021

I think as long as we keep tileindex and tilecount as our agreed interface, and as long as I can still offset the viewproj in raster, I I can have a condition in the code to fork between both logic. I already have a LOT of branching for all the various HDRP features that we're trying to support under a single roof. ;)

Cool, I'll add that then, so that we have a self-contained solution. :)

If anyone wants my output pixel reordering shader that we run after rendering let me know.

We may! @sebastienlagarde, @pmavridis, what do you guys think?

@patrickp-unity3d
Copy link
Contributor

patrickp-unity3d commented Oct 8, 2021

I think as long as we keep tileindex and tilecount as our agreed interface, and as long as I can still offset the viewproj in raster, I I can have a condition in the code to fork between both logic. I already have a LOT of branching for all the various HDRP features that we're trying to support under a single roof. ;)

Cool, I'll add that then, so that we have a self-contained solution. :)

If anyone wants my output pixel reordering shader that we run after rendering let me know.

We may! @sebastienlagarde, @pmavridis, what do you guys think?

It's just a simple blit material that undoes the interleaving: https://github.com/Unity-Technologies/RenderStudio-Dev/blob/master/Packages/com.unity.industrial.renderstudio/Runtime/Resources/unity.industrial.renderstudio/Graphics/Untiling.shader

            // Unity builtin, size of the given texture
            float4 _MainTex_TexelSize;

            // source texture
            Texture2D _MainTex;
            SamplerState my_point_clamp_sampler;

            float _TileCount;

            float4 Frag(Varyings input) : SV_Target
            {
                float2 texcoord = input.texcoord.xy;

                uint tileCount = _TileCount;
                int pixelX = texcoord.x * _MainTex_TexelSize.z;
                int pixelY = texcoord.y * _MainTex_TexelSize.w;
                int tileIndexX = tileCount - 1 - (pixelX - (pixelX / tileCount) * tileCount);
                int tileIndexY = tileCount - 1 - (pixelY - (pixelY / tileCount) * tileCount);
                int tileWidth = _MainTex_TexelSize.z / tileCount;
                int tileHeight = _MainTex_TexelSize.w / tileCount;

                float2 origin =
                    float2(tileIndexX * tileWidth + (pixelX + 0.5) / _TileCount,
                           tileIndexY * tileHeight + (pixelY + 0.5) / _TileCount)
                    / float2(_MainTex_TexelSize.z, _MainTex_TexelSize.w);
                return _MainTex.Sample(my_point_clamp_sampler, origin);
            }

image

@patrickp-unity3d
Copy link
Contributor

Actually, @eturquin I think I must use the viewproj matrix because many shaders depend on the screen space position. Chromatic aberration as well as the street in the above image need it to be in full resolution. If I don't offset the viewproj matrix these will not use the correct pixel. Unless I am very wrong, I think we either need to do as discussed originally or permit both strategies.

@eturquin
Copy link
Contributor Author

eturquin commented Oct 9, 2021

Actually, @eturquin I think I must use the viewproj matrix because many shaders depend on the screen space position. Chromatic aberration as well as the street in the above image need it to be in full resolution. If I don't offset the viewproj matrix these will not use the correct pixel. Unless I am very wrong, I think we either need to do as discussed originally or permit both strategies.

Good point, ok I'll revert the latest change, and let the matrix do its work. :)

Copy link
Contributor

@pmavridis pmavridis left a comment

Choose a reason for hiding this comment

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

This change is small and as long as it solves the issues that the verticals team found, I think we should merge it. DoF sampling might require a small change, as noted below.

Copy link
Contributor

@patrickp-unity3d patrickp-unity3d left a comment

Choose a reason for hiding this comment

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

Looks good, I tested depth of field as well (32 samples only)

Here's some detail at the transition (screengrab via Parsec at 150%)
image

some detail of the nice expected noise pattern (screengrab via Parsec at 200%)
image

@eturquin
Copy link
Contributor Author

Looks good, I tested depth of field as well
Here's some detail at the transition (screengrab via Parsec at 150%)

This is the kind of 8x8 grid-aligned artefacts that I would expect with screen-space, post-process DoF (applied on each 8k tile individually). The path-traced DoF should not exhibit such artefacts. Can you confirm which one it was here?

@pmavridis
Copy link
Contributor

pmavridis commented Oct 12, 2021

screen-space, post-process DoF (applied on each 8k tile individually

@patrickp-unity3d Note that you get path traced DoF only if the focus mode is set to "PhysicalCamera". If it's set to "Manual Ranges" then you get the same post-process DoF as rasterization because the path tracer can only compute physically-based DoF.

@patrickp-unity3d
Copy link
Contributor

patrickp-unity3d commented Oct 12, 2021

screen-space, post-process DoF (applied on each 8k tile individually

@patrickp-unity3d Note that you get path traced DoF only if the focus mode is set to "PhysicalCamera". If it's set to "Manual Ranges" then you get the same post-process DoF as rasterization because the path tracer can only compute physically-based DoF.

Correct I used manual ranges since our users generally have a specific 'hero' framing in mind (I don't mind the tiling but you're correct that this isn't the test we wanted)

This is with physical camera and a 4.6m focus distance (should be the test we want) (looks much more like path tracing than post-processing ;) )

(32 samples only)

Out of focus tire vs (mostly) in focus tire (screengrab via Parsec at 150%):
image
image

@eturquin
Copy link
Contributor Author

This is with physical camera and a 4.6m focus distance (should be the test we want) (looks much more like path tracing than post-processing ;) )

Looking good! I say, ship it! ;)

@sebastienlagarde sebastienlagarde merged commit af1b7c0 into master Oct 20, 2021
@sebastienlagarde sebastienlagarde deleted the hd/pt_tiling branch October 20, 2021 08:09
@patrickp-unity3d
Copy link
Contributor

Hi! So if I understand correctly this will be in HDRP 12.2 and 13.2?

@eturquin
Copy link
Contributor Author

Hi! So if I understand correctly this will be in HDRP 12.2 and 13.2?

Yes, in the first patch for 12.2.

sebastienlagarde added a commit that referenced this pull request Oct 20, 2021
* Added ortho cam support, plus raygen refactor.

* Added support for interleaved tiling.

* Added spread angle adjustment.

* Offset tile sub-pixels, instead of relying on proj matrix modifications.

* Undoed last commit.

* Use tiled pixel coords for all things sampling-related (incl. lens).

* Update CHANGELOG.md

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
odbb added a commit that referenced this pull request Oct 20, 2021
* master:
  Add missing shader stages in shader keyword copying  (#6008)
  [Yamato] Add all DX11 job for URP (#6075)
  [HDRP] Add more performance test coverage (#5814)
  Fix templates ISO date (#6073)
  Fix division by 0 when AO is 0 (#6078)
  Fixed grammar errors (#6077)
  [HDRP][Path Tracing] Improved robustness of the stacklit material (#6066)
  [APV] Cell streaming system (#5731)
  Update revision for URP update test project (#6061)
  [HDRP][Path Tracing] Camera ray misses now return a null value with Minimum Depth > 1 (#6067)
  Renable missing test (Lens Flare) (#5456)
  [HDRP][Path Tracing] Added proper support for interleaved tiling (#5953)
  Fix to render depth or depth/normal of waving grass (#4097)
  Remove ScreenSpaceShadowResolvePass (#6002)
  [HDRP][Docs] Update docs with RendererList related option (#6031)
  Layer drawer used in ray/path tracing now matches 100% with camera's. (#5956)
  Fix iridescence tooltip (#5950)
  [HDRP] Change RenderGraph Begin/Execute function pattern to avoid leaks (#5929)
  [HDRP] Fix errors when switching build targets in editor (#5918)
  Generate a material as a subasset for ShaderGraphs (#5795)
sebastienlagarde added a commit that referenced this pull request Oct 21, 2021
* APV: update some tooltips and add a clamp on dilation validity threshold (#6005)

* Tooltip and dilation thresh clamp

* More tooltip grammar

* Small qol (#6036)

* Fix subdiv view (#6033)

* ** Improving FTPL perf on ps4 by .3 ms on average ** (#5866)

* Adding FPTL caching of light volume, adding new conditional for early out of loop and forcing loop to be dynamic

* Early out on the wave itself if we find at least 1 valid light, saves additional 0.05ms

* Fixing some compiler warnings

* Update to HDRP Asset analytics (#6060)

* Updated HDRP analytics

- New version of hdrp usage to better analyse data
- Default values event to populate default values for the dashboard

* Fixed menu item

* Enable iris normal for Eye shader (#5880)

* Enable Iris normal for Eye shader

* categories

* update eye sample

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* [HDRP] Fix errors when switching build targets in editor #5918

* [HDRP] Change RenderGraph Begin/Execute function pattern to avoid leaks (#5929)

* Fix render graph not being executed when an exception is thrown from the graph recording

* Cleanup + doc

* Fix iridescence tooltip (#5950)

* Fix tooltip

* Update Material-Type.md

* Update iridescence-thickness.md

* Update LitSurfaceInputsUIBlock.cs

* Layer drawer used in ray/path tracing now matches 100% with camera's. (#5956)

Please enter the commit message for your changes. Lines starting

* [HDRP][Docs] Update docs with RendererList related option (#6031)

* Update docs with RendererList related option

* Minor edit

* [HDRP][Path Tracing] Added proper support for interleaved tiling (#5953)

* Added ortho cam support, plus raygen refactor.

* Added support for interleaved tiling.

* Added spread angle adjustment.

* Offset tile sub-pixels, instead of relying on proj matrix modifications.

* Undoed last commit.

* Use tiled pixel coords for all things sampling-related (incl. lens).

* Update CHANGELOG.md

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* Renable missing test (Lens Flare) (#5456)

* Renable missing test (Lens Flare)

* Update references images for 4092

Co-authored-by: Sebastien Lagarde <sebastien@unity3d.com>

* [HDRP][Path Tracing] Camera ray misses now return a null value with Minimum Depth > 1 #6067

* [HDRP][Path Tracing] Improved robustness of the stacklit material (#6066)

* Improved robustness of the stacklit material.

* Updated changelog.

* Changed coat normal sample texture from default to normal

* add 5007 stacklit test scene for PT

* added scene to build settings

Co-authored-by: Remi Chapelain <remi.chapelain@unity3d.com>
Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* Fixed grammar errors (#6077)

* Fix division by 0 when AO is 0 (#6078)

* [HDRP] Fix the injection point field not visible in custom pass volumes (#6084)

* Fix custom pass injection point not visible when using the Camera mode.

* updated changelog

Co-authored-by: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com>
Co-authored-by: Kleber Garcia <kleber.garcia@unity3d.com>
Co-authored-by: JulienIgnace-Unity <julien@unity3d.com>
Co-authored-by: Adrien de Tocqueville <adrien.tocqueville@unity3d.com>
Co-authored-by: Antoine Lelievre <antoinel@unity3d.com>
Co-authored-by: Emmanuel Turquin <emmanuel@turquin.org>
Co-authored-by: Pavlos Mavridis <pavlos.mavridis@unity3d.com>
Co-authored-by: skhiat <55133890+skhiat@users.noreply.github.com>
Co-authored-by: Remi Chapelain <remi.chapelain@unity3d.com>
Co-authored-by: emilybrown1 <88374601+emilybrown1@users.noreply.github.com>
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