No Description
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.

FullScreenPassRendererFeatureEditor.cs 4.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEditor.Rendering;
  4. using UnityEngine;
  5. /// <summary>
  6. /// Custom editor for FullScreenPassRendererFeature class responsible for drawing unavailable by default properties
  7. /// such as custom drop down items and additional properties.
  8. /// </summary>
  9. [CustomEditor(typeof(FullScreenPassRendererFeature))]
  10. public class FullScreenPassRendererFeatureEditor : Editor
  11. {
  12. private SerializedProperty m_InjectionPointProperty;
  13. private SerializedProperty m_RequirementsProperty;
  14. private SerializedProperty m_FetchColorBufferProperty;
  15. private SerializedProperty m_BindDepthStencilAttachmentProperty;
  16. private SerializedProperty m_PassMaterialProperty;
  17. private SerializedProperty m_PassIndexProperty;
  18. private static readonly GUIContent k_InjectionPointGuiContent = new GUIContent("Injection Point", "Specifies where in the frame this pass will be injected.");
  19. private static readonly GUIContent k_RequirementsGuiContent = new GUIContent("Requirements", "A mask of URP internal textures that will need to be generated and bound for sampling.\n\nNote that 'Color' here corresponds to '_CameraOpaqueTexture' so most of the time you will want to use the 'Fetch Color Buffer' option instead.");
  20. private static readonly GUIContent k_FetchColorBufferGuiContent = new GUIContent("Fetch Color Buffer", "Enable this if the assigned material will need to sample the active color target. The active color will be bound to the '_BlitTexture' shader property for sampling. Note that this will introduce an internal color copy pass.");
  21. private static readonly GUIContent k_BindDepthStencilAttachmentGuiContent = new GUIContent("Bind Depth-Stencil", "Enable this to bind the active camera's depth-stencil attachment to the framebuffer (only use this if depth-stencil ops are used by the assigned material as this could have a performance impact).");
  22. private static readonly GUIContent k_PassMaterialGuiContent = new GUIContent("Pass Material", "The material used to render the full screen pass.");
  23. private static readonly GUIContent k_PassGuiContent = new GUIContent("Pass", "The name of the shader pass to use from the assigned material.");
  24. private void OnEnable()
  25. {
  26. m_InjectionPointProperty = serializedObject.FindProperty("injectionPoint");
  27. m_RequirementsProperty = serializedObject.FindProperty("requirements");
  28. m_FetchColorBufferProperty = serializedObject.FindProperty("fetchColorBuffer");
  29. m_BindDepthStencilAttachmentProperty = serializedObject.FindProperty("bindDepthStencilAttachment");
  30. m_PassMaterialProperty = serializedObject.FindProperty("passMaterial");
  31. m_PassIndexProperty = serializedObject.FindProperty("passIndex");
  32. }
  33. /// <summary>
  34. /// Implementation for a custom inspector
  35. /// </summary>
  36. public override void OnInspectorGUI()
  37. {
  38. var currentFeature = target as FullScreenPassRendererFeature;
  39. if (currentFeature.passMaterial == null || currentFeature.passIndex >= currentFeature.passMaterial.passCount)
  40. currentFeature.passIndex = 0;
  41. EditorGUILayout.PropertyField(m_InjectionPointProperty, k_InjectionPointGuiContent);
  42. EditorGUILayout.PropertyField(m_RequirementsProperty, k_RequirementsGuiContent);
  43. EditorGUILayout.PropertyField(m_FetchColorBufferProperty, k_FetchColorBufferGuiContent);
  44. EditorGUILayout.PropertyField(m_BindDepthStencilAttachmentProperty, k_BindDepthStencilAttachmentGuiContent);
  45. EditorGUILayout.PropertyField(m_PassMaterialProperty, k_PassMaterialGuiContent);
  46. if (AdvancedProperties.BeginGroup())
  47. {
  48. DrawMaterialPassProperty(currentFeature);
  49. }
  50. AdvancedProperties.EndGroup();
  51. serializedObject.ApplyModifiedProperties();
  52. }
  53. private void DrawMaterialPassProperty(FullScreenPassRendererFeature feature)
  54. {
  55. List<string> selectablePasses;
  56. bool isMaterialValid = feature.passMaterial != null;
  57. selectablePasses = isMaterialValid ? GetPassIndexStringEntries(feature) : new List<string>() {"No material"};
  58. // If material is invalid 0'th index is selected automatically, so it stays on "No material" entry
  59. // It is invalid index, but FullScreenPassRendererFeature wont execute until material is valid
  60. m_PassIndexProperty.intValue = EditorGUILayout.Popup(k_PassGuiContent, m_PassIndexProperty.intValue, selectablePasses.ToArray());
  61. }
  62. private static List<string> GetPassIndexStringEntries(FullScreenPassRendererFeature component)
  63. {
  64. List<string> passIndexEntries = new List<string>();
  65. for (int i = 0; i < component.passMaterial.passCount; ++i)
  66. {
  67. // "Name of a pass (index)" - "PassAlpha (1)"
  68. string entry = $"{component.passMaterial.GetPassName(i)} ({i})";
  69. passIndexEntries.Add(entry);
  70. }
  71. return passIndexEntries;
  72. }
  73. }