You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
7.1 KiB

5 years ago
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5. [CustomEditor(typeof(FogVolumeRenderer))]
  6. public class FogVolumeRendererEditor : Editor
  7. {
  8. SerializedProperty ShowCamera;
  9. FogVolumeRenderer _target;
  10. private Texture2D InspectorImage;
  11. private GUIStyle HeaderStyle, BodyStyle;
  12. private static bool DebugTab
  13. {
  14. get { return EditorPrefs.GetBool("fvDebugTab"); }
  15. set { EditorPrefs.SetBool("fvDebugTab", value); }
  16. }
  17. private static bool ShowInspectorTooltips
  18. {
  19. get { return EditorPrefs.GetBool("ShowInspectorTooltips"); }
  20. set { EditorPrefs.SetBool("ShowInspectorTooltips", value); }
  21. }
  22. GUIContent VariableField(string VariableName, string Tooltip)
  23. {
  24. return new GUIContent(VariableName, ShowInspectorTooltips ? Tooltip : "");
  25. }
  26. string[] layerMaskName;
  27. //int layerMaskNameIndex = 0;
  28. void OnEnable()
  29. {
  30. _target = (FogVolumeRenderer)target;
  31. ShowCamera = serializedObject.FindProperty("ShowCamera");
  32. InspectorImage = Resources.Load("InspectorImage", typeof(Texture2D)) as Texture2D;
  33. HeaderStyle = new GUIStyle();
  34. HeaderStyle.normal.background = InspectorImage;
  35. BodyStyle = new GUIStyle();
  36. // BodyStyle.normal.background = (Texture2D)Resources.Load("RendererInspectorBody");
  37. if (EditorGUIUtility.isProSkin)
  38. BodyStyle.normal.background = (Texture2D)Resources.Load("RendererInspectorBodyBlack");
  39. else
  40. BodyStyle.normal.background = (Texture2D)Resources.Load("RendererInspectorBodyBright");
  41. List<string> layerMaskList = new List<string>();
  42. for (int i = 0; i < 32; i++)
  43. {
  44. string layerName = LayerMask.LayerToName(i);
  45. //if (layerName != "")
  46. //{
  47. // if (layerName == _target.DepthLayersName)
  48. // layerMaskNameIndex = layerMaskList.Count;
  49. layerMaskList.Add(layerName);
  50. //}
  51. }
  52. layerMaskName = layerMaskList.ToArray();
  53. }
  54. public override void OnInspectorGUI()
  55. {
  56. serializedObject.Update();
  57. GUILayout.Space(10);
  58. // GUILayout.Box(InspectorImage, GUILayout.ExpandWidth(true));
  59. GUILayout.BeginVertical(HeaderStyle);
  60. // EditorGUILayout.HelpBox(BodyStyle.name, MessageType.None);
  61. GUILayout.Space(EditorGUIUtility.currentViewWidth / 4 - 10);
  62. //end header
  63. GUILayout.EndVertical();
  64. //begin body
  65. GUILayout.Space(1);
  66. GUILayout.BeginVertical(BodyStyle);
  67. EditorGUI.BeginChangeCheck();
  68. Undo.RecordObject(_target, "Fog volume Renderer parameter");
  69. GUILayout.Space(20);
  70. // GUILayout.BeginVertical("box");
  71. _target._Downsample = EditorGUILayout.IntSlider("Downscale", _target._Downsample, 1, 16);
  72. //if (_target._Downsample>1)
  73. // _target.RenderableInSceneView = EditorGUILayout.Toggle(VariableField("Render In Scene View", "Makes it visible for reflection probes and Scene viewport"), _target.RenderableInSceneView);
  74. //GUILayout.EndVertical();//end box
  75. if (_target._Downsample > 1)
  76. _target._BlendMode = (FogVolumeRenderer.BlendMode)EditorGUILayout.EnumPopup("Blend Mode", _target._BlendMode);
  77. EditorGUILayout.HelpBox("Resolution: " + _target.FogVolumeResolution, MessageType.None);
  78. if (_target._Downsample > 1)
  79. {
  80. GUILayout.BeginVertical("box");
  81. _target.GenerateDepth = EditorGUILayout.Toggle(VariableField("Depth", "Compute Depth when rendered in low-res and textured volumes collide with scene elements"), _target.GenerateDepth);
  82. if (_target.GenerateDepth)
  83. {
  84. //GUILayout.BeginHorizontal();
  85. //EditorGUILayout.LabelField("Exclude layer");
  86. //int newLayerMaskNameIndex = EditorGUILayout.Popup(layerMaskNameIndex, layerMaskName);
  87. //if (newLayerMaskNameIndex != layerMaskNameIndex)
  88. //{
  89. // layerMaskNameIndex = newLayerMaskNameIndex;
  90. // _target.DepthLayersName = layerMaskName[layerMaskNameIndex];
  91. //}
  92. //GUILayout.EndHorizontal();
  93. // GUILayout.BeginHorizontal();
  94. // EditorGUILayout.LabelField("Depth layers");
  95. _target.DepthLayer2 = EditorGUILayout.MaskField(VariableField("Depth layers", "Select the layers used to collide with FV\n(Experimental feature)"), _target.DepthLayer2, layerMaskName);
  96. //_target.DepthLayer2 = EditorGUILayout.LayerField("Depth layers", _target.DepthLayer2);
  97. //GUILayout.EndHorizontal();
  98. GUILayout.BeginVertical("box");
  99. _target.useBilateralUpsampling = EditorGUILayout.Toggle(VariableField("Edge-aware upscale", "Minimize the aliasing at the edges of colliding elements"), _target.useBilateralUpsampling);
  100. if (_target.useBilateralUpsampling)
  101. {
  102. _target.upsampleDepthThreshold = EditorGUILayout.Slider("Depth Threshold", _target.upsampleDepthThreshold, 0, .01f);
  103. _target.showBilateralEdge = EditorGUILayout.Toggle("Show edge mask", _target.showBilateralEdge);
  104. _target.upsampleMode = (FogVolumeRenderer.UpsampleMode)EditorGUILayout.EnumPopup("Method", _target.upsampleMode);
  105. }
  106. GUILayout.EndVertical();//end box
  107. }
  108. GUILayout.EndVertical();//end box
  109. #region DeNoise
  110. if (_target._Downsample > 1)
  111. {
  112. GUILayout.BeginVertical("box");
  113. _target.TAA = EditorGUILayout.Toggle(VariableField("DeNoise", "Performs Playdead's TAA to minimize noise when using jitter. Note: effect works only in 5.5"), _target.TAA);
  114. if (_target.TAA && _target.HDR)
  115. EditorGUILayout.HelpBox("Color output is in LDR", MessageType.None);
  116. GUILayout.EndVertical();//end box
  117. }
  118. #endregion
  119. // #region Stereo
  120. //if ( _target._Downsample > 0)
  121. //{
  122. // GUILayout.BeginVertical("box");
  123. // _target.useRectangularStereoRT = EditorGUILayout.Toggle("Rectangular stereo", _target.useRectangularStereoRT);
  124. // GUILayout.EndVertical();//end box
  125. //}
  126. // #endregion
  127. if (GUILayout.Button("Debug", EditorStyles.toolbarButton))
  128. DebugTab = !DebugTab;
  129. if (DebugTab)
  130. {
  131. GUILayout.BeginVertical("box");
  132. {
  133. EditorGUILayout.PropertyField(ShowCamera, new GUIContent("Show camera", "Unhide the camera used to render FV in low resolution"));
  134. }
  135. GUILayout.EndVertical();
  136. }
  137. }
  138. EditorGUI.EndChangeCheck();
  139. EditorGUILayout.HelpBox("Fog Volume 3.4 July 2018", MessageType.None);
  140. GUILayout.EndVertical();
  141. if (GUI.changed)
  142. {
  143. EditorUtility.SetDirty(_target);
  144. }
  145. serializedObject.ApplyModifiedProperties();
  146. }
  147. }