Search Unity

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,241
    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:
    400
    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:
    400
    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:
    354
    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:
    160
    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,869
    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:
    160
    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,869
    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:
    354
    I suppose asking for a FSR 2.0 version would be too much?;)
     
  11. atomicjoe

    atomicjoe

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

    blueivy

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

    Alterego-Games

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

    roundyyy

    Joined:
    Dec 23, 2019
    Posts:
    112
    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:
    354
    Our FSR 2 asset in the unity store is fully documented with detailed explanation!
     
  17. atomicjoe

    atomicjoe

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

    Alterego-Games

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

    atomicjoe

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

    Alterego-Games

    Joined:
    Jul 13, 2015
    Posts:
    354
    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
     
    AlejMC, atomicjoe and blueivy like this.
  21. AlejMC

    AlejMC

    Joined:
    Oct 15, 2013
    Posts:
    149
    You guys are definitely at a completely different level on this…
    Got a few questions if you don’t mind me, I’m mostly interesting in mobile endeavors for the time being, making FSR1 the sensible choice I believe.

    Does this one happens to have support too for FSR1? As in, does FSR2+ also provides FSR1?
    Skimming by I also see that it has support for every render pipeline including PostProcessingStack V2, is it possible to control exactly the ordering of when it happens?

    This seems like a great asset overall, definitely interested in FSR2+ with the added benefit that it also has FSR1!
    Same question, is it possible to order it when it happens freely?

    ————
    The reason for the ordering question (and correct me if it is a fruitless idea) is that a lot of the costs on the frame do come from trying to do fancy post processing.
    While we have optimized as much as we can, starting the post processing from a higher base render target resolution (whether natively rendered as such or upscaled) would be shooting ourselves in the foot.
    I’m hoping to somehow put it at the end of it all, or at least after the more expensive ones (AO, Bloom, etc) and hope for the best.

    So, onto a few questions, if time permits:
    1. Is it possible to move the rendering order of it?
    2. Does it even make sense to try to do it closer to the final frame target?
      • I’m not expecting things like bloom and transparent objects to survive that nicely, however 90% of the frame tends to be not a bloomy or particle effects ridden ones, but does it even work at all?
    3. I got no idea exactly how you guys have implemented any of this yet, how complicated would you rate the MetalFX implementation of it from 1 to 5? The FSR1 equivalent at least (spatial upscaling)?
      • It is my understanding that while the implementation is a black box on Apple’s side, it is bound to be enhanced on its own overtime by iOS updates and might be even using things like the Neural Engine to help boost it all.
      • I’m assuming these type of things have to through that C land’s CommandBuffer IssuePluginCustomBlit()? (Don’t even know where to start!)
      • The XCode-side examples are quite just a few lines of plug and play code as the bulk of it is done by already provided libraries.
      • Is it even worth it?
    If you got up until here, thanks a lot.
    I’ll be updating this comment if need be if/once I start understanding a bit more of how all of this works.