설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenSpaceAmbientOcclusionEditor.cs 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. [CustomEditor(typeof(ScreenSpaceAmbientOcclusion))]
  7. internal class ScreenSpaceAmbientOcclusionEditor : Editor
  8. {
  9. #region Serialized Properties
  10. private SerializedProperty m_AOMethod;
  11. private SerializedProperty m_Downsample;
  12. private SerializedProperty m_AfterOpaque;
  13. private SerializedProperty m_Source;
  14. private SerializedProperty m_NormalQuality;
  15. private SerializedProperty m_Intensity;
  16. private SerializedProperty m_DirectLightingStrength;
  17. private SerializedProperty m_Radius;
  18. private SerializedProperty m_Falloff;
  19. private SerializedProperty m_Samples;
  20. private SerializedProperty m_BlurQuality;
  21. #endregion
  22. private bool m_IsInitialized = false;
  23. private HeaderBool m_ShowQualitySettings;
  24. class HeaderBool
  25. {
  26. private string key;
  27. public bool value;
  28. internal HeaderBool(string _key, bool _default = false)
  29. {
  30. key = _key;
  31. if (EditorPrefs.HasKey(key))
  32. value = EditorPrefs.GetBool(key);
  33. else
  34. value = _default;
  35. EditorPrefs.SetBool(key, value);
  36. }
  37. internal void SetValue(bool newValue)
  38. {
  39. value = newValue;
  40. EditorPrefs.SetBool(key, value);
  41. }
  42. }
  43. // Structs
  44. private struct Styles
  45. {
  46. public static GUIContent AOMethod = EditorGUIUtility.TrTextContent("Method", "The noise method to use when calculating the Ambient Occlusion value.");
  47. public static GUIContent Intensity = EditorGUIUtility.TrTextContent("Intensity", "The degree of darkness that Ambient Occlusion adds.");
  48. public static GUIContent Radius = EditorGUIUtility.TrTextContent("Radius", "The radius around a given point, where Unity calculates and applies the effect.");
  49. public static GUIContent Falloff = EditorGUIUtility.TrTextContent("Falloff Distance", "The distance from the camera where Ambient Occlusion should be visible.");
  50. public static GUIContent DirectLightingStrength = EditorGUIUtility.TrTextContent("Direct Lighting Strength", "Controls how much the ambient occlusion affects direct lighting.");
  51. public static GUIContent Quality = EditorGUIUtility.TrTextContent("Quality", "");
  52. public static GUIContent Source = EditorGUIUtility.TrTextContent("Source", "The source of the normal vector values.\nDepth Normals: the feature uses the values generated in the Depth Normal prepass.\nDepth: the feature reconstructs the normal values using the depth buffer.\nIn the Deferred rendering path, the feature uses the G-buffer normals texture.");
  53. public static GUIContent NormalQuality = new GUIContent("Normal Quality", "The number of depth texture samples that Unity takes when computing the normals. Low:1 sample, Medium: 5 samples, High: 9 samples.");
  54. public static GUIContent Downsample = EditorGUIUtility.TrTextContent("Downsample", "With this option enabled, Unity downsamples the SSAO effect texture to improve performance. Each dimension of the texture is reduced by a factor of 2.");
  55. public static GUIContent AfterOpaque = EditorGUIUtility.TrTextContent("After Opaque", "With this option enabled, Unity calculates and apply SSAO after the opaque pass to improve performance on mobile platforms with tiled-based GPU architectures. This is not physically correct.");
  56. public static GUIContent BlurQuality = EditorGUIUtility.TrTextContent("Blur Quality", "High: Bilateral, Medium: Gaussian. Low: Kawase (Single Pass).");
  57. public static GUIContent Samples = EditorGUIUtility.TrTextContent("Samples", "The number of samples that Unity takes when calculating the obscurance value. Low:4 samples, Medium: 8 samples, High: 12 samples.");
  58. }
  59. private void Init()
  60. {
  61. m_ShowQualitySettings = new HeaderBool($"SSAO.QualityFoldout", false);
  62. SerializedProperty settings = serializedObject.FindProperty("m_Settings");
  63. m_AOMethod = settings.FindPropertyRelative("AOMethod");
  64. m_Intensity = settings.FindPropertyRelative("Intensity");
  65. m_Radius = settings.FindPropertyRelative("Radius");
  66. m_Falloff = settings.FindPropertyRelative("Falloff");
  67. m_DirectLightingStrength = settings.FindPropertyRelative("DirectLightingStrength");
  68. m_Source = settings.FindPropertyRelative("Source");
  69. m_NormalQuality = settings.FindPropertyRelative("NormalSamples");
  70. m_Downsample = settings.FindPropertyRelative("Downsample");
  71. m_AfterOpaque = settings.FindPropertyRelative("AfterOpaque");
  72. m_BlurQuality = settings.FindPropertyRelative("BlurQuality");
  73. m_Samples = settings.FindPropertyRelative("Samples");
  74. m_IsInitialized = true;
  75. }
  76. public override void OnInspectorGUI()
  77. {
  78. if (!m_IsInitialized)
  79. Init();
  80. EditorGUILayout.PropertyField(m_AOMethod, Styles.AOMethod);
  81. EditorGUILayout.PropertyField(m_Intensity, Styles.Intensity);
  82. EditorGUILayout.PropertyField(m_Radius, Styles.Radius);
  83. EditorGUILayout.PropertyField(m_Falloff, Styles.Falloff);
  84. m_DirectLightingStrength.floatValue = EditorGUILayout.Slider(Styles.DirectLightingStrength, m_DirectLightingStrength.floatValue, 0f, 1f);
  85. // Make sure these fields are never below 0.0...
  86. m_Intensity.floatValue = Mathf.Max(m_Intensity.floatValue, 0f);
  87. m_Radius.floatValue = Mathf.Max(m_Radius.floatValue, 0f);
  88. m_Falloff.floatValue = Mathf.Max(m_Falloff.floatValue, 0f);
  89. m_ShowQualitySettings.SetValue(EditorGUILayout.Foldout(m_ShowQualitySettings.value, Styles.Quality));
  90. if (m_ShowQualitySettings.value)
  91. {
  92. bool isDeferredRenderingMode = RendererIsDeferred();
  93. EditorGUI.indentLevel++;
  94. // Selecting source is not available for Deferred Rendering...
  95. GUI.enabled = !isDeferredRenderingMode;
  96. EditorGUILayout.PropertyField(m_Source, Styles.Source);
  97. // We only enable this field when depth source is selected...
  98. GUI.enabled = !isDeferredRenderingMode && m_Source.enumValueIndex == (int)ScreenSpaceAmbientOcclusionSettings.DepthSource.Depth;
  99. EditorGUI.indentLevel++;
  100. EditorGUILayout.PropertyField(m_NormalQuality, Styles.NormalQuality);
  101. EditorGUI.indentLevel--;
  102. GUI.enabled = true;
  103. EditorGUILayout.PropertyField(m_Downsample, Styles.Downsample);
  104. EditorGUILayout.PropertyField(m_AfterOpaque, Styles.AfterOpaque);
  105. EditorGUILayout.PropertyField(m_BlurQuality, Styles.BlurQuality);
  106. EditorGUILayout.PropertyField(m_Samples, Styles.Samples);
  107. EditorGUI.indentLevel--;
  108. }
  109. }
  110. private bool RendererIsDeferred()
  111. {
  112. ScreenSpaceAmbientOcclusion ssaoFeature = (ScreenSpaceAmbientOcclusion) target;
  113. UniversalRenderPipelineAsset pipelineAsset = (UniversalRenderPipelineAsset) GraphicsSettings.currentRenderPipeline;
  114. if (ssaoFeature == null || pipelineAsset == null)
  115. return false;
  116. // We have to find the renderer related to the SSAO feature, then test if it is in deferred mode.
  117. var rendererDataList = pipelineAsset.m_RendererDataList;
  118. for (int rendererIndex = 0; rendererIndex < rendererDataList.Length; ++rendererIndex)
  119. {
  120. var rendererData = rendererDataList[rendererIndex] as UniversalRendererData;
  121. if (rendererData == null || rendererData.renderingMode != RenderingMode.Deferred)
  122. continue;
  123. var rendererFeatures = rendererData.rendererFeatures;
  124. foreach (var feature in rendererFeatures)
  125. if (feature is ScreenSpaceAmbientOcclusion occlusion && occlusion == ssaoFeature)
  126. return true;
  127. }
  128. return false;
  129. }
  130. }
  131. }