설명 없음
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.

ShadowsMidtonesHighlightsEditor.cs 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. // TODO: handle retina / EditorGUIUtility.pixelsPerPoint
  7. [CustomEditor(typeof(ShadowsMidtonesHighlights))]
  8. sealed class ShadowsMidtonesHighlightsEditor : VolumeComponentEditor
  9. {
  10. private static class Styles
  11. {
  12. public static readonly GUIContent shadowsLabel = EditorGUIUtility.TrTextContent("Shadows", "Use this to control and apply a hue to the shadows.");
  13. public static readonly GUIContent midtonesLabel = EditorGUIUtility.TrTextContent("Midtones", "Use this to control and apply a hue to the shadows.");
  14. public static readonly GUIContent highlightsLabel = EditorGUIUtility.TrTextContent("Highlights", "Use this to control and apply a hue to the shadows.");
  15. }
  16. SerializedDataParameter m_Shadows;
  17. SerializedDataParameter m_Midtones;
  18. SerializedDataParameter m_Highlights;
  19. SerializedDataParameter m_ShadowsStart;
  20. SerializedDataParameter m_ShadowsEnd;
  21. SerializedDataParameter m_HighlightsStart;
  22. SerializedDataParameter m_HighlightsEnd;
  23. const string k_ShaderName = "Hidden/Universal Render Pipeline/Editor/Shadows Midtones Highlights Curve";
  24. static Material s_Material;
  25. readonly TrackballUIDrawer m_TrackballUIDrawer = new TrackballUIDrawer();
  26. // Curve drawing utilities
  27. Rect m_CurveRect;
  28. RenderTexture m_CurveTex;
  29. public override void OnEnable()
  30. {
  31. var o = new PropertyFetcher<ShadowsMidtonesHighlights>(serializedObject);
  32. m_Shadows = Unpack(o.Find(x => x.shadows));
  33. m_Midtones = Unpack(o.Find(x => x.midtones));
  34. m_Highlights = Unpack(o.Find(x => x.highlights));
  35. m_ShadowsStart = Unpack(o.Find(x => x.shadowsStart));
  36. m_ShadowsEnd = Unpack(o.Find(x => x.shadowsEnd));
  37. m_HighlightsStart = Unpack(o.Find(x => x.highlightsStart));
  38. m_HighlightsEnd = Unpack(o.Find(x => x.highlightsEnd));
  39. }
  40. public override void OnInspectorGUI()
  41. {
  42. if (!CheckMaterialAndShader())
  43. {
  44. return;
  45. }
  46. using (new EditorGUILayout.HorizontalScope())
  47. {
  48. m_TrackballUIDrawer.OnGUI(m_Shadows.value, enableOverrides ? m_Shadows.overrideState : null, Styles.shadowsLabel, GetWheelValue);
  49. GUILayout.Space(4f);
  50. m_TrackballUIDrawer.OnGUI(m_Midtones.value, enableOverrides ? m_Midtones.overrideState : null, Styles.midtonesLabel, GetWheelValue);
  51. GUILayout.Space(4f);
  52. m_TrackballUIDrawer.OnGUI(m_Highlights.value, enableOverrides ? m_Highlights.overrideState : null, Styles.highlightsLabel, GetWheelValue);
  53. }
  54. EditorGUILayout.Space();
  55. // Reserve GUI space
  56. m_CurveRect = GUILayoutUtility.GetRect(128, 80);
  57. m_CurveRect.xMin += EditorGUI.indentLevel * 15f;
  58. if (Event.current.type == EventType.Repaint)
  59. {
  60. float alpha = GUI.enabled ? 1f : 0.4f;
  61. var limits = new Vector4(m_ShadowsStart.value.floatValue, m_ShadowsEnd.value.floatValue, m_HighlightsStart.value.floatValue, m_HighlightsEnd.value.floatValue);
  62. s_Material.SetVector("_ShaHiLimits", limits);
  63. s_Material.SetVector("_Variants", new Vector4(alpha, Mathf.Max(m_HighlightsEnd.value.floatValue, 1f), 0f, 0f));
  64. CheckCurveRT((int)m_CurveRect.width, (int)m_CurveRect.height);
  65. var oldRt = RenderTexture.active;
  66. Graphics.Blit(null, m_CurveTex, s_Material, EditorGUIUtility.isProSkin ? 0 : 1);
  67. RenderTexture.active = oldRt;
  68. GUI.DrawTexture(m_CurveRect, m_CurveTex);
  69. Handles.DrawSolidRectangleWithOutline(m_CurveRect, Color.clear, Color.white * 0.4f);
  70. }
  71. PropertyField(m_ShadowsStart, EditorGUIUtility.TrTextContent("Start"));
  72. m_ShadowsStart.value.floatValue = Mathf.Min(m_ShadowsStart.value.floatValue, m_ShadowsEnd.value.floatValue);
  73. PropertyField(m_ShadowsEnd, EditorGUIUtility.TrTextContent("End"));
  74. m_ShadowsEnd.value.floatValue = Mathf.Max(m_ShadowsStart.value.floatValue, m_ShadowsEnd.value.floatValue);
  75. PropertyField(m_HighlightsStart, EditorGUIUtility.TrTextContent("Start"));
  76. m_HighlightsStart.value.floatValue = Mathf.Min(m_HighlightsStart.value.floatValue, m_HighlightsEnd.value.floatValue);
  77. PropertyField(m_HighlightsEnd, EditorGUIUtility.TrTextContent("End"));
  78. m_HighlightsEnd.value.floatValue = Mathf.Max(m_HighlightsStart.value.floatValue, m_HighlightsEnd.value.floatValue);
  79. }
  80. void CheckCurveRT(int width, int height)
  81. {
  82. if (m_CurveTex == null || !m_CurveTex.IsCreated() || m_CurveTex.width != width || m_CurveTex.height != height)
  83. {
  84. CoreUtils.Destroy(m_CurveTex);
  85. m_CurveTex = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32);
  86. m_CurveTex.hideFlags = HideFlags.HideAndDontSave;
  87. }
  88. }
  89. static Vector3 GetWheelValue(Vector4 v)
  90. {
  91. float w = v.w * (Mathf.Sign(v.w) < 0f ? 1f : 4f);
  92. return new Vector3(
  93. Mathf.Max(v.x + w, 0f),
  94. Mathf.Max(v.y + w, 0f),
  95. Mathf.Max(v.z + w, 0f)
  96. );
  97. }
  98. bool CheckMaterialAndShader()
  99. {
  100. if (s_Material != null)
  101. {
  102. return true;
  103. }
  104. Shader shader = Shader.Find(k_ShaderName);
  105. if (shader == null)
  106. {
  107. Debug.LogError("ShadowsMidtonesHighlightsEditor: Unable to find shader \"" + k_ShaderName + "\"");
  108. return false;
  109. }
  110. s_Material = new Material(shader);
  111. return true;
  112. }
  113. }
  114. }