BloomAndFlaresEditor.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace UnityStandardAssets.ImageEffects
  5. {
  6. [CustomEditor (typeof(BloomAndFlares))]
  7. class BloomAndFlaresEditor : Editor
  8. {
  9. SerializedProperty tweakMode;
  10. SerializedProperty screenBlendMode;
  11. SerializedObject serObj;
  12. SerializedProperty hdr;
  13. SerializedProperty sepBlurSpread;
  14. SerializedProperty useSrcAlphaAsMask;
  15. SerializedProperty bloomIntensity;
  16. SerializedProperty bloomthreshold;
  17. SerializedProperty bloomBlurIterations;
  18. SerializedProperty lensflares;
  19. SerializedProperty hollywoodFlareBlurIterations;
  20. SerializedProperty lensflareMode;
  21. SerializedProperty hollyStretchWidth;
  22. SerializedProperty lensflareIntensity;
  23. SerializedProperty lensflarethreshold;
  24. SerializedProperty flareColorA;
  25. SerializedProperty flareColorB;
  26. SerializedProperty flareColorC;
  27. SerializedProperty flareColorD;
  28. SerializedProperty lensFlareVignetteMask;
  29. void OnEnable () {
  30. serObj = new SerializedObject (target);
  31. screenBlendMode = serObj.FindProperty("screenBlendMode");
  32. hdr = serObj.FindProperty("hdr");
  33. sepBlurSpread = serObj.FindProperty("sepBlurSpread");
  34. useSrcAlphaAsMask = serObj.FindProperty("useSrcAlphaAsMask");
  35. bloomIntensity = serObj.FindProperty("bloomIntensity");
  36. bloomthreshold = serObj.FindProperty("bloomThreshold");
  37. bloomBlurIterations = serObj.FindProperty("bloomBlurIterations");
  38. lensflares = serObj.FindProperty("lensflares");
  39. lensflareMode = serObj.FindProperty("lensflareMode");
  40. hollywoodFlareBlurIterations = serObj.FindProperty("hollywoodFlareBlurIterations");
  41. hollyStretchWidth = serObj.FindProperty("hollyStretchWidth");
  42. lensflareIntensity = serObj.FindProperty("lensflareIntensity");
  43. lensflarethreshold = serObj.FindProperty("lensflareThreshold");
  44. flareColorA = serObj.FindProperty("flareColorA");
  45. flareColorB = serObj.FindProperty("flareColorB");
  46. flareColorC = serObj.FindProperty("flareColorC");
  47. flareColorD = serObj.FindProperty("flareColorD");
  48. lensFlareVignetteMask = serObj.FindProperty("lensFlareVignetteMask");
  49. tweakMode = serObj.FindProperty("tweakMode");
  50. }
  51. public override void OnInspectorGUI () {
  52. serObj.Update();
  53. GUILayout.Label("HDR " + (hdr.enumValueIndex == 0 ? "auto detected, " : (hdr.enumValueIndex == 1 ? "forced on, " : "disabled, ")) + (useSrcAlphaAsMask.floatValue < 0.1f ? " ignoring alpha channel glow information" : " using alpha channel glow information"), EditorStyles.miniBoldLabel);
  54. EditorGUILayout.PropertyField (tweakMode, new GUIContent("Tweak mode"));
  55. EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend mode"));
  56. EditorGUILayout.PropertyField (hdr, new GUIContent("HDR"));
  57. // display info text when screen blend mode cannot be used
  58. Camera cam = (target as BloomAndFlares).GetComponent<Camera>();
  59. if (cam != null) {
  60. if (screenBlendMode.enumValueIndex==0 && ((cam.allowHDR && hdr.enumValueIndex==0) || (hdr.enumValueIndex==1))) {
  61. EditorGUILayout.HelpBox("Screen blend is not supported in HDR. Using 'Add' instead.", MessageType.Info);
  62. }
  63. }
  64. if (1 == tweakMode.intValue)
  65. EditorGUILayout.PropertyField (lensflares, new GUIContent("Cast lens flares"));
  66. EditorGUILayout.Separator ();
  67. EditorGUILayout.PropertyField (bloomIntensity, new GUIContent("Intensity"));
  68. bloomthreshold.floatValue = EditorGUILayout.Slider ("threshold", bloomthreshold.floatValue, -0.05f, 4.0f);
  69. bloomBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", bloomBlurIterations.intValue, 1, 4);
  70. sepBlurSpread.floatValue = EditorGUILayout.Slider ("Blur spread", sepBlurSpread.floatValue, 0.1f, 10.0f);
  71. if (1 == tweakMode.intValue)
  72. useSrcAlphaAsMask.floatValue = EditorGUILayout.Slider (new GUIContent("Use alpha mask", "Make alpha channel define glowiness"), useSrcAlphaAsMask.floatValue, 0.0f, 1.0f);
  73. else
  74. useSrcAlphaAsMask.floatValue = 0.0f;
  75. if (1 == tweakMode.intValue) {
  76. EditorGUILayout.Separator ();
  77. if (lensflares.boolValue) {
  78. // further lens flare tweakings
  79. if (0 != tweakMode.intValue)
  80. EditorGUILayout.PropertyField (lensflareMode, new GUIContent("Lens flare mode"));
  81. else
  82. lensflareMode.enumValueIndex = 0;
  83. EditorGUILayout.PropertyField(lensFlareVignetteMask, new GUIContent("Lens flare mask", "This mask is needed to prevent lens flare artifacts"));
  84. EditorGUILayout.PropertyField (lensflareIntensity, new GUIContent("Local intensity"));
  85. lensflarethreshold.floatValue = EditorGUILayout.Slider ("Local threshold", lensflarethreshold.floatValue, 0.0f, 1.0f);
  86. if (lensflareMode.intValue == 0) {
  87. // ghosting
  88. EditorGUILayout.BeginHorizontal ();
  89. EditorGUILayout.PropertyField (flareColorA, new GUIContent("1st Color"));
  90. EditorGUILayout.PropertyField (flareColorB, new GUIContent("2nd Color"));
  91. EditorGUILayout.EndHorizontal ();
  92. EditorGUILayout.BeginHorizontal ();
  93. EditorGUILayout.PropertyField (flareColorC, new GUIContent("3rd Color"));
  94. EditorGUILayout.PropertyField (flareColorD, new GUIContent("4th Color"));
  95. EditorGUILayout.EndHorizontal ();
  96. }
  97. else if (lensflareMode.intValue == 1) {
  98. // hollywood
  99. EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent("Stretch width"));
  100. hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
  101. EditorGUILayout.PropertyField (flareColorA, new GUIContent("Tint Color"));
  102. }
  103. else if (lensflareMode.intValue == 2) {
  104. // both
  105. EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent("Stretch width"));
  106. hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
  107. EditorGUILayout.BeginHorizontal ();
  108. EditorGUILayout.PropertyField (flareColorA, new GUIContent("1st Color"));
  109. EditorGUILayout.PropertyField (flareColorB, new GUIContent("2nd Color"));
  110. EditorGUILayout.EndHorizontal ();
  111. EditorGUILayout.BeginHorizontal ();
  112. EditorGUILayout.PropertyField (flareColorC, new GUIContent("3rd Color"));
  113. EditorGUILayout.PropertyField (flareColorD, new GUIContent("4th Color"));
  114. EditorGUILayout.EndHorizontal ();
  115. }
  116. }
  117. } else
  118. lensflares.boolValue = false; // disable lens flares in simple tweak mode
  119. serObj.ApplyModifiedProperties();
  120. }
  121. }
  122. }