VolumetricFog.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function VolumetricFog::onEnterFog(%this,%obj)
  23. {
  24. // This method is called whenever the control object (Camera or Player)
  25. // %obj enters the fog area.
  26. // echo("Control Object " @ %obj @ " enters fog " @ %this);
  27. }
  28. function VolumetricFog::onLeaveFog(%this,%obj)
  29. {
  30. // This method is called whenever the control object (Camera or Player)
  31. // %obj leaves the fog area.
  32. // echo("Control Object " @ %obj @ " left fog " @ %this);
  33. }
  34. function VolumetricFog::Dissolve(%this,%speed,%delete)
  35. {
  36. // This method dissolves the fog at speed milliseconds
  37. %this.isBuilding = true;
  38. if (%this.FogDensity > 0)
  39. {
  40. %this.setFogDensity(%this.FogDensity - 0.005);
  41. %this.schedule(%speed,Dissolve,%speed,%delete);
  42. }
  43. else
  44. {
  45. %this.isBuilding = false;
  46. %this.SetFogDensity(0.0);
  47. if (%delete !$= "" && %delete !$="0" && %delete !$="false")
  48. %this.schedule(250,delete);
  49. }
  50. }
  51. function VolumetricFog::Thicken(%this,%speed, %end_density)
  52. {
  53. // This method thickens the fog at speed milliseconds to a density of %end_density
  54. %this.isBuilding = true;
  55. if (%this.FogDensity + 0.005 < %end_density)
  56. {
  57. %this.setFogDensity(%this.FogDensity + 0.005);
  58. %this.schedule(%speed,Thicken,%speed, %end_density);
  59. }
  60. else
  61. {
  62. %this.setFogDensity(%end_density);
  63. %this.isBuilding = false;
  64. }
  65. }
  66. function GenerateFog(%pos,%scale,%color,%density)
  67. {
  68. // This function can be used to generate some fog caused by massive gunfire etc.
  69. // Change shape and modulation data to your likings.
  70. %fog=new VolumetricFog() {
  71. shapeName = "art/environment/Fog_Sphere.dts";
  72. fogColor = %color;
  73. fogDensity = "0.0";
  74. ignoreWater = "0";
  75. MinSize = "250";
  76. FadeSize = "750";
  77. texture = "art/environment/FogMod_heavy.dds";
  78. tiles = "1";
  79. modStrength = "0.2";
  80. PrimSpeed = "-0.01 0.04";
  81. SecSpeed = "0.02 0.02";
  82. position = %pos;
  83. rotation = "0 0 1 20.354";
  84. scale = %scale;
  85. canSave = "1";
  86. canSaveDynamicFields = "1";
  87. };
  88. if (isObject(%fog))
  89. {
  90. MissionCleanup.add(%fog);
  91. %fog.Thicken(500,%density);
  92. }
  93. return %fog;
  94. }