How to use different SSAO settings for different scene?

I want to use different SSAO settings for different scenes and so far, the only way I find is by having different renderers in the Renderer List, then in the respective scenes, select the renderer to use for the main camera.

image

However the default setup of this system seems to be for the purpose of downgrade or upgrade the renderer to support the different graphic quality settings. At this point, I am not sure whether there’s need to support multiple levels of graphics quality for my game.

My question is, can I still use this for my purpose, or is there another way to properly achieve what I want?

I haven’t used it in URP but with HDRP you simply create a Global Volume in your scene and any settings setup there will override the default settings you have in your Renderer List.
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@14.0/manual/Volumes.html

I cannot find Ambient Occlusion in URP Global Volume Profile. I am using 2022.3 LTS, URP. Is this an HDRP feature?

URP: Effect List | Universal RP | 14.0.11

HDRP: Ambient Occlusion | High Definition RP | 8.1.0

There is no Ambient Occlusion volume component in URP. Yes, it is weird, the intensity and radius settings are stored on the render feature :man_shrugging:

It is a contradiction to Unity’s own design philosophy: Renderers make up the render feature configuration and quality settings, volume components provide context sensitive settings.

Is there any workaround for this yet? Should I create another Renderer asset or use a C# script to update this dynamically?

Your best bet is to follow the discussion here: Turn URP SSAO on and off at runtime

Personally I gave up and changed my design requirements.

I ended up using the script from the other thread you linked and combining it with URP Volumes.

Here’s all the code:

Script for adjusting SSAO values at runtime.

/// <summary>
/// From: https://discussions.unity.com/t/turn-urp-ssao-on-and-off-at-runtime/830866/13
/// </summary>
public static class RenderFeatureAccess {

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
    static void RuntimeInitializeOnLoadMethod() {
        s_FieldLUT = new Dictionary<System.Type, Dictionary<string, FieldInfo>>();
        s_TypeNameLUT = new Dictionary<System.Type, string>();
    }

    static Dictionary<System.Type, Dictionary<string, FieldInfo>> s_FieldLUT = new Dictionary<System.Type, Dictionary<string, FieldInfo>>();
    static Dictionary<System.Type, string> s_TypeNameLUT = new Dictionary<System.Type, string>();

    #region Properties

    public static ScriptableRendererFeature ssao {
        get {
            const string kTypeName = "ScreenSpaceAmbientOcclusion";
            return GetRendererFeature(kTypeName);
        }
    }

    public static bool ssaoEnabled {
        get {
            var v = ssao;
            if (v != null) {
                return v.isActive;
            }
            return false;
        }
        set {
            var v = ssao;
            if (v != null) {
                v.SetActive(value);
            }
        }
    }

    public static float ssaoDirectLightingStrength {
        get => GetSettingsFloat(ssao, "m_Settings", "DirectLightingStrength");
        set => SetSettingsFloat(ssao, "m_Settings", "DirectLightingStrength", value);
    }

    public static float ssaoRadius {
        get => GetSettingsFloat(ssao, "m_Settings", "Radius");
        set => SetSettingsFloat(ssao, "m_Settings", "Radius", value);
    }

    public static float ssaoIntensity {
        get => GetSettingsFloat(ssao, "m_Settings", "Intensity");
        set => SetSettingsFloat(ssao, "m_Settings", "Intensity", value);
    }

    #endregion

    #region Helpers

    private static float GetSettingsFloat(ScriptableRendererFeature feature, string settingsName, string memberName) {
        if (feature == null)
            return 0;

        var settingsMember = GetField(feature.GetType(), settingsName);
        var settings = settingsMember.GetValue(feature);

        var directLightingStrengthMember = GetField(settings.GetType(), memberName);
        return (float)directLightingStrengthMember.GetValue(settings);
    }

    private static void SetSettingsFloat(ScriptableRendererFeature feature, string settingsName, string memberName, float value) {
        if (feature == null)
            return;

        var settingsMember = GetField(feature.GetType(), settingsName);
        var settings = settingsMember.GetValue(feature);

        var directLightingStrengthMember = GetField(settings.GetType(), memberName);
        directLightingStrengthMember.SetValue(settings, value);
    }

    private static FieldInfo GetField(System.Type type, string fieldName) {
        if (!s_FieldLUT.TryGetValue(type, out var fields))
            s_FieldLUT[type] = fields = new Dictionary<string, FieldInfo>();

        if (!fields.TryGetValue(fieldName, out var field))
            fields[fieldName] = field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);

        return field;
    }

    public static ScriptableRendererFeature GetRendererFeature(string typeName) {
        var asset = UniversalRenderPipeline.asset;
        var type = asset.GetType();
        var fieldInfo = GetField(type, "m_RendererDataList");
        var renderDatas = (ScriptableRendererData[])fieldInfo.GetValue(asset);
        if (renderDatas == null) {
            return null;
        }

        foreach (var renderData in renderDatas) {
            foreach (var rendererFeature in renderData.rendererFeatures) {
                if (rendererFeature == null) {
                    continue;
                }

                var featureType = rendererFeature.GetType();
                if (!s_TypeNameLUT.TryGetValue(featureType, out var name)) {
                    s_TypeNameLUT[featureType] = name = featureType.Name;
                }

                if (name == typeName) {
                    return rendererFeature;
                }
            }
        }

        return null;
    }

    #endregion
}

Script to create a volume component for the volume stack.

public class SSAOVolumeComponent : VolumeComponent {
    public ClampedFloatParameter intensity = new ClampedFloatParameter(3f, 0f, 30f);
    public ClampedFloatParameter radius = new ClampedFloatParameter(0.2f, 0f, 1f);
}

Script to push the volume stack values to the render feature. I put this on the Camera game object.

[ExecuteInEditMode]
public class UpdateSSAOVolume : MonoBehaviour {

    private float prevIntensity;
    private float prevRadius;
    private bool prevEnabled;

    private void Update() {
        SSAOVolumeComponent ssaoVolume = VolumeManager.instance.stack.GetComponent<SSAOVolumeComponent>();
        if (ssaoVolume != null) {
            float intensity = ssaoVolume.intensity.value;
            bool enabled = intensity > 0;
            if (enabled != prevEnabled) {
                prevEnabled = enabled;
                RenderFeatureAccess.ssaoEnabled = enabled;
            }

            if (intensity != prevIntensity) {
                prevIntensity = intensity;
                RenderFeatureAccess.ssaoIntensity = intensity;
            }

            float radius = ssaoVolume.radius.value;
            if (radius != prevRadius) {
                prevRadius = radius;
                RenderFeatureAccess.ssaoRadius = radius;
            }
        }
    }
}

Appreciate your effort in reporting back your findings here. Thanks!