• TonemappingEditor.cs
  • /
  • /
  • /
  • /
1 using System;
2 using
UnityEditor;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.ImageEffects
6 {
7     
[CustomEditor (typeof(Tonemapping))]
8     
class TonemappingEditor : Editor
9     {
10         SerializedObject serObj;
11
12         SerializedProperty type;
13
14         
// CURVE specific parameter
15         SerializedProperty remapCurve;
16
17         SerializedProperty exposureAdjustment;
18
19         
// REINHARD specific parameter
20         SerializedProperty middleGrey;
21         SerializedProperty white;
22         SerializedProperty adaptionSpeed;
23         SerializedProperty adaptiveTextureSize;
24
25         
void OnEnable () {
26             serObj =
new SerializedObject (target);
27
28             type = serObj.FindProperty (
"type");
29             remapCurve = serObj.FindProperty (
"remapCurve");
30             exposureAdjustment = serObj.FindProperty (
"exposureAdjustment");
31             middleGrey = serObj.FindProperty (
"middleGrey");
32             white = serObj.FindProperty (
"white");
33             adaptionSpeed = serObj.FindProperty (
"adaptionSpeed");
34             adaptiveTextureSize = serObj.FindProperty(
"adaptiveTextureSize");
35         }
36
37
38         
public override void OnInspectorGUI () {
39             serObj.Update ();
40
41             GUILayout.Label(
"Mapping HDR to LDR ranges since 1982", EditorStyles.miniLabel);
42
43             Camera cam = (target
as Tonemapping).GetComponent<Camera>();
44             
if (cam != null) {
45                 
if (!cam.hdr) {
46                     EditorGUILayout.HelpBox(
"The camera is not HDR enabled. This will likely break the Tonemapper.", MessageType.Warning);
47                 }
48                 
else if (!(target as Tonemapping).validRenderTextureFormat) {
49                     EditorGUILayout.HelpBox(
"The input to Tonemapper is not in HDR. Make sure that all effects prior to this are executed in HDR.", MessageType.Warning);
50                 }
51             }
52
53             EditorGUILayout.PropertyField (type,
new GUIContent ("Technique"));
54
55             
if (type.enumValueIndex == (int) Tonemapping.TonemapperType.UserCurve) {
56                 EditorGUILayout.PropertyField (remapCurve,
new GUIContent ("Remap curve", "Specify the mapping of luminances yourself"));
57             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.SimpleReinhard) {
58                 EditorGUILayout.PropertyField (exposureAdjustment,
new GUIContent ("Exposure", "Exposure adjustment"));
59             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.Hable) {
60                 EditorGUILayout.PropertyField (exposureAdjustment,
new GUIContent ("Exposure", "Exposure adjustment"));
61             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.Photographic) {
62                 EditorGUILayout.PropertyField (exposureAdjustment,
new GUIContent ("Exposure", "Exposure adjustment"));
63             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.OptimizedHejiDawson) {
64                 EditorGUILayout.PropertyField (exposureAdjustment,
new GUIContent ("Exposure", "Exposure adjustment"));
65             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.AdaptiveReinhard) {
66                 EditorGUILayout.PropertyField (middleGrey,
new GUIContent ("Middle grey", "Middle grey defines the average luminance thus brightening or darkening the entire image."));
67                 EditorGUILayout.PropertyField (white,
new GUIContent ("White", "Smallest luminance value that will be mapped to white"));
68                 EditorGUILayout.PropertyField (adaptionSpeed,
new GUIContent ("Adaption Speed", "Speed modifier for the automatic adaption"));
69                 EditorGUILayout.PropertyField (adaptiveTextureSize,
new GUIContent ("Texture size", "Defines the amount of downsamples needed."));
70             }
else if (type.enumValueIndex == (int) Tonemapping.TonemapperType.AdaptiveReinhardAutoWhite) {
71                 EditorGUILayout.PropertyField (middleGrey,
new GUIContent ("Middle grey", "Middle grey defines the average luminance thus brightening or darkening the entire image."));
72                 EditorGUILayout.PropertyField (adaptionSpeed,
new GUIContent ("Adaption Speed", "Speed modifier for the automatic adaption"));
73                 EditorGUILayout.PropertyField (adaptiveTextureSize,
new GUIContent ("Texture size", "Defines the amount of downsamples needed."));
74             }
75
76             GUILayout.Label(
"All following effects will use LDR color buffers", EditorStyles.miniBoldLabel);
77
78             serObj.ApplyModifiedProperties();
79         }
80     }
81 }


Gõ tìm kiếm nhanh...