UniversalRendererDataEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. [CustomEditor(typeof(UniversalRendererData), true)]
  7. public class UniversalRendererDataEditor : ScriptableRendererDataEditor
  8. {
  9. private static class Styles
  10. {
  11. public static readonly GUIContent RendererTitle = EditorGUIUtility.TrTextContent("Universal Renderer", "Custom Universal Renderer for Universal RP.");
  12. public static readonly GUIContent PostProcessIncluded = EditorGUIUtility.TrTextContent("Enabled", "Enables the use of post processing effects within the scene. If disabled, Unity excludes post processing renderer Passes, shaders and textures from the build.");
  13. public static readonly GUIContent PostProcessLabel = EditorGUIUtility.TrTextContent("Data", "The asset containing references to shaders and Textures that the Renderer uses for post-processing.");
  14. public static readonly GUIContent FilteringSectionLabel = EditorGUIUtility.TrTextContent("Filtering", "Settings that controls and define which layers the renderer draws.");
  15. public static readonly GUIContent OpaqueMask = EditorGUIUtility.TrTextContent("Opaque Layer Mask", "Controls which opaque layers this renderer draws.");
  16. public static readonly GUIContent TransparentMask = EditorGUIUtility.TrTextContent("Transparent Layer Mask", "Controls which transparent layers this renderer draws.");
  17. public static readonly GUIContent RenderingSectionLabel = EditorGUIUtility.TrTextContent("Rendering", "Settings related to rendering and lighting.");
  18. public static readonly GUIContent RenderingModeLabel = EditorGUIUtility.TrTextContent("Rendering Path", "Select a rendering path.");
  19. public static readonly GUIContent DepthPrimingModeLabel = EditorGUIUtility.TrTextContent("Depth Priming Mode", "With depth priming enabled, Unity uses the depth buffer generated in the depth prepass to determine if a fragment should be rendered or skipped during the Base Camera opaque pass. Disabled: Unity does not perform depth priming. Auto: If there is a Render Pass that requires a depth prepass, Unity performs the depth prepass and depth priming. Forced: Unity performs the depth prepass and depth priming.");
  20. public static readonly GUIContent DepthPrimingModeInfo = EditorGUIUtility.TrTextContent("On Android, iOS, and Apple TV, Unity performs depth priming only in the Forced mode. On tiled GPUs, which are common to those platforms, depth priming might reduce performance when combined with MSAA.");
  21. public static readonly GUIContent RenderPassLabel = EditorGUIUtility.TrTextContent("Native RenderPass", "Enables URP to use RenderPass API. Has no effect on OpenGLES2");
  22. public static readonly GUIContent RenderPassSectionLabel = EditorGUIUtility.TrTextContent("RenderPass", "This section contains properties related to render passes.");
  23. public static readonly GUIContent ShadowsSectionLabel = EditorGUIUtility.TrTextContent("Shadows", "This section contains properties related to rendering shadows.");
  24. public static readonly GUIContent PostProcessingSectionLabel = EditorGUIUtility.TrTextContent("Post-processing", "This section contains properties related to rendering post-processing.");
  25. public static readonly GUIContent OverridesSectionLabel = EditorGUIUtility.TrTextContent("Overrides", "This section contains Render Pipeline properties that this Renderer overrides.");
  26. public static readonly GUIContent accurateGbufferNormalsLabel = EditorGUIUtility.TrTextContent("Accurate G-buffer normals", "Normals in G-buffer use octahedron encoding/decoding. This improves visual quality but might reduce performance.");
  27. //public static readonly GUIContent tiledDeferredShadingLabel = EditorGUIUtility.TrTextContent("Tiled Deferred Shading (Experimental)", "Allows Tiled Deferred Shading on appropriate lights");
  28. public static readonly GUIContent defaultStencilStateLabel = EditorGUIUtility.TrTextContent("Default Stencil State", "Configure the stencil state for the opaque and transparent render passes.");
  29. public static readonly GUIContent shadowTransparentReceiveLabel = EditorGUIUtility.TrTextContent("Transparent Receive Shadows", "When disabled, none of the transparent objects will receive shadows.");
  30. public static readonly GUIContent invalidStencilOverride = EditorGUIUtility.TrTextContent("Error: When using the deferred rendering path, the Renderer requires the control over the 4 highest bits of the stencil buffer to store Material types. The current combination of the stencil override options prevents the Renderer from controlling the required bits. Try changing one of the options to Replace.");
  31. public static readonly GUIContent clusteredRenderingLabel = EditorGUIUtility.TrTextContent("Clustered (experimental)", "(Experimental) Enables clustered rendering, allowing for more lights per object and more accurate light cullling.");
  32. public static readonly GUIContent intermediateTextureMode = EditorGUIUtility.TrTextContent("Intermediate Texture", "Controls when URP renders via an intermediate texture.");
  33. }
  34. SerializedProperty m_OpaqueLayerMask;
  35. SerializedProperty m_TransparentLayerMask;
  36. SerializedProperty m_RenderingMode;
  37. SerializedProperty m_DepthPrimingMode;
  38. SerializedProperty m_AccurateGbufferNormals;
  39. //SerializedProperty m_TiledDeferredShading;
  40. SerializedProperty m_ClusteredRendering;
  41. SerializedProperty m_TileSize;
  42. SerializedProperty m_UseNativeRenderPass;
  43. SerializedProperty m_DefaultStencilState;
  44. SerializedProperty m_PostProcessData;
  45. SerializedProperty m_Shaders;
  46. SerializedProperty m_ShadowTransparentReceiveProp;
  47. SerializedProperty m_IntermediateTextureMode;
  48. #if URP_ENABLE_CLUSTERED_UI
  49. static bool s_EnableClusteredUI => true;
  50. #else
  51. static bool s_EnableClusteredUI => false;
  52. #endif
  53. private void OnEnable()
  54. {
  55. m_OpaqueLayerMask = serializedObject.FindProperty("m_OpaqueLayerMask");
  56. m_TransparentLayerMask = serializedObject.FindProperty("m_TransparentLayerMask");
  57. m_RenderingMode = serializedObject.FindProperty("m_RenderingMode");
  58. m_DepthPrimingMode = serializedObject.FindProperty("m_DepthPrimingMode");
  59. m_AccurateGbufferNormals = serializedObject.FindProperty("m_AccurateGbufferNormals");
  60. // Not exposed yet.
  61. //m_TiledDeferredShading = serializedObject.FindProperty("m_TiledDeferredShading");
  62. m_ClusteredRendering = serializedObject.FindProperty("m_ClusteredRendering");
  63. m_TileSize = serializedObject.FindProperty("m_TileSize");
  64. m_UseNativeRenderPass = serializedObject.FindProperty("m_UseNativeRenderPass");
  65. m_DefaultStencilState = serializedObject.FindProperty("m_DefaultStencilState");
  66. m_PostProcessData = serializedObject.FindProperty("postProcessData");
  67. m_Shaders = serializedObject.FindProperty("shaders");
  68. m_ShadowTransparentReceiveProp = serializedObject.FindProperty("m_ShadowTransparentReceive");
  69. m_IntermediateTextureMode = serializedObject.FindProperty("m_IntermediateTextureMode");
  70. }
  71. public override void OnInspectorGUI()
  72. {
  73. serializedObject.Update();
  74. EditorGUILayout.Space();
  75. EditorGUILayout.LabelField(Styles.FilteringSectionLabel, EditorStyles.boldLabel);
  76. EditorGUI.indentLevel++;
  77. EditorGUILayout.PropertyField(m_OpaqueLayerMask, Styles.OpaqueMask);
  78. EditorGUILayout.PropertyField(m_TransparentLayerMask, Styles.TransparentMask);
  79. EditorGUI.indentLevel--;
  80. EditorGUILayout.Space();
  81. EditorGUILayout.LabelField(Styles.RenderingSectionLabel, EditorStyles.boldLabel);
  82. EditorGUI.indentLevel++;
  83. EditorGUILayout.PropertyField(m_RenderingMode, Styles.RenderingModeLabel);
  84. if (m_RenderingMode.intValue == (int)RenderingMode.Deferred)
  85. {
  86. EditorGUI.indentLevel++;
  87. EditorGUILayout.PropertyField(m_AccurateGbufferNormals, Styles.accurateGbufferNormalsLabel, true);
  88. //EditorGUILayout.PropertyField(m_TiledDeferredShading, Styles.tiledDeferredShadingLabel, true);
  89. EditorGUI.indentLevel--;
  90. }
  91. if (m_RenderingMode.intValue == (int)RenderingMode.Forward)
  92. {
  93. EditorGUI.indentLevel++;
  94. if (s_EnableClusteredUI)
  95. {
  96. EditorGUILayout.PropertyField(m_ClusteredRendering, Styles.clusteredRenderingLabel);
  97. EditorGUI.BeginDisabledGroup(!m_ClusteredRendering.boolValue);
  98. EditorGUILayout.PropertyField(m_TileSize);
  99. EditorGUI.EndDisabledGroup();
  100. }
  101. EditorGUILayout.PropertyField(m_DepthPrimingMode, Styles.DepthPrimingModeLabel);
  102. if (m_DepthPrimingMode.intValue != (int)DepthPrimingMode.Disabled)
  103. {
  104. EditorGUILayout.HelpBox(Styles.DepthPrimingModeInfo.text, MessageType.Info);
  105. }
  106. EditorGUI.indentLevel--;
  107. }
  108. EditorGUI.indentLevel--;
  109. EditorGUILayout.Space();
  110. EditorGUILayout.LabelField(Styles.RenderPassSectionLabel, EditorStyles.boldLabel);
  111. EditorGUI.indentLevel++;
  112. EditorGUILayout.PropertyField(m_UseNativeRenderPass, Styles.RenderPassLabel);
  113. EditorGUI.indentLevel--;
  114. EditorGUILayout.Space();
  115. EditorGUILayout.LabelField(Styles.ShadowsSectionLabel, EditorStyles.boldLabel);
  116. EditorGUI.indentLevel++;
  117. EditorGUILayout.PropertyField(m_ShadowTransparentReceiveProp, Styles.shadowTransparentReceiveLabel);
  118. EditorGUI.indentLevel--;
  119. EditorGUILayout.Space();
  120. EditorGUILayout.LabelField(Styles.PostProcessingSectionLabel, EditorStyles.boldLabel);
  121. EditorGUI.indentLevel++;
  122. EditorGUI.BeginChangeCheck();
  123. var postProcessIncluded = EditorGUILayout.Toggle(Styles.PostProcessIncluded, m_PostProcessData.objectReferenceValue != null);
  124. if (EditorGUI.EndChangeCheck())
  125. {
  126. m_PostProcessData.objectReferenceValue = postProcessIncluded ? PostProcessData.GetDefaultPostProcessData() : null;
  127. }
  128. EditorGUI.indentLevel++;
  129. EditorGUILayout.PropertyField(m_PostProcessData, Styles.PostProcessLabel);
  130. EditorGUI.indentLevel--;
  131. EditorGUI.indentLevel--;
  132. EditorGUILayout.Space();
  133. EditorGUILayout.LabelField(Styles.OverridesSectionLabel, EditorStyles.boldLabel);
  134. EditorGUI.indentLevel++;
  135. EditorGUILayout.PropertyField(m_DefaultStencilState, Styles.defaultStencilStateLabel, true);
  136. SerializedProperty overrideStencil = m_DefaultStencilState.FindPropertyRelative("overrideStencilState");
  137. if (overrideStencil.boolValue && m_RenderingMode.intValue == (int)RenderingMode.Deferred)
  138. {
  139. CompareFunction stencilFunction = (CompareFunction)m_DefaultStencilState.FindPropertyRelative("stencilCompareFunction").enumValueIndex;
  140. StencilOp stencilPass = (StencilOp)m_DefaultStencilState.FindPropertyRelative("passOperation").enumValueIndex;
  141. StencilOp stencilFail = (StencilOp)m_DefaultStencilState.FindPropertyRelative("failOperation").enumValueIndex;
  142. StencilOp stencilZFail = (StencilOp)m_DefaultStencilState.FindPropertyRelative("zFailOperation").enumValueIndex;
  143. bool invalidFunction = stencilFunction == CompareFunction.Disabled || stencilFunction == CompareFunction.Never;
  144. bool invalidOp = stencilPass != StencilOp.Replace && stencilFail != StencilOp.Replace && stencilZFail != StencilOp.Replace;
  145. if (invalidFunction || invalidOp)
  146. EditorGUILayout.HelpBox(Styles.invalidStencilOverride.text, MessageType.Error, true);
  147. }
  148. EditorGUI.indentLevel--;
  149. EditorGUILayout.Space();
  150. EditorGUILayout.LabelField("Compatibility", EditorStyles.boldLabel);
  151. EditorGUI.indentLevel++;
  152. {
  153. EditorGUILayout.PropertyField(m_IntermediateTextureMode, Styles.intermediateTextureMode);
  154. }
  155. EditorGUI.indentLevel--;
  156. EditorGUILayout.Space();
  157. serializedObject.ApplyModifiedProperties();
  158. base.OnInspectorGUI(); // Draw the base UI, contains ScriptableRenderFeatures list
  159. // Add a "Reload All" button in inspector when we are in developer's mode
  160. if (EditorPrefs.GetBool("DeveloperMode"))
  161. {
  162. EditorGUILayout.Space();
  163. EditorGUILayout.PropertyField(m_Shaders, true);
  164. if (GUILayout.Button("Reload All"))
  165. {
  166. var resources = target as UniversalRendererData;
  167. resources.shaders = null;
  168. ResourceReloader.ReloadAllNullIn(target, UniversalRenderPipelineAsset.packagePath);
  169. }
  170. }
  171. }
  172. }
  173. }