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.

815 lines
46 KiB

5 years ago
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Collections;
  4. using UnityEditorInternal;
  5. using System.IO;
  6. [CustomEditor(typeof(FogVolume))]
  7. public class FogVolumeEditor : Editor
  8. {
  9. #region Variables
  10. private static bool ShowInspectorTooltips
  11. {
  12. get { return EditorPrefs.GetBool("ShowInspectorTooltips", true); }
  13. set { EditorPrefs.SetBool("ShowInspectorTooltips", value); }
  14. }
  15. FogVolume _target;
  16. private const string _showCustomizationOptions = "showCustomizationOptions";
  17. private GUIStyle Theme1, ThemeFooter;
  18. #endregion
  19. //Texture2D[] _InspectorBackground;
  20. void OnEnable()
  21. {
  22. _target = (FogVolume)target;
  23. string m_ScriptFilePath;
  24. string BackgroundImagesPath;
  25. MonoScript ms = MonoScript.FromScriptableObject(this);
  26. m_ScriptFilePath = AssetDatabase.GetAssetPath(ms);
  27. FileInfo fi = new FileInfo(m_ScriptFilePath);
  28. BackgroundImagesPath = fi.Directory.ToString();
  29. BackgroundImagesPath= BackgroundImagesPath.Replace("\\", "/");
  30. BackgroundImagesPath += "/Themes/png";
  31. _target.BackgroundImagesPath = BackgroundImagesPath;
  32. int ImageIndex = 0;
  33. foreach (string filePath in System.IO.Directory.GetFiles(BackgroundImagesPath))
  34. {
  35. if (!filePath.Contains(".meta"))
  36. // print(filePath);
  37. ImageIndex++;
  38. }
  39. _target._InspectorBackground = null;
  40. _target._InspectorBackground = new Texture2D[ImageIndex];
  41. // print(ImageIndex);
  42. int i = 0;
  43. foreach (string filePath in System.IO.Directory.GetFiles(BackgroundImagesPath))
  44. {
  45. if (!filePath.Contains(".meta"))
  46. {
  47. byte[] fileData;
  48. // print(filePath);
  49. fileData = File.ReadAllBytes(filePath);
  50. //init
  51. Texture2D tex = new Texture2D(1, 32, TextureFormat.RHalf, false, true);
  52. tex.filterMode = FilterMode.Trilinear;
  53. tex.LoadImage(fileData);
  54. _target._InspectorBackground[i] = tex;
  55. i++;
  56. }
  57. }
  58. Theme1 = new GUIStyle();
  59. ThemeFooter = new GUIStyle();
  60. // ThemeFooter.normal.background = MakeTex(new Color(.31f, 0.2f, .3f));
  61. if (EditorGUIUtility.isProSkin)
  62. ThemeFooter.normal.background = (Texture2D)Resources.Load("RendererInspectorBodyBlack");
  63. else
  64. ThemeFooter.normal.background = (Texture2D)Resources.Load("RendererInspectorBodyBright");
  65. }
  66. GUIContent VariableField(string VariableName, string Tooltip)
  67. {
  68. return new GUIContent(VariableName, ShowInspectorTooltips ? Tooltip : "");
  69. }
  70. public override bool RequiresConstantRepaint() { return true; }
  71. public override void OnInspectorGUI()
  72. {
  73. GUILayout.Space(10);
  74. serializedObject.Update();
  75. GUI.color = Color.white;
  76. GUILayout.BeginVertical(Theme1);
  77. //some info about fog type
  78. EditorGUI.BeginChangeCheck();
  79. Undo.RecordObject(target, "Fog volume parameter");
  80. #region Basic
  81. // _target.bias = EditorGUILayout.Slider("bias", _target.bias, 0, 1);
  82. //_target.RenderableInSceneView Rod, lo moví pabajo, a other/rendering options
  83. if (_target._FogType == FogVolume.FogType.Textured)
  84. {
  85. _target.FogMainColor = EditorGUILayout.ColorField(new GUIContent("Light energy", ShowInspectorTooltips ? "Multiplies all lighting contributions" : ""), _target.FogMainColor);
  86. _target.bVolumeFog = EditorGUILayout.Toggle(VariableField("Volume Fog", "Fills the empty space left by noise with volumetric fog. This fog allows the use of pointlights and shadows"), _target.bVolumeFog);
  87. }
  88. else
  89. _target.FogMainColor = EditorGUILayout.ColorField("Color", _target.FogMainColor);
  90. if (!_target.EnableNoise && !_target.EnableGradient || _target.bVolumeFog)
  91. _target.Visibility = EditorGUILayout.FloatField(VariableField("Visibility", "Fog Visibility") , _target.Visibility);
  92. _target.fogVolumeScale = EditorGUILayout.Vector3Field("Size", _target.fogVolumeScale);
  93. if (_target._FogType == FogVolume.FogType.Textured)
  94. {
  95. if (_target.bVolumeFog)
  96. {
  97. GUILayout.BeginVertical("box");
  98. _target._FogColor = EditorGUILayout.ColorField("Volume Fog Color", _target._FogColor);
  99. _target._AmbientAffectsFogColor = EditorGUILayout.Toggle(VariableField("Apply ambient color", "Use ambient color and proxy volume to multiply this color"), _target._AmbientAffectsFogColor);
  100. GUILayout.EndVertical();//end box
  101. }
  102. }
  103. if(_target._FogType == FogVolume.FogType.Textured)//3.1.9 Hide if Uniform. Its going to be hardcoded as "Traditional"
  104. _target._BlendMode = (FogVolumeRenderer.BlendMode)EditorGUILayout.EnumPopup(VariableField("Blend Mode", "Choose between standard of premultiplied alpha blend"), _target._BlendMode);
  105. #endregion
  106. #region lighting
  107. //GUILayout.BeginHorizontal("toolbarbutton");
  108. //EditorGUILayout.LabelField("Lighting");
  109. //showLighting = EditorGUILayout.Toggle("Show", showLighting);
  110. //GUILayout.EndHorizontal();
  111. //if (_target.EnableNoise /*|| _target.EnableGradient*/)
  112. if (GUILayout.Button("Lighting", EditorStyles.toolbarButton))
  113. _target.showLighting = !_target.showLighting;
  114. if (_target.showLighting)
  115. {
  116. if (_target._FogType == FogVolume.FogType.Textured)
  117. {
  118. GUILayout.BeginVertical("box");
  119. _target._AmbientColor = EditorGUILayout.ColorField(VariableField("Ambient", "Ambient is added as first light contribution. Alpha is used for volumetric shadows ambient amount"), _target._AmbientColor);
  120. _target.Absorption = EditorGUILayout.Slider(VariableField("Absorption", "How much ambient light is absorbed by noise. Depends on noise density"), _target.Absorption, 0, 1);
  121. if (_target.useHeightGradient)
  122. {
  123. _target.HeightAbsorption = EditorGUILayout.Slider(VariableField("Height Absorption", "Multiplies lighting contributoins with height gradient 1"), _target.HeightAbsorption, 0, 1);
  124. }
  125. GUILayout.EndVertical();
  126. if (_target.EnableNoise)
  127. {
  128. string HeightAbsorptionTooltip = "Define a height gradient to attenuate lighting. To disable, set both sliders to -1";
  129. EditorGUILayout.LabelField(VariableField("Height absorption gradient", HeightAbsorptionTooltip), EditorStyles.boldLabel);
  130. GUILayout.BeginVertical("box");
  131. _target.HeightAbsorptionMin = EditorGUILayout.Slider(VariableField("min", HeightAbsorptionTooltip), _target.HeightAbsorptionMin, -1, 1);
  132. _target.HeightAbsorptionMax = EditorGUILayout.Slider(VariableField("max", HeightAbsorptionTooltip), _target.HeightAbsorptionMax, -1, 1);
  133. GUILayout.EndVertical();
  134. }
  135. // if( GUILayout.Button(_target.bAbsorption.ToString()))
  136. // _target.bAbsorption = !_target.bAbsorption;
  137. // else
  138. // _target.bAbsorption = false;
  139. //
  140. // Debug.Log(_target.bAbsorption);
  141. if (_target.Absorption == 0)
  142. _target.bAbsorption = false;
  143. else
  144. _target.bAbsorption = true;
  145. }
  146. _target.Sun = (Light)EditorGUILayout.ObjectField("Sun Light", _target.Sun, typeof(Light), true);
  147. if (_target.Sun != null)
  148. {
  149. if (_target._FogType == FogVolume.FogType.Textured)
  150. _target._LightExposure = EditorGUILayout.Slider(VariableField("Light Exposure", "Overrides light intensity"), _target._LightExposure, 1, 5);
  151. if (_target.EnableNoise)
  152. {
  153. GUILayout.BeginVertical("box");
  154. _target.Lambert = EditorGUILayout.Toggle(VariableField("Lambertian", "Computes lambert lighting. Disabled by default\n uncomment //#pragma shader_feature _LAMBERT_SHADING in FogVolume.shader to enable"), _target.Lambert);
  155. if (_target.Lambert)
  156. {
  157. _target.DirectLightingAmount = EditorGUILayout.Slider("Amount", _target.DirectLightingAmount, .01f, 10f);
  158. _target.LambertianBias = EditorGUILayout.Slider("Lambertian Bias", _target.LambertianBias, .5f, 1);
  159. _target.NormalDistance = EditorGUILayout.Slider("Normal detail", _target.NormalDistance, .01f, .0001f);
  160. _target.DirectLightingDistance = EditorGUILayout.FloatField("Distance", _target.DirectLightingDistance);
  161. }
  162. GUILayout.EndVertical();
  163. }
  164. #region VolumeFogInscattering
  165. if (_target._FogType == FogVolume.FogType.Textured)
  166. if (_target.bVolumeFog)
  167. {
  168. GUILayout.BeginVertical("box");
  169. _target.VolumeFogInscattering = EditorGUILayout.Toggle(VariableField("Volume Fog Inscattering", "Computes phase function in fog"), _target.VolumeFogInscattering);
  170. if (_target.VolumeFogInscattering && _target.bVolumeFog)
  171. {
  172. _target.VolumeFogInscatteringColor = EditorGUILayout.ColorField("Color", _target.VolumeFogInscatteringColor);
  173. _target.VolumeFogInscatterColorAffectedWithFogColor = EditorGUILayout.Toggle(VariableField("Tint with fog color", "Off: reacts additively\nOn: incident light is tinted with the given fog color"), _target.VolumeFogInscatterColorAffectedWithFogColor);
  174. _target.VolumeFogInscatteringAnisotropy = EditorGUILayout.Slider(VariableField("Anisotropy", "Balance of forward and back scattering"), _target.VolumeFogInscatteringAnisotropy, -1, 1);
  175. _target.VolumeFogInscatteringIntensity = EditorGUILayout.Slider("Intensity", _target.VolumeFogInscatteringIntensity, 0, 1);
  176. _target.VolumeFogInscatteringStartDistance = EditorGUILayout.FloatField("Start Distance", _target.VolumeFogInscatteringStartDistance);
  177. _target.VolumeFogInscatteringTransitionWideness = EditorGUILayout.FloatField("Transition Wideness", _target.VolumeFogInscatteringTransitionWideness);
  178. }
  179. GUILayout.EndVertical();
  180. }
  181. #endregion
  182. #region Inscattering
  183. // if (_target.NoiseIntensity > 0)
  184. // {
  185. GUILayout.BeginVertical("box");
  186. _target.EnableInscattering = EditorGUILayout.Toggle(VariableField("Inscattering", "Computes phase function in noise. It is affected by absorption"), _target.EnableInscattering);
  187. if (_target.EnableInscattering)
  188. {
  189. _target.InscatteringColor = EditorGUILayout.ColorField("Color", _target.InscatteringColor);
  190. _target.InscatteringShape = EditorGUILayout.Slider(VariableField("Anisotropy", "Balance of forward and back scattering"), _target.InscatteringShape, -1, 1);
  191. _target.InscatteringIntensity = EditorGUILayout.Slider("Intensity", _target.InscatteringIntensity, 0, 1);
  192. _target.InscatteringStartDistance = EditorGUILayout.FloatField("Start Distance", _target.InscatteringStartDistance);
  193. _target.InscatteringTransitionWideness = EditorGUILayout.FloatField("Transition Wideness", _target.InscatteringTransitionWideness);
  194. }
  195. GUILayout.EndVertical();
  196. // }
  197. // else
  198. // _target.EnableInscattering = false;
  199. #endregion
  200. if (_target.EnableNoise && _target._NoiseVolume != null)
  201. {
  202. GUILayout.BeginVertical("box");
  203. _target._DirectionalLighting = EditorGUILayout.Toggle(VariableField("Directional Lighting", "Light is absorbed along light direction. Looks like sub-surface scattering"), _target._DirectionalLighting);
  204. if (_target._DirectionalLighting)
  205. {
  206. _target.LightExtinctionColor = EditorGUILayout.ColorField(VariableField("Extinction Color", "The color of the light after full absorption"), _target.LightExtinctionColor);
  207. // _target.DirectionalLightingClamp= EditorGUILayout.Slider(VariableField("Clamp", "Limit the maximum extiction"), _target.DirectionalLightingClamp, 1,5);
  208. _target._DirectionalLightingDistance = EditorGUILayout.Slider(VariableField("Distance", "Distance between samples"), _target._DirectionalLightingDistance, 0, 2.0f);
  209. _target.DirectLightingShadowDensity = EditorGUILayout.Slider(VariableField("Density", "Amount of light being absorbed"), _target.DirectLightingShadowDensity, 0, 15);
  210. _target.DirectLightingShadowSteps = EditorGUILayout.IntSlider(VariableField("Iterations", "How many times to compute. Each iteration computes noise one more time causing dramatical performance hits"), _target.DirectLightingShadowSteps, 1, 5);
  211. }
  212. GUILayout.EndVertical();
  213. }
  214. }
  215. if (_target.EnableNoise && _target.Sun)
  216. {
  217. GUILayout.BeginVertical("box");
  218. _target._ShadeNoise = EditorGUILayout.Toggle(VariableField("Self shadow", "Computes directional shadows. \n It has high performance impact"), _target._ShadeNoise);
  219. if (_target._ShadeNoise)
  220. {
  221. // _target.Shade = EditorGUILayout.Slider("Shadow intensity", _target.Shade, 0, 1);
  222. _target.ShadowShift = EditorGUILayout.Slider(VariableField("Shadow distance", "Distance between samples"), _target.ShadowShift, .0f, 2);
  223. _target._SelfShadowSteps = EditorGUILayout.IntSlider("Iterations", _target._SelfShadowSteps, 1, 20);
  224. _target._SelfShadowColor = EditorGUILayout.ColorField(VariableField("Shadow color", "Ambient color x Shadow color"), _target._SelfShadowColor);
  225. }
  226. GUILayout.EndVertical();
  227. }
  228. //
  229. if (_target._FogType == FogVolume.FogType.Textured)
  230. {
  231. if (_target.FogRenderer.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.On ||
  232. _target.FogRenderer.receiveShadows == true)
  233. {
  234. GUILayout.BeginVertical("box");
  235. EditorGUILayout.LabelField("Opacity shadow map", EditorStyles.boldLabel);
  236. // _target.CastShadows = EditorGUILayout.Toggle("Cast Shadows", _target.CastShadows);//lets control it trough the renderer
  237. if (_target.Sun && _target.CastShadows)//casi mejor que un droplist
  238. {
  239. //tempShadowCaster = _target.CastShadows;
  240. _target.ShadowCameraPosition = EditorGUILayout.IntField(VariableField("Vertical Offset", "Distance of the shadow camera. Use the prefab RT Viewer to see the result"), _target.ShadowCameraPosition);
  241. _target.SunAttached = EditorGUILayout.Toggle(VariableField("Attach light", "The assigned light will inherit the volume rotation. This is useful to cast fake shadows with noise. Check the scene Sunset to see this in action"), _target.SunAttached);
  242. _target.ShadowColor = EditorGUILayout.ColorField("Shadow Color", _target.ShadowColor);
  243. _target._ShadowCamera.textureSize = (ShadowCamera.TextureSize)EditorGUILayout.EnumPopup(VariableField("Resolution", "Resolution of the shadow map"), _target._ShadowCamera.textureSize);
  244. _target.ShadowCameraSkippedFrames = EditorGUILayout.IntSlider(VariableField("Skip frames", "Skip frames to reduce costs"), _target.ShadowCameraSkippedFrames, 0, 10);
  245. GUILayout.BeginVertical("box");
  246. EditorGUILayout.LabelField("Convolution", EditorStyles.boldLabel);
  247. _target._ShadowCamera.iterations = EditorGUILayout.IntSlider("Iterations", _target._ShadowCamera.iterations, 0, 5);
  248. if (_target._ShadowCamera.iterations > 0)
  249. _target._ShadowCamera.Downsampling = EditorGUILayout.IntSlider("Downsampling", _target._ShadowCamera.Downsampling, 0, 5);
  250. if (_target._ShadowCamera.iterations > 1)
  251. _target._ShadowCamera.blurSpread = EditorGUILayout.Slider("Radius", _target._ShadowCamera.blurSpread, 0, 1);
  252. GUILayout.EndVertical();
  253. }
  254. else
  255. {
  256. if (_target.FogRenderer.receiveShadows)
  257. _target.ShadowCaster = (FogVolume)EditorGUILayout.ObjectField(VariableField("Shadowmap coming from:", "Assign here the fog volume that is used to cast shadows"), _target.ShadowCaster, typeof(FogVolume), true);
  258. if (_target.ShadowCaster != null)
  259. _target.CastShadows = false;
  260. // tempShadowCaster = _target.CastShadows;
  261. }
  262. if (_target.CastShadows == false && _target.FogRenderer.receiveShadows)
  263. {
  264. _target.UseConvolvedLightshafts = EditorGUILayout.Toggle(VariableField("Use convolved lightshaft", "You can select here if you want to use the blurred shadow"), _target.UseConvolvedLightshafts);
  265. _target.ShadowCutoff = EditorGUILayout.Slider(VariableField("Shadow Cutoff", "Apply contrast to the sampled shadow"), _target.ShadowCutoff, 0.001f, 1);
  266. }
  267. GUILayout.EndVertical();
  268. }
  269. //_target.RT_Opacity = (RenderTexture)EditorGUILayout.ObjectField("LightMapRT", _target.RT_Opacity, typeof(RenderTexture), false);
  270. //_target._LightMapTex = (Texture2D)EditorGUILayout.ObjectField("LightMapTex", _target._LightMapTex, typeof(Texture2D), false);
  271. }
  272. else
  273. _target.CastShadows = false;
  274. if (_target.Sun && _target.EnableNoise)
  275. {
  276. GUILayout.BeginVertical("box");
  277. _target.LightHalo = EditorGUILayout.Toggle("Halo", _target.LightHalo);
  278. if (_target.LightHalo && _target.EnableNoise)
  279. {
  280. _target._LightHaloTexture = (Texture2D)EditorGUILayout.ObjectField("Halo texture", _target._LightHaloTexture, typeof(Texture2D), true);
  281. _target._HaloWidth = EditorGUILayout.Slider("Width", _target._HaloWidth, 0, 1);
  282. _target._HaloRadius = EditorGUILayout.Slider("Radius", _target._HaloRadius, -5, 1);
  283. _target._HaloAbsorption = EditorGUILayout.Slider(VariableField("Absorption", "How much is absorption affecting"), _target._HaloAbsorption, 0, 1);
  284. // _target._HaloOpticalDispersion = EditorGUILayout.Slider("OpticalDispersion", _target._HaloOpticalDispersion, 0, 8);
  285. _target._HaloIntensity = EditorGUILayout.Slider("Intensity", _target._HaloIntensity, 0, 1);
  286. }
  287. GUILayout.EndVertical();
  288. }//TODO. Halo should be always available
  289. }
  290. #endregion
  291. #region PointLights
  292. string PointLightTittle = "";
  293. if (SystemInfo.graphicsShaderLevel > 30)
  294. PointLightTittle = "Lights";
  295. else
  296. PointLightTittle = "Lights not available on this platform ";// + SystemInfo.graphicsShaderLevel;
  297. if (_target._FogType == FogVolume.FogType.Textured)
  298. if (GUILayout.Button(PointLightTittle, EditorStyles.toolbarButton))
  299. _target.showPointLights = !_target.showPointLights;
  300. if (_target.showPointLights &&
  301. SystemInfo.graphicsShaderLevel > 30)
  302. {
  303. _target.PointLightsActive = EditorGUILayout.Toggle("Enable", _target.PointLightsActive);
  304. }
  305. if (_target.showPointLights && _target.PointLightsActive)
  306. if (_target._FogType == FogVolume.FogType.Textured)
  307. {
  308. _target.PointLightsRealTimeUpdate = EditorGUILayout.Toggle(VariableField("Real-time search", "Fog Volume will search for lights in the scene hierarchy. \nEnable this for a brief moment if lights were added to the scene."), _target.PointLightsRealTimeUpdate);
  309. _target.PointLightBoxCheck = EditorGUILayout.Toggle(VariableField("Inside box only", "Computes only lights that are inside of the volume boundaries. Turn off to compute lights that are outside of the volume"), _target.PointLightBoxCheck);
  310. //GUILayout.BeginHorizon=tal("toolbarbutton");
  311. //EditorGUILayout.LabelField("Point lights");
  312. //GUILayout.EndHorizontal();
  313. _target._LightScatterMethod = (FogVolume.LightScatterMethod)EditorGUILayout.EnumPopup("Attenuation Method", _target._LightScatterMethod);
  314. _target.PointLightsIntensity = EditorGUILayout.Slider("Intensity", _target.PointLightsIntensity, 0, 50);
  315. _target.PointLightingDistance = Mathf.Max(1, _target.PointLightingDistance);
  316. _target.PointLightingDistance = EditorGUILayout.FloatField(VariableField("Range clamp", "Use this parameter to limit the spherical distance of the pointlight so that it is not computed when attenuation is zero. Use it to improve performance"), _target.PointLightingDistance);
  317. _target.PointLightingDistance2Camera = Mathf.Max(1, _target.PointLightingDistance2Camera);
  318. _target.PointLightingDistance2Camera = EditorGUILayout.FloatField(VariableField("Draw distance", "Point-light is attenuated at the given distance and turned off as soon as that distance is exceeded"), _target.PointLightingDistance2Camera);
  319. //_target.PointLightScreenMargin = EditorGUILayout.Slider("Discard margin", _target.PointLightScreenMargin, 0, 5);deprecated
  320. _target.PointLightScreenMargin = 0;
  321. _target.PointLightCullSizeMultiplier = EditorGUILayout.FloatField(VariableField("Light visibility", "The higher this value, the further the lights need to be offscreen in order to be discarded by the renderer."), _target.PointLightCullSizeMultiplier);
  322. /*
  323. if (!_target.PointLightsRealTimeUpdate)
  324. {
  325. var FogLights = serializedObject.FindProperty("FogLights");
  326. GUILayout.BeginVertical("box");
  327. EditorGUI.indentLevel++;
  328. EditorGUILayout.PropertyField(FogLights, new GUIContent
  329. ("Editable array"), true);
  330. EditorGUI.indentLevel--;
  331. GUILayout.EndVertical();
  332. }
  333. var PointLightsList = serializedObject.FindProperty("PointLightsList");
  334. GUILayout.BeginVertical("box");
  335. EditorGUI.indentLevel++;
  336. EditorGUILayout.PropertyField(PointLightsList, new GUIContent("Currently computed:"), true);
  337. EditorGUI.indentLevel--;
  338. GUILayout.EndVertical();
  339. */
  340. int totalLightCount = _target.GetTotalLightCount();
  341. int visibleLightCount = _target.GetVisibleLightCount();
  342. EditorGUILayout.HelpBox("Contains " + totalLightCount + " lights", MessageType.None);
  343. EditorGUILayout.HelpBox("Rendering " + visibleLightCount + " lights", MessageType.None);
  344. }
  345. #endregion
  346. #region ColorManagement
  347. //GUILayout.BeginHorizontal("toolbarbutton");
  348. //_target.ColorAdjust = EditorGUILayout.Toggle("Color Settings", _target.ColorAdjust);
  349. //showColorTab = EditorGUILayout.Toggle(" Show \t ", showColorTab);
  350. //GUILayout.EndHorizontal();
  351. if (GUILayout.Button(new GUIContent("Color management", ShowInspectorTooltips? "Color postprocessing such as contrast, brightness and tonemapper":"") , EditorStyles.toolbarButton))
  352. _target.showColorTab = !_target.showColorTab;
  353. if (/*_target.ColorAdjust && */_target.showColorTab)
  354. {
  355. _target.ColorAdjust = EditorGUILayout.Toggle("Active", _target.ColorAdjust);
  356. _target.Offset = EditorGUILayout.Slider("Offset", _target.Offset, -.5f, .5f);
  357. _target.Gamma = EditorGUILayout.Slider("Gamma", _target.Gamma, .01f, 3);
  358. if (_target.ColorAdjust)
  359. _target.Tonemap = EditorGUILayout.Toggle("Tonemap", _target.Tonemap);
  360. if (_target.Tonemap && _target.ColorAdjust)
  361. _target.Exposure = EditorGUILayout.Slider("Exposure", _target.Exposure, 2.5f, 5);
  362. }
  363. #endregion
  364. #region Renderer
  365. if (_target._FogType == FogVolume.FogType.Textured)
  366. {
  367. // GUILayout.BeginHorizontal("toolbarbutton");
  368. // EditorGUILayout.LabelField("Volume properties");
  369. //showVolumeProperties = EditorGUILayout.Toggle("Show", showVolumeProperties);
  370. // GUILayout.EndHorizontal();
  371. if (GUILayout.Button("Renderer", EditorStyles.toolbarButton))
  372. _target.showVolumeProperties = !_target.showVolumeProperties;
  373. if (_target.showVolumeProperties)
  374. {
  375. _target.NoiseIntensity = EditorGUILayout.Slider(VariableField("Intensity", "Opacity of noise and gradients"), _target.NoiseIntensity, 0, 1);
  376. GUILayout.BeginVertical("box");
  377. _target.SceneCollision = EditorGUILayout.Toggle(VariableField("Scene Collision", "Textured fog will collide with environment when set to ON. _CameraDepthTexture is requierd for Scene view collisions. Enable Depth in camera script to generate the depth map required for Game view collisions. Disable if the volume is rendered in the background to avoid unneded computation"), _target.SceneCollision);
  378. if (_target.SceneCollision)
  379. _target._SceneIntersectionSoftness = EditorGUILayout.Slider(VariableField("Softness", "Pixels that get in contact with scene elements are faded to black. Use this slider to control the softeness of this transition"), _target._SceneIntersectionSoftness, 50, .01f);
  380. GUILayout.EndVertical();
  381. _target._jitter = EditorGUILayout.Slider(VariableField("Jitter", "Apply noise to the sample position. Use this in combination with DeNoise (camera script) to conceal the gaps between samples"), _target._jitter, 0, .1f);
  382. _target._SamplingMethod = (FogVolume.SamplingMethod)EditorGUILayout.EnumPopup(VariableField("Sampling Method", "Choose between distance to camera or view aligned planes. Hidden by default: uncomment #pragma shader_feature SAMPLING_METHOD_ViewAligned in FogVolume.shader"), _target._SamplingMethod);
  383. _target.Iterations = EditorGUILayout.IntSlider(VariableField("Max Iterations", "Set the max iterations to perform."), _target.Iterations, 10, 1000);
  384. _target.IterationStep = EditorGUILayout.FloatField(VariableField("Iteration step size", "Distance between iterations"), _target.IterationStep);
  385. _target.FadeDistance = EditorGUILayout.FloatField(VariableField("Draw distance", "Noise is faded to black at the given distance. Loop will stop then"), _target.FadeDistance);
  386. _target._OptimizationFactor = EditorGUILayout.Slider(VariableField("Optimization Factor", "Used to increase the distance between iterations so that we can have more quality at close distances. Far distances will be less opaque"), _target._OptimizationFactor, 0, 5e-09f);
  387. if (_target.EnableNoise)
  388. {
  389. GUILayout.BeginVertical("box");
  390. _target.useHeightGradient = EditorGUILayout.Toggle(VariableField("Height Gradient", "Noise opacity is multiplied with a vertical gradient"), _target.useHeightGradient);
  391. if (_target.useHeightGradient)
  392. {
  393. GUILayout.BeginVertical("box");
  394. _target.GradMin = EditorGUILayout.Slider("Grad 1 Min", _target.GradMin, -1, 1);
  395. _target.GradMax = EditorGUILayout.Slider("Grad 1 Max", _target.GradMax, -1, 1);
  396. GUILayout.EndVertical();
  397. GUILayout.BeginVertical("box");
  398. _target.GradMin2 = EditorGUILayout.Slider("Grad 2 Min", _target.GradMin2, -1, 1);
  399. _target.GradMax2 = EditorGUILayout.Slider("Grad 2 Max", _target.GradMax2, -1, 1);
  400. GUILayout.EndVertical();
  401. }
  402. EditorGUILayout.EndVertical();
  403. }
  404. if (_target.EnableNoise)
  405. {
  406. GUILayout.BeginVertical("box");
  407. _target.bSphericalFade = EditorGUILayout.Toggle(VariableField("Radius Fade", "Multiplies noise opacity with a spherical range. Disabled by default. Uncomment #pragma shader_feature SPHERICAL_FADE in FogVolume.shader to enable"), _target.bSphericalFade);
  408. if (_target.bSphericalFade)
  409. {
  410. _target.SphericalFadeDistance = EditorGUILayout.FloatField("Distance", _target.SphericalFadeDistance);
  411. }
  412. EditorGUILayout.EndVertical();
  413. }
  414. _target._DebugMode = (FogVolume.DebugMode)EditorGUILayout.EnumPopup(VariableField("View mode: ", "Disabled by default. Uncomment #pragma multi_compile _ DEBUG in FogVolume.shader"), _target._DebugMode);
  415. //Primitives
  416. GUILayout.BeginHorizontal("toolbarbutton");
  417. _target.EnableDistanceFields = EditorGUILayout.Toggle("Enable Primitives", _target.EnableDistanceFields);
  418. if (_target.EnableDistanceFields && _target.GetTotalPrimitiveCount() > 0)
  419. EditorGUILayout.LabelField(_target.GetVisiblePrimitiveCount() + " primitives visible | " + _target.GetTotalPrimitiveCount() + " primitives in volume");
  420. else
  421. EditorGUILayout.LabelField("0 primitives visible | 0 primitives in volume");
  422. GUILayout.EndHorizontal();
  423. if (_target.EnableDistanceFields)
  424. {
  425. GUILayout.BeginVertical("box");
  426. _target.ShowPrimitives = EditorGUILayout.Toggle(VariableField("Show primitives", "Enables the primitive renderer component"), _target.ShowPrimitives);
  427. _target.PrimitivesRealTimeUpdate = EditorGUILayout.Toggle(VariableField("Real-time search", "Searches primitives that are inside of the volume. Turn on only to refresh the list"), _target.PrimitivesRealTimeUpdate);
  428. EditorGUILayout.EndVertical();
  429. _target.Constrain = EditorGUILayout.Slider(VariableField("Size", "Overrides the primitive original size"), _target.Constrain, 0, -150);
  430. _target._PrimitiveEdgeSoftener = EditorGUILayout.Slider(VariableField("Softness", "Softens the primitive shape"), _target._PrimitiveEdgeSoftener, 1, 100);
  431. _target._PrimitiveCutout = EditorGUILayout.Slider(VariableField("Cutout", "Cuts the distance field with the primitive boundaries"), _target._PrimitiveCutout, 0, .99999f);
  432. /*
  433. var PrimitivesList = serializedObject.FindProperty("PrimitivesList");
  434. GUILayout.BeginVertical("box");
  435. EditorGUI.indentLevel++;
  436. EditorGUILayout.PropertyField(PrimitivesList, true);
  437. EditorGUI.indentLevel--;
  438. EditorGUILayout.EndVertical();
  439. */
  440. }
  441. }
  442. }
  443. #endregion
  444. #region Noise
  445. if (GUILayout.Button("Noise", EditorStyles.toolbarButton))
  446. _target.showNoiseProperties = !_target.showNoiseProperties;
  447. // GUILayout.BeginHorizontal("toolbarbutton");
  448. //EditorGUILayout.LabelField("");
  449. // showNoiseProperties = EditorGUILayout.Toggle(" Show", showNoiseProperties);
  450. //GUILayout.EndHorizontal();
  451. if (/*_target.EnableNoise && */_target.showNoiseProperties)
  452. {
  453. _target.EnableNoise = EditorGUILayout.Toggle("Active", _target.EnableNoise);
  454. if (_target.EnableNoise)
  455. {
  456. GUILayout.BeginVertical("Box");
  457. EditorGUILayout.LabelField("Common", EditorStyles.boldLabel);
  458. //var TexturesRect = GUILayoutUtility.GetRect(new GUIContent(""), GUIStyle.none);
  459. //EditorGUI.indentLevel++;
  460. //_target.TexturesGroup = EditorGUI.Foldout(TexturesRect, _target.TexturesGroup, "Noise textures");
  461. //if (_target.TexturesGroup)
  462. //{
  463. // _target._NoiseVolume = (Texture3D)EditorGUILayout.ObjectField("Base", _target._NoiseVolume, typeof(Texture3D), false);
  464. // // _target._NoiseVolume2 = (Texture3D)EditorGUILayout.ObjectField("Detail", _target._NoiseVolume2, typeof(Texture3D), false);
  465. // _target.CoverageTex = (Texture2D)EditorGUILayout.ObjectField(VariableField("Coverage (Experimental)",
  466. // "Input texture to add or multiply coverage. This texture is sampled in the vertical axis. Uncomment #define COVERAGE in FogVolume.shader and test scene: Ocean"), _target.CoverageTex, typeof(Texture2D), false);
  467. //}
  468. //EditorGUI.indentLevel--;
  469. // _target.CastShadows = tempShadowCaster;
  470. _target._3DNoiseScale = EditorGUILayout.FloatField(VariableField("Scale", "Global size of all the noise layers"), _target._3DNoiseScale);
  471. //_target.Procedural = EditorGUILayout.Toggle("Procedural", _target.Procedural);
  472. //
  473. #region Coordinates&Deformers
  474. GUILayout.BeginVertical("box");
  475. EditorGUILayout.LabelField("Coordinates", EditorStyles.boldLabel);
  476. _target.Speed = EditorGUILayout.Vector3Field("Scroll", _target.Speed);
  477. _target.Stretch = EditorGUILayout.Vector3Field("Stretch", _target.Stretch);
  478. GUILayout.EndVertical();
  479. GUILayout.BeginVertical("box");
  480. EditorGUILayout.LabelField("Deformers", EditorStyles.boldLabel);
  481. _target.Vortex = EditorGUILayout.Slider(VariableField("Swirl", "Twist the space. Very useful to break tiling"), _target.Vortex, 0, 3);
  482. if (_target.Vortex > 0)
  483. {
  484. _target.RotationSpeed = EditorGUILayout.Slider("Rotation Speed", _target.RotationSpeed, 0, 10);
  485. _target.rotation = EditorGUILayout.Slider("Rotation", _target.rotation, 0, 360);
  486. _target._VortexAxis = (FogVolume.VortexAxis)EditorGUILayout.EnumPopup("Axis", _target._VortexAxis);
  487. }
  488. GUILayout.EndVertical();
  489. //
  490. GUILayout.EndVertical();
  491. // GUILayout.EndVertical();
  492. #endregion
  493. GUILayout.BeginVertical("Box");
  494. EditorGUILayout.LabelField("Base layer", EditorStyles.boldLabel);
  495. _target.Coverage = EditorGUILayout.Slider(VariableField("Coverage", "Multiplies the base layer intensity. Lighting is affected as density increases"), _target.Coverage, 0, 5);
  496. _target.NoiseContrast = EditorGUILayout.Slider(VariableField("Contrast", "Apply contrast to noise. High values creates more empty space, which is good for performance"), _target.NoiseContrast, 0, 20);
  497. _target.NoiseDensity = EditorGUILayout.Slider(VariableField(
  498. "Density", "Opacity of the final noise. This won't change the shape of the noise as Intensity does. It only affects the density / opacity of the noise"),
  499. _target.NoiseDensity, 0, 20);
  500. _target.Octaves = EditorGUILayout.IntSlider(VariableField("Octaves", "How many layers of noise to use"), _target.Octaves, 1, 5);
  501. _target.BaseTiling = EditorGUILayout.FloatField(VariableField("Base Tiling", "Independent scale for this layer"), _target.BaseTiling);
  502. _target._BaseRelativeSpeed = EditorGUILayout.Slider(VariableField("Speed", "Independent speed multiplier for this layer"), _target._BaseRelativeSpeed, 0, 4);
  503. GUILayout.EndVertical();
  504. GUILayout.BeginVertical("Box");
  505. EditorGUILayout.LabelField("Detail layer", EditorStyles.boldLabel);
  506. _target.DetailTiling = EditorGUILayout.FloatField("Tiling", _target.DetailTiling);
  507. _target._DetailRelativeSpeed = EditorGUILayout.Slider("Speed", _target._DetailRelativeSpeed, 0, 20);
  508. _target.DetailDistance = EditorGUILayout.FloatField(VariableField("Draw Distance", "This layer is a lot more costly than the base. Limit the draw distance to incerase performance"), _target.DetailDistance);
  509. if (_target.DetailDistance > 0)
  510. {
  511. _target._NoiseDetailRange = EditorGUILayout.Slider(VariableField("Trim",
  512. "The detail layer is used to cut the base layer at the edges. If contrast is not too high, this will be more effective"), _target._NoiseDetailRange, 0, 1);
  513. _target._DetailMaskingThreshold = EditorGUILayout.Slider(VariableField
  514. ("Trim Threshold", "Detail layer is applied only at the edges of the base layer. Use this slider to control the size of this edge"),
  515. _target._DetailMaskingThreshold, 1, 350);
  516. //_target.DetailSamplingBaseOpacityLimit = EditorGUILayout.Slider(VariableField("Cutoff", "This is the threshold to stop the detail sampling. We don't compute detail when the base layer opacity is higher than this value"), _target.DetailSamplingBaseOpacityLimit, 0, 1);
  517. if (_target.Octaves > 1)
  518. _target._Curl = EditorGUILayout.Slider(VariableField("Curl", "Used to distort the edges. Check the 'Time of Day' demo to see this in action"), _target._Curl, 0, 1);
  519. }
  520. GUILayout.EndVertical();
  521. //_target.noise2D= (Texture2D)EditorGUILayout.ObjectField("noise2D", _target.noise2D, typeof(Texture2D), false);
  522. }
  523. }
  524. #endregion
  525. #region Gradient
  526. if (GUILayout.Button("Gradient", EditorStyles.toolbarButton))
  527. _target.showGradient = !_target.showGradient;
  528. if (_target.showGradient)
  529. {
  530. _target.EnableGradient = EditorGUILayout.Toggle("Active", _target.EnableGradient);
  531. if (_target.EnableGradient)
  532. _target.Gradient = (Texture2D)EditorGUILayout.ObjectField("", _target.Gradient, typeof(Texture2D), true);
  533. }
  534. #endregion
  535. #region Footer
  536. GUILayout.EndVertical();//termina estilo anterior
  537. EditorGUI.indentLevel++;
  538. if (GUILayout.Button("Other", EditorStyles.toolbarButton))
  539. _target.OtherTAB = !_target.OtherTAB;
  540. GUILayout.BeginVertical(ThemeFooter);
  541. if (_target.OtherTAB)
  542. {
  543. GUILayout.Space(10);
  544. var OtherRect = GUILayoutUtility.GetRect(new GUIContent(""), GUIStyle.none);
  545. _target.showOtherOptions = EditorGUI.Foldout(OtherRect, _target.showOtherOptions, "Rendering options");
  546. if (_target.showOtherOptions)
  547. {
  548. //EditorGUI.indentLevel++;
  549. // if(!_target.CreateSurrogate)
  550. _target.DrawOrder = EditorGUILayout.IntField(new GUIContent("DrawOrder", "Ignored when surrogates are not created manually"), _target.DrawOrder);
  551. _target._PushAlpha = EditorGUILayout.Slider(new GUIContent("Push Alpha", "Compensate opacity when samples are not enough"), _target._PushAlpha, 1, 2f);
  552. _target._ztest = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("ZTest ", _target._ztest);
  553. if (_target.GameCameraGO != null /*&& _target._FogType == FogVolume.FogType.Textured*/)
  554. if (_target.GameCameraGO.GetComponent<FogVolumeRenderer>() &&
  555. _target.GameCameraGO.GetComponent<FogVolumeRenderer>()._Downsample > 0 &&
  556. _target._FogType == FogVolume.FogType.Textured)
  557. _target.CreateSurrogate = EditorGUILayout.Toggle(VariableField("Create Surrogate mesh",
  558. "A copy of the volume mesh is created to project the result of the low-res render. This is good for preview, but usually, we have to create surrogate meshes by hand to sort them manually"), _target.CreateSurrogate);
  559. _target._VisibleByReflectionProbeStatic = EditorGUILayout.Toggle("Visible for static probe", _target._VisibleByReflectionProbeStatic);
  560. _target.RenderableInSceneView = EditorGUILayout.Toggle(VariableField("Render In Scene View", "Volume is not visible in Scene view. Please not that it won't be visible for reflection probes either"), _target.RenderableInSceneView);
  561. _target.ExcludeFromLowRes = EditorGUILayout.Toggle(VariableField("Exclude from low res",
  562. "Exclude this fog volume from the main game camera low res process\n" +
  563. "Enable and change the layer\n useful when rendering underwater fog with another camera\nA custom depth buffer can be injected uncommenting this line: #pragma multi_compile _ ExternalDepth"), _target.ExcludeFromLowRes);
  564. if (_target.ExcludeFromLowRes)
  565. _target.InjectCustomDepthBuffer = EditorGUILayout.Toggle(VariableField("External depth buffer",
  566. "Feed this Volume with a custom depth buffer with name: _CustomCameraDepthTexture\n useful when rendering underwater fog with another camera that has horizontal clip plane\nUncomment this line: #pragma multi_compile _ ExternalDepth"), _target.InjectCustomDepthBuffer);
  567. }
  568. GUILayout.Space(10);
  569. var DebugOptionsRect = GUILayoutUtility.GetRect(new GUIContent(""), GUIStyle.none);
  570. _target.showDebugOptions = EditorGUI.Foldout(DebugOptionsRect, _target.showDebugOptions, "Debug options");
  571. if (_target.showDebugOptions)
  572. {
  573. _target.ShowDebugGizmos =
  574. EditorGUILayout.Toggle("Draw Debug Gizmos", _target.ShowDebugGizmos);
  575. }
  576. GUILayout.Space(10);
  577. var CustomizationOptionsRect = GUILayoutUtility.GetRect(new GUIContent(""), GUIStyle.none);
  578. _target.showCustomizationOptions = EditorGUI.Foldout(CustomizationOptionsRect, _target.showCustomizationOptions, "Customize look");
  579. if (_target.showCustomizationOptions)
  580. {
  581. // EditorGUI.indentLevel++;
  582. // _target._InspectorBackground = (Texture2D)EditorGUILayout.ObjectField("Background", _target._InspectorBackground, typeof(Texture2D), false);
  583. if (EditorGUIUtility.isProSkin)
  584. {
  585. if (_target._InspectorBackground.Length > 0)
  586. _target._InspectorBackgroundIndex =
  587. EditorGUILayout.IntSlider("Inspector background",
  588. _target._InspectorBackgroundIndex,
  589. 0,
  590. _target._InspectorBackground.Length -
  591. 1);
  592. }
  593. _target.HideWireframe = EditorGUILayout.Toggle("Scene view wireframe", _target.HideWireframe);
  594. ShowInspectorTooltips = EditorGUILayout.Toggle(new GUIContent("Enable inspector tooltips", "Work in progress"), ShowInspectorTooltips);
  595. // EditorGUI.indentLevel--;
  596. }
  597. GUILayout.Space(10);
  598. bool prevSaveMaterials = _target.SaveMaterials;
  599. _target.SaveMaterials =
  600. EditorGUILayout.Toggle(new GUIContent("Save Materials", "Ensures that material shaders are built correctly when creating a platform specific build."),
  601. _target.SaveMaterials);
  602. if (prevSaveMaterials != _target.SaveMaterials && _target.SaveMaterials)
  603. {
  604. _target.RequestSavingMaterials = true;
  605. }
  606. else
  607. {
  608. _target.RequestSavingMaterials = false;
  609. }
  610. }
  611. if (_target._InspectorBackground.Length > 0)
  612. if (_target._InspectorBackground[_target._InspectorBackgroundIndex] != null && EditorGUIUtility.isProSkin)
  613. Theme1.normal.background = _target._InspectorBackground[_target._InspectorBackgroundIndex];
  614. GUILayout.EndVertical();//end footer style
  615. EditorGUI.indentLevel--;
  616. //GUI.backgroundColor = new Color(.9f, .5f, .9f);
  617. #endregion
  618. #region Info
  619. if (GUILayout.Button("Info", EditorStyles.toolbarButton))
  620. _target.generalInfo = !_target.generalInfo;
  621. if (_target.generalInfo)
  622. {
  623. GUILayout.BeginVertical("box");
  624. EditorGUILayout.LabelField("Description",EditorStyles.boldLabel);
  625. _target.Description = EditorGUILayout.TextArea(_target.Description, GUILayout.MaxWidth(300));
  626. EditorGUILayout.LabelField("Version 3.4");
  627. EditorGUILayout.LabelField("Release date: May 2018");
  628. EditorGUILayout.LabelField("Fog type: " + _target._FogType.ToString());
  629. #region Camera
  630. if (_target.GameCameraGO)
  631. {
  632. EditorGUILayout.LabelField("Assigned camera: " + _target.GameCameraGO.name);
  633. if (GUILayout.Button("Select " + _target.GameCameraGO.name, EditorStyles.toolbarButton))
  634. Selection.activeGameObject = _target.GameCameraGO;
  635. }
  636. else
  637. GUILayout.Button("No valid camera found", EditorStyles.toolbarButton);
  638. GUILayout.EndVertical();
  639. GUILayout.Space(10);
  640. #endregion
  641. }
  642. #endregion
  643. if (EditorGUI.EndChangeCheck())
  644. {
  645. EditorUtility.SetDirty(target);
  646. }
  647. serializedObject.ApplyModifiedProperties();
  648. }
  649. }