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