| | 1 | | using System.Collections; |
| | 2 | | using System.Reflection; |
| | 3 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.Rendering; |
| | 6 | | using UnityEngine.Rendering.Universal; |
| | 7 | |
|
| | 8 | | namespace DCL.SettingsCommon.SettingsControllers.SpecificControllers |
| | 9 | | { |
| | 10 | | [CreateAssetMenu(menuName = "Settings/Controllers/Controls/SSAO Controller", fileName = "SSAOControlController")] |
| | 11 | | public class SSAOControlController : SpinBoxSettingsControlController |
| | 12 | | { |
| | 13 | | private UniversalRenderPipelineAsset urpAsset = null; |
| | 14 | | private ScriptableRendererFeature ssaoFeature; |
| | 15 | |
|
| | 16 | | private object settings; |
| | 17 | | private FieldInfo sourceField; |
| | 18 | | private FieldInfo downsampleField; |
| | 19 | |
|
| | 20 | | public override void Initialize() |
| | 21 | | { |
| 1 | 22 | | base.Initialize(); |
| | 23 | |
|
| 1 | 24 | | urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| | 25 | |
|
| 1 | 26 | | ScriptableRenderer forwardRenderer = urpAsset.GetRenderer(0) as ScriptableRenderer; |
| 1 | 27 | | var featuresField = typeof(ScriptableRenderer).GetField("m_RendererFeatures", BindingFlags.NonPublic | Bindi |
| | 28 | |
|
| 1 | 29 | | IList features = featuresField.GetValue(forwardRenderer) as IList; |
| 1 | 30 | | ssaoFeature = features[0] as ScriptableRendererFeature; |
| | 31 | |
|
| 1 | 32 | | FieldInfo settingsField = ssaoFeature.GetType().GetField("m_Settings", BindingFlags.NonPublic | BindingFlags |
| 1 | 33 | | settings = settingsField.GetValue(ssaoFeature); |
| | 34 | |
|
| 1 | 35 | | sourceField = settings.GetType().GetField("Source", BindingFlags.NonPublic | BindingFlags.Instance); |
| 1 | 36 | | downsampleField = settings.GetType().GetField("Downsample", BindingFlags.NonPublic | BindingFlags.Instance); |
| 1 | 37 | | } |
| | 38 | |
|
| 1 | 39 | | public override object GetStoredValue() { return currentQualitySetting.ssaoQuality; } |
| | 40 | |
|
| | 41 | | public override void UpdateSetting(object newValue) |
| | 42 | | { |
| 1 | 43 | | int value = (int)newValue; |
| | 44 | | switch ( value ) |
| | 45 | | { |
| | 46 | | case (int)QualitySettings.SSAOQualityLevel.OFF: |
| 0 | 47 | | ssaoFeature.SetActive(false); |
| 0 | 48 | | break; |
| | 49 | | case (int)QualitySettings.SSAOQualityLevel.LOW: |
| 0 | 50 | | ssaoFeature.SetActive(true); |
| 0 | 51 | | sourceField.SetValue(settings, 0); |
| 0 | 52 | | downsampleField.SetValue(settings, true); |
| 0 | 53 | | break; |
| | 54 | | case (int)QualitySettings.SSAOQualityLevel.MID: |
| 1 | 55 | | ssaoFeature.SetActive(true); |
| 1 | 56 | | sourceField.SetValue(settings, 1); |
| 1 | 57 | | downsampleField.SetValue(settings, true); |
| 1 | 58 | | break; |
| | 59 | | case (int)QualitySettings.SSAOQualityLevel.HIGH: |
| 0 | 60 | | ssaoFeature.SetActive(true); |
| 0 | 61 | | sourceField.SetValue(settings, 1); |
| 0 | 62 | | downsampleField.SetValue(settings, false); |
| | 63 | | break; |
| | 64 | | } |
| | 65 | |
|
| 1 | 66 | | currentQualitySetting.ssaoQuality = (QualitySettings.SSAOQualityLevel)value; |
| 1 | 67 | | } |
| | 68 | | } |
| | 69 | | } |