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

Resolved How to change dynamic resolution at runtime?

Discussion in 'General Graphics' started by gsylvain, Jun 7, 2021.

  1. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    Using unity 2020.3.8f1 + HDRP 10.5.

    The dynamic resolution seems to work fine when I directly modify the HDRP asset at runtime. It is doing exactly what I expect and need.

    I can't find a way to do just that by code.

    Code (CSharp):
    1. (GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset).currentPlatformRenderPipelineSettings.dynamicResolutionSettings.forcedPercentage = 0.5f;
    The code above doesn't work because currentPlatformRenderPipelineSettings is a struct. I tried to modify it but there is no setter. edit: It is impossible to alter the HDRP asset at runtime.

    I tried:
    Code (CSharp):
    1. DynamicResolutionHandler.SetDynamicResScaler(SetDynamicResolutionScale, DynamicResScalePolicyType.ReturnsPercentage);
    and forcing a "return 0.5f;" in the callback method. Still not working. I can still change the dynamic res settings in the HDRP asset and it works like a charm.

    I also tried this without success:
    Code (CSharp):
    1. ScalableBufferManager.ResizeBuffers(0.5f, 0.5f);
    Does anyone know how to change the dynamic resolution at runtime? Please note that I'm not looking for Screen.SetResolution, which is different.

    Thank you!
     
    Last edited: Jun 11, 2021
  2. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    One more question - there is 2 places where to enable and set the dynamic res. One from the HDRP asset and one by code using DynamicResolutionHandler.Update( GlobalDynamicResolutionSettings ... ).

    Which of these is overriding the other? The doc is almost inexistent on this subject.
     
  3. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    Resolved!

    Here's a checklist in order to enable dynamic resolution and you wish to modify it by code at runtime:

    - hdrp asset -> dynamic resolution
    - enable = true
    - set a valid min/max res. ex: [ 50, 100 ]
    - force screen percent = FALSE. Setting this to true will override any value you try to set by code.​
    - code
    - Call this once: DynamicResolutionHandler.SetDynamicResScaler(() => your_screen_percent, DynamicResScalePolicyType.ReturnsPercentage);, where the value is between 0.01 and 100.0​
    - camera
    - enable "allow dynamic resolution" on each camera​
     
    funnymanwin and andylewisart like this.
  4. funnymanwin

    funnymanwin

    Joined:
    Mar 20, 2020
    Posts:
    12
    THANKS SO MUCH!
    This is second time when I implemented FSR and DLSS with your guide
     
    gsylvain likes this.