3 using UnityEditor.AnimatedValues;
6 namespace UnityStandardAssets.ImageEffects
8 [CustomEditor(typeof(DepthOfField))]
11 SerializedObject serObj;
13 SerializedProperty visualizeFocus;
14 SerializedProperty focalLength;
15 SerializedProperty focalSize;
16 SerializedProperty aperture;
17 SerializedProperty focalTransform;
18 SerializedProperty maxBlurSize;
19 SerializedProperty highResolution;
21 SerializedProperty blurType;
22 SerializedProperty blurSampleCount;
24 SerializedProperty nearBlur;
25 SerializedProperty foregroundOverlap;
27 SerializedProperty dx11BokehThreshold;
28 SerializedProperty dx11SpawnHeuristic;
29 SerializedProperty dx11BokehTexture;
30 SerializedProperty dx11BokehScale;
31 SerializedProperty dx11BokehIntensity;
33 AnimBool showFocalDistance =
new AnimBool();
34 AnimBool showDiscBlurSettings =
new AnimBool();
35 AnimBool showDX11BlurSettings =
new AnimBool();
36 AnimBool showNearBlurOverlapSize =
new AnimBool();
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; } }
46 serObj =
new SerializedObject(target);
48 visualizeFocus = serObj.FindProperty(
"visualizeFocus");
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");
57 blurType = serObj.FindProperty(
"blurType");
58 blurSampleCount = serObj.FindProperty(
"blurSampleCount");
60 nearBlur = serObj.FindProperty(
"nearBlur");
61 foregroundOverlap = serObj.FindProperty(
"foregroundOverlap");
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");
69 InitializedAnimBools();
72 void InitializedAnimBools()
74 showFocalDistance.valueChanged.AddListener(Repaint);
75 showFocalDistance.value = useFocalDistance;
77 showDiscBlurSettings.valueChanged.AddListener(Repaint);
78 showDiscBlurSettings.value = useDiscBlur;
80 showDX11BlurSettings.valueChanged.AddListener(Repaint);
81 showDX11BlurSettings.value = useDX11Blur;
83 showNearBlurOverlapSize.valueChanged.AddListener(Repaint);
84 showNearBlurOverlapSize.value = useNearBlur;
88 void UpdateAnimBoolTargets()
90 showFocalDistance.target = useFocalDistance;
91 showDiscBlurSettings.target = useDiscBlur;
92 showDX11BlurSettings.target = useDX11Blur;
93 showNearBlurOverlapSize.target = useNearBlur;
97 public override void OnInspectorGUI()
101 UpdateAnimBoolTargets();
103 EditorGUILayout.LabelField(
"Simulates camera lens defocus", EditorStyles.miniLabel);
105 GUILayout.Label(
"Focal Settings");
106 EditorGUILayout.PropertyField(visualizeFocus,
new GUIContent(
" Visualize"));
107 EditorGUILayout.PropertyField(focalTransform,
new GUIContent(
" Focus on Transform"));
109 if (EditorGUILayout.BeginFadeGroup(showFocalDistance.faded))
111 EditorGUILayout.PropertyField(focalLength,
new GUIContent(
" Focal Distance"));
113 EditorGUILayout.EndFadeGroup();
115 EditorGUILayout.Slider(focalSize, 0.0f, 2.0f,
new GUIContent(
" Focal Size"));
116 EditorGUILayout.Slider(aperture, 0.0f, 1.0f,
new GUIContent(
" Aperture"));
118 EditorGUILayout.Separator();
120 EditorGUILayout.PropertyField(blurType,
new GUIContent(
"Defocus Type"));
122 if (!(target as
DepthOfField).Dx11Support() && blurType.enumValueIndex > 0)
124 EditorGUILayout.HelpBox(
"DX11 mode not supported (need shader model 5)", MessageType.Info);
127 if (EditorGUILayout.BeginFadeGroup(showDiscBlurSettings.faded))
129 EditorGUILayout.PropertyField(blurSampleCount,
new GUIContent(
" Sample Count"));
131 EditorGUILayout.EndFadeGroup();
133 EditorGUILayout.Slider(maxBlurSize, 0.1f, 2.0f,
new GUIContent(
" Max Blur Distance"));
134 EditorGUILayout.PropertyField(highResolution,
new GUIContent(
" High Resolution"));
136 EditorGUILayout.Separator();
138 EditorGUILayout.PropertyField(nearBlur,
new GUIContent(
"Near Blur"));
139 if (EditorGUILayout.BeginFadeGroup(showNearBlurOverlapSize.faded))
141 EditorGUILayout.Slider(foregroundOverlap, 0.1f, 2.0f,
new GUIContent(
" Overlap Size"));
143 EditorGUILayout.EndFadeGroup();
145 EditorGUILayout.Separator();
147 if (EditorGUILayout.BeginFadeGroup(showDX11BlurSettings.faded))
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"));
156 EditorGUILayout.EndFadeGroup();
158 serObj.ApplyModifiedProperties();