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. Dismiss Notice

Question How to Programatically change properties on Screen Space Ambient Occlusion?

Discussion in 'Universal Render Pipeline' started by DennisWardAltair, Jan 26, 2021.

  1. DennisWardAltair

    DennisWardAltair

    Joined:
    Apr 4, 2019
    Posts:
    27
    I've added a Screen Space Ambient Occlusion Renderer Feature to the forward renderer, and it functions as expected, but I want to programatically change these options at runtime by script. I've not had any luck getting an object through which I can access properties and change them.

    I'm not even sure about what namespace to use to get at the SSAO effect?

    Code (CSharp):
    1.         UniversalAdditionalCameraData camdata = Camera.main.GetUniversalAdditionalCameraData();
    2.         ForwardRenderer renderer = camdata.scriptableRenderer as ForwardRenderer;
    3.         ScriptableRenderer.RenderingFeatures features = renderer.supportedRenderingFeatures;
    4.  
    The snippet above is how I've accessed the ForwardRenderer, but I'm not sure how to access the SSAO feature. There's nothing in the features I see that I can use. I'm using Unity 2020.2 along with URP 10.2.2.

    Thanks, Dennis
     
  2. dwatt-hollowworldgames

    dwatt-hollowworldgames

    Joined:
    Apr 26, 2019
    Posts:
    104
    I am trying this in my settings scriptable.

    Code (CSharp):
    1.  
    2. [Serializable]
    3.         public class GraphicsSettings
    4.         {
    5.             public ForwardRendererData rendererData;
    6.             public bool ambientOcclusion;
    7.  
    8.             public void Apply()
    9.             {
    10. #if !UNITY_EDITOR
    11.                 for(int x = 0;x < rendererData.rendererFeatures.Count;x++)
    12.                 {
    13.                     if(rendererData.rendererFeatures[x].name == "Screen Space Ambient Occlusion")
    14.                     {
    15.                         rendererData.rendererFeatures[x].SetActive(ambientOcclusion);
    16.                     }
    17.                 }
    18. #endif
    19.             }
    20.         }
    21.  
    this might do it but only when not in the editor otherwise it would change your forward renderer data which is a scriptableobject. I am not sure about the name but a run through the code in debug should fix it.
     
    Last edited: Feb 3, 2021
    SheZii00 and AndersonMarquess like this.
  3. SheZii00

    SheZii00

    Joined:
    Nov 17, 2020
    Posts:
    1
    Thanks @DwaTT . Your solution works.