Search Unity

Change SSAO ScriptableRendererFeature at runtime

Discussion in 'Universal Render Pipeline' started by o-san, Jul 2, 2021.

  1. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    I'm trying to change the SSAO radius at runtime but have come to a dead-end. This is what I got so far:

    Code (CSharp):
    1. public ForwardRendererData forwardRendererData;
    2. ...
    3. private void Awake()
    4. {
    5.  
    6.     List<ScriptableRendererFeature> feat;
    7.     feat = forwardRendererData.rendererFeatures;
    8.    
    9.     for (int x = 0; x < feat.Count; x++)
    10.     {
    11.  
    12.         if (feat[x].name == "ScreenSpaceAmbientOcclusion")
    13.         {
    14.  
    15.             // feat[x].SetActive(false); <- This works
    16.  
    17.             var t = feat[x].GetType().GetProperty("m_Settings", BindingFlags.NonPublic);
    18.  
    19.             // t == null, no t.Radius etc.
    20.  
    21.         }
    22.  
    23.     }
    24.  
    25. }
    Any help appreciated.
     
  2. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,266
    Radius and intensity should have been stored on a volume component. The general idea is to put performance/quality options on a render feature, so they can vary per renderer or quality level. But anything that may differ per scene, should be on a volume component. Ironically, Unity didn't follow their own design for SSAO :p

    Your value 't' is an abstract value, so you won't be able to access properties like radius or intensity directly. Instead you have to cast it to a ScreenSpaceAmbientOcclusionSettings type. Which is internal, so you'd have to use reflection to get that first. And likely use reflection for any other properties. So the rabbit hole goes deeper still!
     
  3. o-san

    o-san

    Joined:
    Jun 23, 2018
    Posts:
    32
    Thanks, yes I noticed that ScreenSpaceAmbientOcclusionSettings is internal. I was hoping for a more future-safe way of doing this stuff but I guess I'm out of luck.

    I'm having trouble getting to the internal class using reflection. Any pointers? =)
     
  4. sarvarxba404

    sarvarxba404

    Joined:
    Aug 31, 2020
    Posts:
    2
    Hello, Any solution found?
    ScreenSpaceAmbientOcclusionSettings
    how to change?
     
  5. wenzy

    wenzy

    Joined:
    Nov 17, 2015
    Posts:
    44
    Meet the same problem. Is there any solution yet?