public static void SetSSAOActive(bool active) { var urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; ScriptableRenderer forwardRenderer = urpAsset.GetRenderer(0); FieldInfo featuresField = typeof(ScriptableRenderer).GetField("m_RendererFeatures", BindingFlags.NonPublic | BindingFlags.Instance); IList features = featuresField.GetValue(forwardRenderer) as IList; ScriptableRendererFeature ssaoFeature = features[0] as ScriptableRendererFeature; if (!active) { ssaoFeature.SetActive(false); return; } FieldInfo settingsField = ssaoFeature.GetType().GetField("m_Settings", BindingFlags.NonPublic | BindingFlags.Instance); object settings = settingsField.GetValue(ssaoFeature); FieldInfo sourceField = settings.GetType().GetField("Source", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo downsampleField = settings.GetType().GetField("Downsample", BindingFlags.NonPublic | BindingFlags.Instance); ssaoFeature.SetActive(true); sourceField.SetValue(settings, 1); downsampleField.SetValue(settings, false); }
public override void Initialize() { base.Initialize(); urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; ScriptableRenderer forwardRenderer = urpAsset.GetRenderer(0) as ScriptableRenderer; var featuresField = typeof(ScriptableRenderer).GetField("m_RendererFeatures", BindingFlags.NonPublic | BindingFlags.Instance); IList features = featuresField.GetValue(forwardRenderer) as IList; ssaoFeature = features[0] as ScriptableRendererFeature; FieldInfo settingsField = ssaoFeature.GetType().GetField("m_Settings", BindingFlags.NonPublic | BindingFlags.Instance); settings = settingsField.GetValue(ssaoFeature); sourceField = settings.GetType().GetField("Source", BindingFlags.NonPublic | BindingFlags.Instance); downsampleField = settings.GetType().GetField("Downsample", BindingFlags.NonPublic | BindingFlags.Instance); }
public void AddRendererFeatureIfNotPresent(ScriptableRendererFeature feature) { var rendererFeatures = GetScriptableRendererFeatures(); if (rendererFeatures != null && !rendererFeatures.Exists(element => element.GetType() == feature.GetType())) { rendererFeatures.Add(feature); } }