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

How to use DynRes through API?

Discussion in 'High Definition Render Pipeline' started by PutridEx, Jul 17, 2021.

  1. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Dynamic Resolution.
    My attempts didn't quite work out.
    I'm just trying to enable Dynamic Resolution with Forced Screen Percentage and a value that goes with Forced screen perc.



    Code (CSharp):
    1.  
    2.  GlobalDynamicResolutionSettings settings;
    3.  
    4. void Start()
    5.     {
    6.  
    7.         settings.enabled = true;
    8.         settings.dynResType = DynamicResolutionType.Hardware;
    9.         settings.upsampleFilter = DynamicResUpscaleFilter.Bilinear;
    10.         settings.forceResolution = true;
    11.         settings.forcedPercentage = 20.0f;
    12.         DynamicResolutionHandler.instance.Update(settings, null);
    13.  
    14.         //mainCam = Camera.main;
    15.         //DynamicResolutionHandler.UpdateAndUseCamera(mainCam, settings, null);
    16.         //DynamicResolutionHandler.SetDynamicResScaler(DefaultDynamicResMethod, DynamicResScalePolicyType.ReturnsPercentage);
    17. }
    18.  
    19. static private float DefaultDynamicResMethod()
    20.     {
    21.         return 20f;
    22.     }
    23.  
    24.  
    25.  
    26.  
    27.  
    DefaultDynamicResMethod tested using 0.2 and 20

    Commented out code was also tested -- I can't see any changes in playmode within the editor.
    It's enabled in camera & asset.
    I've tested manually activating it through the HDRP asset menu and it works, very visible difference at 20, using force screen perc. 2020 LTS


    Code (CSharp):
    1. print(DynamicResolutionHandler.instance.DynamicResolutionEnabled());
    2.         print(DynamicResolutionHandler.instance.GetCurrentScale());
    Prints that DynRes is enabled and is at 0.2 (20) Screen Perc, although it's not really working.


    Any ideas?
     
    Last edited: Jul 20, 2021
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Still can't get it working :(
    Note that I can force screen Res on in the HDRP asset settings and it works, so dynamic resolution is enabled correctly.
    It's just that I'm not sure how to enable it through the API/code.
     
    Last edited: Jul 20, 2021
  3. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    760
    Hey, there's a snippet in the documentation that is a good starting point here.

    Also, hardware dynamic resolution on Windows is only working when using DX12, so that may be something.
     
    PutridEx likes this.
  4. francescoc_unity

    francescoc_unity

    Unity Technologies

    Joined:
    Sep 19, 2018
    Posts:
    193
    Instead of going through forcing a resolution, you should go through the process to set a lambda as SetDynamicResScaler

    The documentation has a simple example, you can replace the example to make sure it returns always the same value if it is what you need

    https://docs.unity3d.com/Packages/c...efinition@12.0/manual/Dynamic-Resolution.html

    Note that regarding what @chap-unity correctly mentioned, HW is supported only on DX12, but on any other platform it will automatically fallback to Software.
     
    Last edited: Jul 20, 2021
    Lex4art and PutridEx like this.
  5. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Thank you both, got it working.
     
    chap-unity likes this.
  6. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    resuming this thread. The feature works also with DX11, but I have more questions:

    is the function to use in
    SetDynamicResScaler considered global? So one for each camera allowing dynamic resolution?

    what is the method:
    DynamicResolutionHandler.UpdateAndUseCamera(_component);

    and how/why is used?
     
  7. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    I believe all that stuff isn't meant to be used by users like that, more internal stuff. It's not a proper runtime API, as I thought it was.

    From my time looking this up, one of the devs told me there's no API for Dynamic Res right now. Really the only way to change the screen% in runtime is through the SetDynamicResScaler, and it will use the dynamic res upsampler specified in the HDRP settings. There's no way to change that in real time other than applying a completely different HDRP asset that has a different upscaler type.

    Hopefully in the future we'll get an proper API, there's no ETA -- but it will be a great day when it happens. Users can mix and match between many great upscalers and their settings
    it'll also be helpful for the sake of testing builds and performance, would make a tremendous difference.
     
    Last edited: Jul 27, 2021
  8. francescoc_unity

    francescoc_unity

    Unity Technologies

    Joined:
    Sep 19, 2018
    Posts:
    193
    > SetDynamicResScaler considered global? So one for each camera allowing dynamic resolution?

    Yes, the scaler is shared among all cameras using dynamic res.

    > DynamicResolutionHandler.UpdateAndUseCamera(_component);

    It is really just something to be used by SRP maintainer, as a user of HDRP no need to worry about it. Some API needs to be public as the dynamic resolution system is in CORE SRP and it is really meant for SRP maintainers only.


    To be clear the resolution can be changed at runtime with that API, the only thing missing is the runtime switch of filters.
     
    sebas77 likes this.
  9. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,641
    thank you a lot!
     
  10. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Hey, A bit unrelated but I'd rather not create a new thread if possible :D
    do you know what the differences are between hardware and software dynamic resolution? There's actually no doc about the hardware option, only software from what I can tell.

    I believe I've read one of the differences is it applies some sharpening that isn't applied in software? is that true?
     
  11. francescoc_unity

    francescoc_unity

    Unity Technologies

    Joined:
    Sep 19, 2018
    Posts:
    193
    Hey, yes our doc is a bit lacking, we plan on improving it soon, however in this case the difference is mentioned in the doc https://docs.unity3d.com/Packages/c...efinition@12.0/manual/Dynamic-Resolution.html (first paragraph):

    To do this, HDRP uses hardware dynamic resolution, if the platform supports it, otherwise it uses a software version. The main difference is that, for hardware dynamic resolution, the hardware treats the render targets up until the back buffer as being of the scaled size. This means that is is faster to clear the render targets.
     
    PutridEx likes this.
  12. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
  13. francescoc_unity

    francescoc_unity

    Unity Technologies

    Joined:
    Sep 19, 2018
    Posts:
    193
    Ruchir and PutridEx like this.
  14. sergeytata

    sergeytata

    Joined:
    Sep 27, 2021
    Posts:
    4
    Hi, this is not much relevant to the API, but this seems to be an active thread about dynamic resolution :)
    I tried selecting TAA Upsample method and it behaves weirdly. It crops the frame. Why is it doing this? I can't seem to find the answer in docs.
     
  15. DMI84

    DMI84

    Joined:
    Jun 5, 2016
    Posts:
    6
    I see still no good way to change it by runtime?
    I just create few assets with different settings (Disabled, Quality, Balanced, Fast) and switch it by QualitySettings Level.
     
  16. JansM

    JansM

    Unity Technologies

    Joined:
    May 20, 2019
    Posts:
    15
    Hey! Does DynamicResolutionHandler's SetUpscaleFilter work for you?
     
  17. DMI84

    DMI84

    Joined:
    Jun 5, 2016
    Posts:
    6