Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Showcase Community FSR support for the Built-In Renderer

Discussion in 'General Graphics' started by tatoforever, Aug 4, 2021.

  1. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    Sorry for a probably-dumb question, but how do you add this new effect to the PPV2 stack? It's not listed when I try to add a new effect (only shows Unity and Psychose, which only has the original FSR effect). (And also, what's your GPU that the water ocean scene is just 3ms!?)
     
  2. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    390
    hi sorry I should have been clearer. Firstly, a disclaimer: This is strictly a proof-of-concept only, I hope this is correct but it might not be

    My hacky strategy to get this working in the PPV2 stack is essentially as follows:
    As a base, use AMD_FIDELITY_FX_FSR_ALTERNATIVE as provided by @atomicjoe I then modified this code so that the output rendertexture is available to a new custom PPV2 "effect" which all it does is blit in this rendertexture:

    in a new file AUX_FX_FSR_STACK.cs I used the following hacky code:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.Rendering.PostProcessing;
    4.  
    5. namespace AMD_FIDELITY_FX
    6. {
    7.     [Serializable]
    8.     [PostProcess(typeof(AUX_FX_FSR_STACK_Renderer), PostProcessEvent.BeforeStack,
    9.         "Psychose Interactive/AMD Fidelity FX/FSR AUX")]
    10.     public sealed class AUX_FX_FSR_STACK : PostProcessEffectSettings
    11.     {
    12.        
    13.     }
    14.  
    15.     public sealed class AUX_FX_FSR_STACK_Renderer : PostProcessEffectRenderer<AUX_FX_FSR_STACK>
    16.     {
    17.         static public RenderTexture superSampledOutput;
    18.  
    19.         public override void Render(PostProcessRenderContext context)
    20.         {
    21.             if (superSampledOutput!=null) {
    22.                 context.command.BlitFullscreenTriangle(superSampledOutput, context.destination, false, new Rect(0f, 0f, context.camera.pixelWidth, context.camera.pixelHeight));
    23.             }
    24.         }
    25.     }
    26. }
    I then tweaked the end of AMD_FIDELITY_FX_FSR_ALTERNATIVE.cs Initialize() to add in:
    Code (CSharp):
    1. AMD_FIDELITY_FX.AUX_FX_FSR_STACK_Renderer.superSampledOutput = superSampledOutput;
    Then, I set up the "real" camera with a PPV2 layer for antialiasing only:

    upload_2021-10-8_17-50-16.png

    The FidelityFX screen output camera which the AMD_FIDELITY_FX_FSR_ALTERNATIVE.cs creates I then added a layer with normal post-processing settings but no AA, and disabled the AUX_FSR script.

    The net effect, as I understand it is as follows:

    on the main camera, the AMD_FIDELITY_FX_FSR_ALTERNATIVE.cs script retargets the camera to rendertexture which is smaller than the monitor output, dynamic resolution can work on a rendertexture but not without. PPV2 then runs to perform e.g. SMAA only at this scale. Then AMD_FIDELITY_FX_FSR_ALTERNATIVE.cs runs the fidelity fx to a new, larger rendertexture.

    PPV2 runs on the aux camera, and via the hacky PPV2 effect draws the larger rendertexture, then applies whatever PPV2 effect you add in.

    Phew!

    regards the 3ms time I wouldnt trust that too much. I am on a 1070 mobile, but when I captured the screenshot I had downsampling on the fidelityfx at 2. Therefore for a 4k screen it is only actually rendering at 1080p before upscaling. This is the most severe quality reduction fidelityfx recommends.

    I hope this helps, good luck!
     
    atomicjoe likes this.
  3. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    390
    addendum in case anyone come back to this. My approach outlined above has a reasonably significant flaw. The problem is that the camera depth buffer and motion vectors are not preserved through the upsampling method to the post processing effects running afterwards. This means that post processing effects which depend on these, notably:

    depth-of-field
    motion blur
    screen space reflections
    ambient obscurance

    will not work correctly. Ideally there would be a way to pass this information through e.g. via the compute shader however at the moment I am not sure how to do this. My plan is to move these effects (where used) to run on the camera prior to upsampling which is not ideal but I think will probably look OK.
     
  4. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
    The PPV2 version only seems to be working in Unity 2021.2 (at least in the version I used) and not in 2020.3. I'll let you guys know if I can make it work in 2020

    EDIT: Stupid update: Disregard my message, since Dynamic Resolution only works in DX12 you have to have your project in dx12...
     
    Last edited: Dec 17, 2021
    atomicjoe likes this.
  5. TanselAltinel

    TanselAltinel

    Joined:
    Jan 7, 2015
    Posts:
    190
    I suppose this wouldn't work on Android VR, right?

    Well, turns out it works, but it only renders at the lower left corner, lol. Same dynamic resolution bug for HDRP/DLSS
     
  6. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    153
    I don't suppose anyone figured out a workaround to get this working on Mac/Metal?
     
  7. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,834
    I don't have a Mac to try but it should work on metal: it's working even on Android OpenGLES3
    Is it throwing errors?
    Does metal support compute shaders?
     
  8. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    153
    No errors, just a black screen like the @sameng was seeing. Metal definitely supports compute shaders as I'm using GPU Instancer with no issues.
     
  9. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,834
    I'm afraid I can't help with that since I don't have a Mac. :(
     
  10. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
    I suppose asking for a FSR 2.0 version would be too much?;)
     
  11. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,834
    It hasn't been open sourced yet.
     
  12. blueivy

    blueivy

    Joined:
    Mar 4, 2013
    Posts:
    614
  13. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
  14. roundyyy

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    110
    Amazing work! Would it be hard to add single pass VR support on shaders?
     
  15. albertputinjobs

    albertputinjobs

    Joined:
    Jan 10, 2021
    Posts:
    8
    I am a noob looking to increase fps in builtin renderer can someone explain me how to use FSR to get more fps in editor ?
     
    Alterego-Games likes this.
  16. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
    Our FSR 2 asset in the unity store is fully documented with detailed explanation!
     
  17. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,834
    mgear and Unifikation like this.
  18. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
    atomicjoe likes this.
  19. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,834
    That's not a bug, it's a FEATURE! :D
     
    Alterego-Games likes this.
  20. Alterego-Games

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    261
    Well personally I think my version is better;) I'm constantly improving it's usability. Its not free, but I'm giving almost real-time support for it:).

    I'm also updating my FSR 2 asset with a fallback FSR 1 option for BIRP (free update). Which will also inject FSR 1 the way it's supposed too.

    @sameng I did find out why this asset isn't working for Metal on MacOS and fixed it, so if you're still looking for FSR 1, it'll be included in my FSR 2 asset soon!

    https://assetstore.unity.com/packages/tools/utilities/fsr-2-upscaling-for-unity-252172

    FSR 1 Performance 1920x1080 running @ 960x540 not as good as FSR 2, but still quite good and much cheaper on the GPU (also for mobiles!):
    Screenshot 2023-09-01 at 16.43.12.png
     
    atomicjoe and blueivy like this.