Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Showcase [Open Source] Screen Space GBuffer Path Tracing in URP 14

Discussion in 'Universal Render Pipeline' started by wwWwwwW1, Dec 9, 2022.

  1. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hey, I just found out the reason that I cannot add reflection probes fallback to the effect. (currently the probe will be black or grey)

    That's because the current full screen pass renderer feature will always use "Draw Procedural" even if the mode is set to "Blit".
    DrawProcedural.jpg

    URP_ForwardPlus_ReflectionProbes_Update.jpg

    I will test it further once the "Blit" mode works, and I think a box projected probe fallback will greatly improve the stability of this screen space effect.
    FullScreenPass_Blit.jpg
     
    pierre92nicot likes this.
  3. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    The report is confirmed as a duplicate issue of UUM-2631.

    I think it won't be fixed soon, so I tried to manually set reflection probes. (see this thread or this C# script)
    AddProbeSetter.jpg

    If you need to access reflection probes in a URP blit pass, you may try the method mentioned above. Now the effect is much better than before.

    Custom Sky Fallback:
    SkyFallBack.jpg

    [Last Edited] Reflection Probe Fallback: (Probe Intensity set to 0.37)
    ProbeFallBack2.jpg

    [Last Edited] Off-Screen Light Plane:
    EmissionFromReflectionProbe.jpg

    The fall back is not perfect because reflection probes don't capture depth information. But it's enough to provide some off-screen data.

    Reflection Probe Preview Only:
    ProbePreview.jpg
     
    Last edited: Feb 1, 2023
  4. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hi, I added Forward rendering path support to the repository. (URP forces Forward path on OpenGL platforms)

    If you need to render GBuffers (0,1,2) in a Forward path, you can try this renderer feature.
    ForwardGBufferFeature.jpg

    For OpenGL platforms, some extra steps are needed.
    SupportForwardPath.jpg
     
  5. mcstr

    mcstr

    Joined:
    Feb 4, 2016
    Posts:
    2
    amazing project!
     
    wwWwwwW1 likes this.
  6. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hi, I've done many improvements to it since the last post. They can be find in the commits page.

    The biggest improvement is the real-time accumulation (temporal re-projection).
    Real-timeMode.jpg

    Most of the artifacts (weird shadows) are fixed by considering back-face in ray marching. These back-faces reuse the front GBuffer to reduce performance cost.
    Before:
    Before.jpg
    After:
    After.jpg

    The back-face now appears in reflection when "Accurate Thickness" (render back-face depth) is enabled. This may not be 100% correct but looks much better than before (with hole).
    OriginalCornellBox.jpg

    The next steps might be:
    • Move this post-processing effect into object's shader to allow more accurate reflection probe fallback.
    • Further reduce ghosting in real-time accumulation.
    • Move this post-processing effect into object's shader to see if it's possible to support other lighting models (refraction, ...).
     
    Marseol and lilacsky824 like this.
  7. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,622
    nice, very interesting
     
    wwWwwwW1 likes this.
  8. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Hey, I'm still looking for a way that is efficient enough (less draw call & overdraw) to implement per object reflection probe fallback.

    So I added refraction support to it first. To render refractions, objects need to use "Universal Render Pipeline/Screen Space Path Tracing/Refraction Lit" shader graph, which is provided by the repository, and tick "Support Refraction" in the accumulation renderer feature.
    Refraction.jpg

    The idea is similar to layered rendering.

    Details:
    1. Render transparent objects to three transparent GBuffers (0, 1, 2) and write depth to "_CameraDepthAttachment" (camera's depth target).
    2. Render both opaque & transparent objects' back-face depth to "_CameraBackDepthTexture".
    3. [Optional] Render back-face normals (DepthNormals) rather than rendering back-face depth (DepthOnly).

    Now we have these for calculating refractions:
    - "_CameraDepthAttachment": Opaque & Transparent Depth Layer 1
    - "_CameraBackDepthTexture": Opaque & Transparent Depth Layer 2
    - "_CameraDepthTexture": Opaque Depth Layer

    This allows calculating the actual thickness of refracting objects, and find intersections for opaque objects that are covered by them.

    The "_TransparentGBuffer1" (specular.rgb occlusion.a) is used to store index of refraction (ior.r) and surface type (surfaceType.a). The "occlusion.a" for other transparent objects will be 1.0.

    As this effect is based on rasterization, it doesn't support recursive refraction, which means that other refractions cannot be seen in refractions.

    For Unity lights, (shadows) transparency uses dithered transparent shadows.
    Raster_Shadows.jpg

    Only path traced shadows (from indirect lighting, emission, ...) can have things like refraction caustics.
    Green Glass Sphere.jpg

    It's not perfect yet and I think it can be improved later. (URP transparent motion vectors, ...)
     
    Last edited: Apr 19, 2023
    clabbe likes this.
  9. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    I saw a simple but effective open source spatial denoiser on shadertoy, and it works well after porting to URP. It uses different surface data to avoid blurring the edges and colors.

    Now it's possible to use recorder to export videos without setting extremely high SPPs.

    Temporal Denoise Only (TAA + Real-time Accumulation):


    Temporal Spatial Denoise:


    TAA causes severe ghosting, maybe need to find a way to replace it.
     
    Felinde and FunixGames like this.
  10. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    The reflection probe atlas in Forward+ makes accessing all reflection probes in a full screen shader possible. I've tried it and the results were satisfying.

    Forward and Deferred:
    Forward_or_Deferred.jpg

    Forward+:
    Forward+.jpg

    I haven't pulled it to the repo yet because I think it needs more tests and I'm considering downgrading the repo's editor version to 2022 LTS (from 2023.1b).
     
    Felinde likes this.
  11. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    I didn't forget about this repo and it's actually actively developed (when I have time).

    For example, recently I came up with a better way to handle both large and small objects in the same scene.
    Let's divide the total steps (ex. 24) of ray marching into 3 parts (small = 4, medium = 8, large = 12) and marching the ray according to steps order.

    The size of small steps can be set very small (ex. 2 mm) to ensure that ray marching does not miss extremely small objects.

    Medium step size can be set to a larger unit (ex. 2 cm) so that objects can produce reflections & shadows.

    The large steps are used to "fill" the scene and allow rays to travel further. It's set to "0.6 m" in the screenshot below.
    SmallObjects.jpg

    Before and After (small objects):
    before.jpg after.jpg

    This repo is also the foundation of adding a good enough SSGI for URP to me. I wasn't very satisfied with my SSR (based on an early version of this SSPT), so I decided to spend more time improving this (ex. the most important denoise) first before starting to add SSGI.
     
    impheris and mgear like this.
  12. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,622
    looks amazing but for some reason the gray book looks off...
     
    wwWwwwW1 likes this.
  13. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    761
    Thanks for pointing it out! Do you mean the blue gray book in the first screenshot?

    I increased the total steps (low: 24 → medium: 48) to test if it's relevant, and found that it's because of the lack of information in screen space (being occluded).
    SmallObjects2.jpg

    It could be improved if there was a way to render more layers of depth, but I doubt it's worth it in terms of performance. Another solution might be to use inline ray tracing, but obviously it's not the time yet. (Vulkan inline ray tracing in URP)
     
    impheris likes this.