BloomEditor.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace UnityStandardAssets.ImageEffects
  5. {
  6. [CustomEditor (typeof(Bloom))]
  7. class BloomEditor : Editor
  8. {
  9. SerializedProperty tweakMode;
  10. SerializedProperty screenBlendMode;
  11. SerializedObject serObj;
  12. SerializedProperty hdr;
  13. SerializedProperty quality;
  14. SerializedProperty sepBlurSpread;
  15. SerializedProperty bloomIntensity;
  16. SerializedProperty bloomThresholdColor;
  17. SerializedProperty bloomThreshold;
  18. SerializedProperty bloomBlurIterations;
  19. SerializedProperty hollywoodFlareBlurIterations;
  20. SerializedProperty lensflareMode;
  21. SerializedProperty hollyStretchWidth;
  22. SerializedProperty lensflareIntensity;
  23. SerializedProperty flareRotation;
  24. SerializedProperty lensFlareSaturation;
  25. SerializedProperty lensflareThreshold;
  26. SerializedProperty flareColorA;
  27. SerializedProperty flareColorB;
  28. SerializedProperty flareColorC;
  29. SerializedProperty flareColorD;
  30. SerializedProperty lensFlareVignetteMask;
  31. void OnEnable () {
  32. serObj = new SerializedObject (target);
  33. screenBlendMode = serObj.FindProperty("screenBlendMode");
  34. hdr = serObj.FindProperty("hdr");
  35. quality = serObj.FindProperty("quality");
  36. sepBlurSpread = serObj.FindProperty("sepBlurSpread");
  37. bloomIntensity = serObj.FindProperty("bloomIntensity");
  38. bloomThreshold = serObj.FindProperty("bloomThreshold");
  39. bloomThresholdColor = serObj.FindProperty("bloomThresholdColor");
  40. bloomBlurIterations = serObj.FindProperty("bloomBlurIterations");
  41. lensflareMode = serObj.FindProperty("lensflareMode");
  42. hollywoodFlareBlurIterations = serObj.FindProperty("hollywoodFlareBlurIterations");
  43. hollyStretchWidth = serObj.FindProperty("hollyStretchWidth");
  44. lensflareIntensity = serObj.FindProperty("lensflareIntensity");
  45. lensflareThreshold = serObj.FindProperty("lensflareThreshold");
  46. lensFlareSaturation = serObj.FindProperty("lensFlareSaturation");
  47. flareRotation = serObj.FindProperty("flareRotation");
  48. flareColorA = serObj.FindProperty("flareColorA");
  49. flareColorB = serObj.FindProperty("flareColorB");
  50. flareColorC = serObj.FindProperty("flareColorC");
  51. flareColorD = serObj.FindProperty("flareColorD");
  52. lensFlareVignetteMask = serObj.FindProperty("lensFlareVignetteMask");
  53. tweakMode = serObj.FindProperty("tweakMode");
  54. }
  55. public override void OnInspectorGUI () {
  56. serObj.Update();
  57. EditorGUILayout.LabelField("Glow and Lens Flares for bright screen pixels", EditorStyles.miniLabel);
  58. EditorGUILayout.PropertyField (quality, new GUIContent("Quality", "High quality preserves high frequencies with bigger blurs and uses a better blending and down-/upsampling"));
  59. EditorGUILayout.Separator ();
  60. EditorGUILayout.PropertyField (tweakMode, new GUIContent("Mode"));
  61. EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend"));
  62. EditorGUILayout.PropertyField (hdr, new GUIContent("HDR"));
  63. EditorGUILayout.Separator ();
  64. // display info text when screen blend mode cannot be used
  65. Camera cam = (target as Bloom).GetComponent<Camera>();
  66. if (cam != null) {
  67. if (screenBlendMode.enumValueIndex==0 && ((cam.allowHDR && hdr.enumValueIndex==0) || (hdr.enumValueIndex==1))) {
  68. EditorGUILayout.HelpBox("Screen blend is not supported in HDR. Using 'Add' instead.", MessageType.Info);
  69. }
  70. }
  71. EditorGUILayout.PropertyField (bloomIntensity, new GUIContent("Intensity"));
  72. bloomThreshold.floatValue = EditorGUILayout.Slider ("Threshold", bloomThreshold.floatValue, -0.05f, 4.0f);
  73. if (1 == tweakMode.intValue) {
  74. EditorGUILayout.PropertyField(bloomThresholdColor, new GUIContent(" RGB Threshold"));
  75. }
  76. EditorGUILayout.Separator ();
  77. bloomBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur Iterations", bloomBlurIterations.intValue, 1, 4);
  78. sepBlurSpread.floatValue = EditorGUILayout.Slider (" Sample Distance", sepBlurSpread.floatValue, 0.1f, 10.0f);
  79. EditorGUILayout.Separator ();
  80. if (1 == tweakMode.intValue) {
  81. // further lens flare tweakings
  82. if (0 != tweakMode.intValue)
  83. EditorGUILayout.PropertyField (lensflareMode, new GUIContent("Lens Flares"));
  84. else
  85. lensflareMode.enumValueIndex = 0;
  86. EditorGUILayout.PropertyField (lensflareIntensity, new GUIContent(" Local Intensity", "0 disables lens flares entirely (optimization)"));
  87. lensflareThreshold.floatValue = EditorGUILayout.Slider ("Threshold", lensflareThreshold.floatValue, 0.0f, 4.0f);
  88. if (Mathf.Abs(lensflareIntensity.floatValue) > Mathf.Epsilon) {
  89. if (lensflareMode.intValue == 0) {
  90. // ghosting
  91. EditorGUILayout.BeginHorizontal ();
  92. EditorGUILayout.PropertyField (flareColorA, new GUIContent(" 1st Color"));
  93. EditorGUILayout.PropertyField (flareColorB, new GUIContent(" 2nd Color"));
  94. EditorGUILayout.EndHorizontal ();
  95. EditorGUILayout.BeginHorizontal ();
  96. EditorGUILayout.PropertyField (flareColorC, new GUIContent(" 3rd Color"));
  97. EditorGUILayout.PropertyField (flareColorD, new GUIContent(" 4th Color"));
  98. EditorGUILayout.EndHorizontal ();
  99. }
  100. else if (lensflareMode.intValue == 1) {
  101. // hollywood
  102. EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent(" Stretch width"));
  103. EditorGUILayout.PropertyField (flareRotation, new GUIContent( " Rotation"));
  104. hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
  105. EditorGUILayout.PropertyField (lensFlareSaturation, new GUIContent(" Saturation"));
  106. EditorGUILayout.PropertyField (flareColorA, new GUIContent(" Tint Color"));
  107. }
  108. else if (lensflareMode.intValue == 2) {
  109. // both
  110. EditorGUILayout.PropertyField (hollyStretchWidth, new GUIContent(" Stretch width"));
  111. hollywoodFlareBlurIterations.intValue = EditorGUILayout.IntSlider (" Blur Iterations", hollywoodFlareBlurIterations.intValue, 1, 4);
  112. EditorGUILayout.PropertyField (lensFlareSaturation, new GUIContent(" Saturation"));
  113. EditorGUILayout.BeginHorizontal ();
  114. EditorGUILayout.PropertyField (flareColorA, new GUIContent(" 1st Color"));
  115. EditorGUILayout.PropertyField (flareColorB, new GUIContent(" 2nd Color"));
  116. EditorGUILayout.EndHorizontal ();
  117. EditorGUILayout.BeginHorizontal ();
  118. EditorGUILayout.PropertyField (flareColorC, new GUIContent(" 3rd Color"));
  119. EditorGUILayout.PropertyField (flareColorD, new GUIContent(" 4th Color"));
  120. EditorGUILayout.EndHorizontal ();
  121. }
  122. EditorGUILayout.PropertyField(lensFlareVignetteMask, new GUIContent(" Mask", "This mask is needed to prevent lens flare artifacts"));
  123. }
  124. }
  125. serObj.ApplyModifiedProperties();
  126. }
  127. }
  128. }