| | 1 | | using System.Reflection; |
| | 2 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Rendering; |
| | 5 | | using UnityEngine.Rendering.Universal; |
| | 6 | |
|
| | 7 | | namespace DCL.SettingsCommon.SettingsControllers.SpecificControllers |
| | 8 | | { |
| | 9 | | [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Shadow Resolution", fileName = "ShadowResolutionControlCo |
| | 10 | | public class ShadowResolutionControlController : SpinBoxSettingsControlController |
| | 11 | | { |
| | 12 | | private const int LOG2_256 = 8; // log2(256), where 256 is the lowest Resolution in Unity (it goes [256, 512, 10 |
| | 13 | |
|
| | 14 | | private UniversalRenderPipelineAsset lightweightRenderPipelineAsset; |
| | 15 | | private FieldInfo lwrpaShadowResolutionField; |
| | 16 | |
|
| | 17 | | public override void Initialize() |
| | 18 | | { |
| 2 | 19 | | base.Initialize(); |
| | 20 | |
|
| 2 | 21 | | lightweightRenderPipelineAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| | 22 | |
|
| 2 | 23 | | if (lightweightRenderPipelineAsset == null) |
| 0 | 24 | | return; |
| | 25 | |
|
| 2 | 26 | | lwrpaShadowResolutionField = lightweightRenderPipelineAsset.GetType().GetField("m_MainLightShadowmapResoluti |
| 2 | 27 | | } |
| | 28 | |
|
| | 29 | | public override object GetStoredValue() => |
| 2 | 30 | | (int)Mathf.Log((int)currentQualitySetting.shadowResolution, 2) - LOG2_256; |
| | 31 | |
|
| | 32 | | public override void UpdateSetting(object newValue) |
| | 33 | | { |
| 2 | 34 | | currentQualitySetting.shadowResolution = (UnityEngine.Rendering.Universal.ShadowResolution)(256 << (int)newV |
| | 35 | |
|
| 2 | 36 | | if (lightweightRenderPipelineAsset != null) |
| 2 | 37 | | lwrpaShadowResolutionField?.SetValue(lightweightRenderPipelineAsset, currentQualitySetting.shadowResolut |
| 2 | 38 | | } |
| | 39 | | } |
| | 40 | | } |