- DepthOfFieldEditor.cs
- /
- /
- /
- /
1 using System;
2 using UnityEditor;
3 using UnityEditor.AnimatedValues;
4 using UnityEngine;
5
6 namespace UnityStandardAssets.ImageEffects
7 {
8 [CustomEditor(typeof(DepthOfField))]
9 class DepthOfFieldEditor : Editor
10 {
11 SerializedObject serObj;
12
13 SerializedProperty visualizeFocus;
14 SerializedProperty focalLength;
15 SerializedProperty focalSize;
16 SerializedProperty aperture;
17 SerializedProperty focalTransform;
18 SerializedProperty maxBlurSize;
19 SerializedProperty highResolution;
20
21 SerializedProperty blurType;
22 SerializedProperty blurSampleCount;
23
24 SerializedProperty nearBlur;
25 SerializedProperty foregroundOverlap;
26
27 SerializedProperty dx11BokehThreshold;
28 SerializedProperty dx11SpawnHeuristic;
29 SerializedProperty dx11BokehTexture;
30 SerializedProperty dx11BokehScale;
31 SerializedProperty dx11BokehIntensity;
32
33 AnimBool showFocalDistance = new AnimBool();
34 AnimBool showDiscBlurSettings = new AnimBool();
35 AnimBool showDX11BlurSettings = new AnimBool();
36 AnimBool showNearBlurOverlapSize = new AnimBool();
37
38 bool useFocalDistance { get { return focalTransform.objectReferenceValue == null; } }
39 bool useDiscBlur { get { return blurType.enumValueIndex < 1; } }
40 bool useDX11Blur { get { return blurType.enumValueIndex > 0; } }
41 bool useNearBlur { get { return nearBlur.boolValue; } }
42
43
44 void OnEnable()
45 {
46 serObj = new SerializedObject(target);
47
48 visualizeFocus = serObj.FindProperty("visualizeFocus");
49
50 focalLength = serObj.FindProperty("focalLength");
51 focalSize = serObj.FindProperty("focalSize");
52 aperture = serObj.FindProperty("aperture");
53 focalTransform = serObj.FindProperty("focalTransform");
54 maxBlurSize = serObj.FindProperty("maxBlurSize");
55 highResolution = serObj.FindProperty("highResolution");
56
57 blurType = serObj.FindProperty("blurType");
58 blurSampleCount = serObj.FindProperty("blurSampleCount");
59
60 nearBlur = serObj.FindProperty("nearBlur");
61 foregroundOverlap = serObj.FindProperty("foregroundOverlap");
62
63 dx11BokehThreshold = serObj.FindProperty("dx11BokehThreshold");
64 dx11SpawnHeuristic = serObj.FindProperty("dx11SpawnHeuristic");
65 dx11BokehTexture = serObj.FindProperty("dx11BokehTexture");
66 dx11BokehScale = serObj.FindProperty("dx11BokehScale");
67 dx11BokehIntensity = serObj.FindProperty("dx11BokehIntensity");
68
69 InitializedAnimBools();
70 }
71
72 void InitializedAnimBools()
73 {
74 showFocalDistance.valueChanged.AddListener(Repaint);
75 showFocalDistance.value = useFocalDistance;
76
77 showDiscBlurSettings.valueChanged.AddListener(Repaint);
78 showDiscBlurSettings.value = useDiscBlur;
79
80 showDX11BlurSettings.valueChanged.AddListener(Repaint);
81 showDX11BlurSettings.value = useDX11Blur;
82
83 showNearBlurOverlapSize.valueChanged.AddListener(Repaint);
84 showNearBlurOverlapSize.value = useNearBlur;
85 }
86
87
88 void UpdateAnimBoolTargets()
89 {
90 showFocalDistance.target = useFocalDistance;
91 showDiscBlurSettings.target = useDiscBlur;
92 showDX11BlurSettings.target = useDX11Blur;
93 showNearBlurOverlapSize.target = useNearBlur;
94 }
95
96
97 public override void OnInspectorGUI()
98 {
99 serObj.Update();
100
101 UpdateAnimBoolTargets();
102
103 EditorGUILayout.LabelField("Simulates camera lens defocus", EditorStyles.miniLabel);
104
105 GUILayout.Label("Focal Settings");
106 EditorGUILayout.PropertyField(visualizeFocus, new GUIContent(" Visualize"));
107 EditorGUILayout.PropertyField(focalTransform, new GUIContent(" Focus on Transform"));
108
109 if (EditorGUILayout.BeginFadeGroup(showFocalDistance.faded))
110 {
111 EditorGUILayout.PropertyField(focalLength, new GUIContent(" Focal Distance"));
112 }
113 EditorGUILayout.EndFadeGroup();
114
115 EditorGUILayout.Slider(focalSize, 0.0f, 2.0f, new GUIContent(" Focal Size"));
116 EditorGUILayout.Slider(aperture, 0.0f, 1.0f, new GUIContent(" Aperture"));
117
118 EditorGUILayout.Separator();
119
120 EditorGUILayout.PropertyField(blurType, new GUIContent("Defocus Type"));
121
122 if (!(target as DepthOfField).Dx11Support() && blurType.enumValueIndex > 0)
123 {
124 EditorGUILayout.HelpBox("DX11 mode not supported (need shader model 5)", MessageType.Info);
125 }
126
127 if (EditorGUILayout.BeginFadeGroup(showDiscBlurSettings.faded))
128 {
129 EditorGUILayout.PropertyField(blurSampleCount, new GUIContent(" Sample Count"));
130 }
131 EditorGUILayout.EndFadeGroup();
132
133 EditorGUILayout.Slider(maxBlurSize, 0.1f, 2.0f, new GUIContent(" Max Blur Distance"));
134 EditorGUILayout.PropertyField(highResolution, new GUIContent(" High Resolution"));
135
136 EditorGUILayout.Separator();
137
138 EditorGUILayout.PropertyField(nearBlur, new GUIContent("Near Blur"));
139 if (EditorGUILayout.BeginFadeGroup(showNearBlurOverlapSize.faded))
140 {
141 EditorGUILayout.Slider(foregroundOverlap, 0.1f, 2.0f, new GUIContent(" Overlap Size"));
142 }
143 EditorGUILayout.EndFadeGroup();
144
145 EditorGUILayout.Separator();
146
147 if (EditorGUILayout.BeginFadeGroup(showDX11BlurSettings.faded))
148 {
149 GUILayout.Label("DX11 Bokeh Settings");
150 EditorGUILayout.PropertyField(dx11BokehTexture, new GUIContent(" Bokeh Texture"));
151 EditorGUILayout.Slider(dx11BokehScale, 0.0f, 50.0f, new GUIContent(" Bokeh Scale"));
152 EditorGUILayout.Slider(dx11BokehIntensity, 0.0f, 100.0f, new GUIContent(" Bokeh Intensity"));
153 EditorGUILayout.Slider(dx11BokehThreshold, 0.0f, 1.0f, new GUIContent(" Min Luminance"));
154 EditorGUILayout.Slider(dx11SpawnHeuristic, 0.01f, 1.0f, new GUIContent(" Spawn Heuristic"));
155 }
156 EditorGUILayout.EndFadeGroup();
157
158 serObj.ApplyModifiedProperties();
159 }
160 }
161 }