VolumetricFogProfileEditor.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //#define FOG_BORDER
  2. //#define FOG_SHADOW_CANCELLATION
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace VolumetricFogAndMist2 {
  6. [CustomEditor(typeof(VolumetricFogProfile))]
  7. public class VolumetricFogProfileEditor : Editor {
  8. SerializedProperty raymarchQuality, raymarchMinStep, jittering, dithering;
  9. SerializedProperty renderQueue, sortingLayerID, sortingOrder;
  10. SerializedProperty constantDensity, noiseTexture, noiseStrength, noiseScale, noiseFinalMultiplier;
  11. SerializedProperty useDetailNoise, detailTexture, detailScale, detailStrength, detailOffset;
  12. SerializedProperty density;
  13. SerializedProperty shape, border, customHeight, height, verticalOffset, distance, distanceFallOff, maxDistance, maxDistanceFallOff;
  14. SerializedProperty terrainFit, terrainFitResolution, terrainLayerMask, terrainFogHeight, terrainFogMinAltitude, terrainFogMaxAltitude;
  15. SerializedProperty albedo, enableDepthGradient, depthGradient, depthGradientMaxDistance, enableHeightGradient, heightGradient;
  16. SerializedProperty brightness, deepObscurance, specularColor, specularThreshold, specularIntensity, ambientLightMultiplier;
  17. SerializedProperty turbulence, windDirection, useCustomDetailNoiseWindDirection, detailNoiseWindDirection;
  18. SerializedProperty dayNightCycle, sunDirection, sunColor, sunIntensity, lightDiffusionPower, lightDiffusionIntensity;
  19. SerializedProperty receiveShadows, shadowIntensity, shadowCancellation, shadowMaxDistance;
  20. SerializedProperty cookie;
  21. SerializedProperty distantFog, distantFogColor, distantFogStartDistance, distantFogDistanceDensity, distantFogMaxHeight, distantFogHeightDensity, distantFogDiffusionIntensity, distantFogRenderQueue;
  22. private void OnEnable() {
  23. raymarchQuality = serializedObject.FindProperty("raymarchQuality");
  24. raymarchMinStep = serializedObject.FindProperty("raymarchMinStep");
  25. jittering = serializedObject.FindProperty("jittering");
  26. dithering = serializedObject.FindProperty("dithering");
  27. renderQueue = serializedObject.FindProperty("renderQueue");
  28. sortingLayerID = serializedObject.FindProperty("sortingLayerID");
  29. sortingOrder = serializedObject.FindProperty("sortingOrder");
  30. constantDensity = serializedObject.FindProperty("constantDensity");
  31. noiseTexture = serializedObject.FindProperty("noiseTexture");
  32. noiseStrength = serializedObject.FindProperty("noiseStrength");
  33. noiseScale = serializedObject.FindProperty("noiseScale");
  34. noiseFinalMultiplier = serializedObject.FindProperty("noiseFinalMultiplier");
  35. useDetailNoise = serializedObject.FindProperty("useDetailNoise");
  36. detailTexture = serializedObject.FindProperty("detailTexture");
  37. detailScale = serializedObject.FindProperty("detailScale");
  38. detailStrength = serializedObject.FindProperty("detailStrength");
  39. detailOffset = serializedObject.FindProperty("detailOffset");
  40. density = serializedObject.FindProperty("density");
  41. shape = serializedObject.FindProperty("shape");
  42. border = serializedObject.FindProperty("border");
  43. customHeight = serializedObject.FindProperty("customHeight");
  44. height = serializedObject.FindProperty("height");
  45. verticalOffset = serializedObject.FindProperty("verticalOffset");
  46. distance = serializedObject.FindProperty("distance");
  47. distanceFallOff = serializedObject.FindProperty("distanceFallOff");
  48. maxDistance = serializedObject.FindProperty("maxDistance");
  49. maxDistanceFallOff = serializedObject.FindProperty("maxDistanceFallOff");
  50. terrainFit = serializedObject.FindProperty("terrainFit");
  51. terrainFitResolution = serializedObject.FindProperty("terrainFitResolution");
  52. terrainLayerMask = serializedObject.FindProperty("terrainLayerMask");
  53. terrainFogHeight = serializedObject.FindProperty("terrainFogHeight");
  54. terrainFogMinAltitude = serializedObject.FindProperty("terrainFogMinAltitude");
  55. terrainFogMaxAltitude = serializedObject.FindProperty("terrainFogMaxAltitude");
  56. albedo = serializedObject.FindProperty("albedo");
  57. enableDepthGradient = serializedObject.FindProperty("enableDepthGradient");
  58. depthGradient = serializedObject.FindProperty("depthGradient");
  59. depthGradientMaxDistance = serializedObject.FindProperty("depthGradientMaxDistance");
  60. enableHeightGradient = serializedObject.FindProperty("enableHeightGradient");
  61. heightGradient = serializedObject.FindProperty("heightGradient");
  62. brightness = serializedObject.FindProperty("brightness");
  63. deepObscurance = serializedObject.FindProperty("deepObscurance");
  64. specularColor = serializedObject.FindProperty("specularColor");
  65. specularThreshold = serializedObject.FindProperty("specularThreshold");
  66. specularIntensity = serializedObject.FindProperty("specularIntensity");
  67. ambientLightMultiplier = serializedObject.FindProperty("ambientLightMultiplier");
  68. turbulence = serializedObject.FindProperty("turbulence");
  69. windDirection = serializedObject.FindProperty("windDirection");
  70. useCustomDetailNoiseWindDirection = serializedObject.FindProperty("useCustomDetailNoiseWindDirection");
  71. detailNoiseWindDirection = serializedObject.FindProperty("detailNoiseWindDirection");
  72. dayNightCycle = serializedObject.FindProperty("dayNightCycle");
  73. sunDirection = serializedObject.FindProperty("sunDirection");
  74. sunColor = serializedObject.FindProperty("sunColor");
  75. sunIntensity = serializedObject.FindProperty("sunIntensity");
  76. lightDiffusionPower = serializedObject.FindProperty("lightDiffusionPower");
  77. lightDiffusionIntensity = serializedObject.FindProperty("lightDiffusionIntensity");
  78. receiveShadows = serializedObject.FindProperty("receiveShadows");
  79. shadowIntensity = serializedObject.FindProperty("shadowIntensity");
  80. shadowCancellation = serializedObject.FindProperty("shadowCancellation");
  81. shadowMaxDistance = serializedObject.FindProperty("shadowMaxDistance");
  82. cookie = serializedObject.FindProperty("cookie");
  83. distantFog = serializedObject.FindProperty("distantFog");
  84. distantFogColor = serializedObject.FindProperty("distantFogColor");
  85. distantFogStartDistance = serializedObject.FindProperty("distantFogStartDistance");
  86. distantFogDistanceDensity = serializedObject.FindProperty("distantFogDistanceDensity");
  87. distantFogMaxHeight = serializedObject.FindProperty("distantFogMaxHeight");
  88. distantFogHeightDensity = serializedObject.FindProperty("distantFogHeightDensity");
  89. distantFogDiffusionIntensity = serializedObject.FindProperty("distantFogDiffusionIntensity");
  90. distantFogRenderQueue = serializedObject.FindProperty("distantFogRenderQueue");
  91. }
  92. public override void OnInspectorGUI() {
  93. serializedObject.Update();
  94. EditorGUILayout.PropertyField(raymarchQuality);
  95. EditorGUILayout.PropertyField(raymarchMinStep);
  96. EditorGUILayout.PropertyField(jittering);
  97. EditorGUILayout.PropertyField(dithering);
  98. EditorGUILayout.PropertyField(renderQueue);
  99. EditorGUILayout.PropertyField(sortingLayerID);
  100. EditorGUILayout.PropertyField(sortingOrder);
  101. EditorGUILayout.PropertyField(constantDensity);
  102. if (!constantDensity.boolValue) {
  103. EditorGUILayout.PropertyField(noiseTexture);
  104. EditorGUI.indentLevel++;
  105. EditorGUILayout.PropertyField(noiseStrength, new GUIContent("Strength"));
  106. EditorGUILayout.PropertyField(noiseScale, new GUIContent("Scale"));
  107. EditorGUILayout.PropertyField(noiseFinalMultiplier, new GUIContent("Multiplier"));
  108. EditorGUI.indentLevel--;
  109. EditorGUILayout.PropertyField(useDetailNoise, new GUIContent("Detail Noise"));
  110. if (useDetailNoise.boolValue) {
  111. EditorGUI.indentLevel++;
  112. EditorGUILayout.PropertyField(detailTexture);
  113. EditorGUILayout.PropertyField(detailStrength, new GUIContent("Strength"));
  114. EditorGUILayout.PropertyField(detailScale, new GUIContent("Scale"));
  115. EditorGUILayout.PropertyField(detailOffset, new GUIContent("Offset"));
  116. EditorGUI.indentLevel--;
  117. }
  118. }
  119. EditorGUILayout.PropertyField(density);
  120. EditorGUILayout.PropertyField(shape);
  121. #if FOG_BORDER
  122. EditorGUILayout.PropertyField(border);
  123. #else
  124. GUI.enabled = false;
  125. EditorGUILayout.LabelField("Border", "(Disabled in Volumetric Fog Manager)");
  126. GUI.enabled = true;
  127. #endif
  128. EditorGUILayout.PropertyField(customHeight, new GUIContent("Custom Volume Height"));
  129. if (customHeight.boolValue) {
  130. EditorGUI.indentLevel++;
  131. EditorGUILayout.PropertyField(height);
  132. EditorGUI.indentLevel--;
  133. }
  134. EditorGUILayout.PropertyField(verticalOffset);
  135. EditorGUILayout.PropertyField(distance);
  136. if (distance.floatValue > 0) {
  137. EditorGUI.indentLevel++;
  138. EditorGUILayout.PropertyField(distanceFallOff);
  139. EditorGUI.indentLevel--;
  140. }
  141. EditorGUILayout.PropertyField(maxDistance);
  142. EditorGUILayout.PropertyField(maxDistanceFallOff);
  143. EditorGUILayout.PropertyField(terrainFit);
  144. if (terrainFit.boolValue) {
  145. EditorGUI.indentLevel++;
  146. EditorGUILayout.PropertyField(terrainFitResolution, new GUIContent("Resolution"));
  147. EditorGUILayout.PropertyField(terrainLayerMask, new GUIContent("Layer Mask"));
  148. if (Terrain.activeTerrain != null) {
  149. int terrainLayer = Terrain.activeTerrain.gameObject.layer;
  150. if ((terrainLayerMask.intValue & (1 << terrainLayer)) == 0) {
  151. EditorGUILayout.HelpBox("Current terrain layer is not included in this layer mask. Terrain fit may not work properly.", MessageType.Warning);
  152. }
  153. }
  154. EditorGUILayout.PropertyField(terrainFogHeight, new GUIContent("Fog Height"));
  155. EditorGUILayout.PropertyField(terrainFogMinAltitude, new GUIContent("Min Altitude"));
  156. EditorGUILayout.PropertyField(terrainFogMaxAltitude, new GUIContent("Max Altitude"));
  157. EditorGUI.indentLevel--;
  158. }
  159. EditorGUILayout.PropertyField(albedo);
  160. Color albedoColor = albedo.colorValue;
  161. albedoColor.a = EditorGUILayout.Slider(new GUIContent("Alpha"), albedoColor.a, 0, 1f);
  162. albedo.colorValue = albedoColor;
  163. EditorGUILayout.PropertyField(enableDepthGradient);
  164. if (enableDepthGradient.boolValue) {
  165. EditorGUI.indentLevel++;
  166. EditorGUILayout.PropertyField(depthGradient);
  167. EditorGUILayout.PropertyField(depthGradientMaxDistance, new GUIContent("Max Distance"));
  168. EditorGUI.indentLevel--;
  169. }
  170. EditorGUILayout.PropertyField(enableHeightGradient);
  171. if (enableHeightGradient.boolValue) {
  172. EditorGUI.indentLevel++;
  173. EditorGUILayout.PropertyField(heightGradient);
  174. EditorGUI.indentLevel--;
  175. }
  176. EditorGUILayout.PropertyField(brightness);
  177. EditorGUILayout.PropertyField(deepObscurance);
  178. EditorGUILayout.PropertyField(specularColor);
  179. EditorGUILayout.PropertyField(specularThreshold);
  180. EditorGUILayout.PropertyField(specularIntensity);
  181. EditorGUILayout.PropertyField(turbulence);
  182. EditorGUILayout.PropertyField(windDirection);
  183. EditorGUILayout.PropertyField(useCustomDetailNoiseWindDirection, new GUIContent("Custom Detail Noise Wind"));
  184. if (useCustomDetailNoiseWindDirection.boolValue) {
  185. EditorGUILayout.PropertyField(detailNoiseWindDirection);
  186. }
  187. EditorGUILayout.PropertyField(dayNightCycle);
  188. if (dayNightCycle.boolValue) {
  189. VolumetricFogManager manager = VolumetricFogManager.GetManagerIfExists();
  190. if (manager != null && manager.sun == null) {
  191. EditorGUILayout.HelpBox("You must assign a directional light to the Sun property of the Volumetric Fog Manager.", MessageType.Warning);
  192. if (GUILayout.Button("Go to Volumetric Fog Manager")) {
  193. Selection.activeGameObject = manager.gameObject;
  194. EditorGUIUtility.ExitGUI();
  195. return;
  196. }
  197. }
  198. } else {
  199. EditorGUILayout.PropertyField(sunDirection);
  200. EditorGUILayout.PropertyField(sunColor);
  201. EditorGUILayout.PropertyField(sunIntensity);
  202. }
  203. EditorGUILayout.PropertyField(ambientLightMultiplier, new GUIContent("Ambient Light", "Amount of ambient light that influences fog colors"));
  204. EditorGUILayout.PropertyField(lightDiffusionPower);
  205. EditorGUILayout.PropertyField(lightDiffusionIntensity);
  206. #if UNITY_2021_3_OR_NEWER
  207. EditorGUILayout.PropertyField(cookie);
  208. #endif
  209. EditorGUILayout.PropertyField(receiveShadows);
  210. if (receiveShadows.boolValue) {
  211. EditorGUI.indentLevel++;
  212. EditorGUILayout.PropertyField(shadowIntensity);
  213. #if FOG_SHADOW_CANCELLATION
  214. EditorGUILayout.PropertyField(shadowCancellation);
  215. #endif
  216. EditorGUILayout.PropertyField(shadowMaxDistance);
  217. EditorGUI.indentLevel--;
  218. }
  219. EditorGUILayout.PropertyField(distantFog, new GUIContent("Enable Distant Fog"));
  220. if (distantFog.boolValue) {
  221. EditorGUILayout.PropertyField(distantFogColor, new GUIContent("Color"));
  222. EditorGUILayout.PropertyField(distantFogStartDistance, new GUIContent("Start Distance"));
  223. EditorGUILayout.PropertyField(distantFogDistanceDensity, new GUIContent("Distance Density"));
  224. EditorGUILayout.PropertyField(distantFogMaxHeight, new GUIContent("Max Height"));
  225. EditorGUILayout.PropertyField(distantFogHeightDensity, new GUIContent("Height Density"));
  226. EditorGUILayout.PropertyField(distantFogDiffusionIntensity, new GUIContent("Diffusion Intensity Multiplier"));
  227. EditorGUILayout.PropertyField(distantFogRenderQueue, new GUIContent("Render Queue"));
  228. }
  229. serializedObject.ApplyModifiedProperties();
  230. }
  231. }
  232. }