TonemappingEditor.cs 4.4 KB

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