ViewerWater.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using OpenMetaverse;
  29. using OpenMetaverse.StructuredData;
  30. namespace OpenSim.Framework
  31. {
  32. public class WaterData
  33. {
  34. public UUID normalMap = new("822ded49-9a6c-f61c-cb89-6df54f42cdf4");
  35. public UUID transpTexture = new("2bfd3884-7e27-69b9-ba3a-3e673f680004");
  36. public float blurMultiplier = 0.04f;
  37. public float fresnelOffset = 0.5f;
  38. public float fresnelScale = 0.4f;
  39. public Vector3 normScale = new(2f, 2f, 2f);
  40. public float scaleAbove = 0.03f;
  41. public float scaleBelow = 0.2f;
  42. public float underWaterFogMod = 0.25f;
  43. public Vector3 waterFogColor = new(0.0156f, 0.149f, 0.2509f);
  44. public float waterFogDensity = 10;
  45. public Vector2 wave1Dir = new(1.05f, -0.42f);
  46. public Vector2 wave2Dir = new(1.11f, -1.16f);
  47. public string Name;
  48. public void FromWLOSD(string name, OSD osd)
  49. {
  50. Vector4 v4tmp;
  51. OSDMap map = osd as OSDMap;
  52. blurMultiplier = map["blurMultiplier"];
  53. fresnelOffset = map["fresnelOffset"];
  54. fresnelScale = map["fresnelScale"];
  55. normScale = map["normScale"];
  56. normalMap = map["normalMap"];
  57. scaleAbove = map["scaleAbove"];
  58. scaleBelow = map["scaleBelow"];
  59. underWaterFogMod = map["underWaterFogMod"];
  60. v4tmp = map["waterFogColor"];
  61. waterFogColor = new Vector3(v4tmp.X, v4tmp.Y, v4tmp.Z);
  62. waterFogDensity = map["waterFogDensity"];
  63. wave1Dir = map["wave1Dir"];
  64. wave2Dir = map["wave2Dir"];
  65. Name = name;
  66. }
  67. public OSDMap ToWLOSD()
  68. {
  69. return new OSDMap
  70. {
  71. ["blurMultiplier"] = blurMultiplier,
  72. ["fresnelOffset"] = fresnelOffset,
  73. ["fresnelScale"] = fresnelScale,
  74. ["normScale"] = normScale,
  75. ["normalMap"] = normalMap,
  76. ["scaleAbove"] = scaleAbove,
  77. ["scaleBelow"] = scaleBelow,
  78. ["underWaterFogMod"] = underWaterFogMod,
  79. ["waterFogColor"] = new Vector4(waterFogColor.X, waterFogColor.Y, waterFogColor.Z, 1),
  80. ["waterFogDensity"] = waterFogDensity,
  81. //["waterFogDensity"] = MathF.Pow(2.0f, waterFogDensity),
  82. ["wave1Dir"] = wave1Dir,
  83. ["wave2Dir"] = wave2Dir
  84. };
  85. }
  86. public void FromOSD(string name, OSDMap map)
  87. {
  88. OSD otmp;
  89. if (map.TryGetValue("blur_multiplier", out otmp))
  90. blurMultiplier = otmp;
  91. if (map.TryGetValue("fresnel_offset", out otmp))
  92. fresnelOffset = otmp;
  93. if (map.TryGetValue("fresnel_scale", out otmp))
  94. fresnelScale = otmp;
  95. if (map.TryGetValue("normal_scale", out otmp))
  96. normScale = otmp;
  97. if (map.TryGetValue("normal_map", out otmp))
  98. normalMap = otmp;
  99. if (map.TryGetValue("scale_above", out otmp))
  100. scaleAbove = otmp;
  101. if (map.TryGetValue("scale_below", out otmp))
  102. scaleBelow = otmp;
  103. if (map.TryGetValue("underwater_fog_mod", out otmp))
  104. underWaterFogMod = otmp;
  105. if (map.TryGetValue("water_fog_color", out otmp))
  106. waterFogColor = otmp;
  107. if (map.TryGetValue("water_fog_density", out otmp))
  108. waterFogDensity = otmp;
  109. if (map.TryGetValue("wave1_direction", out otmp))
  110. wave1Dir = otmp;
  111. if (map.TryGetValue("wave2_direction", out otmp))
  112. wave2Dir = otmp;
  113. if (map.TryGetValue("transparent_texture", out otmp))
  114. transpTexture = otmp;
  115. Name = name;
  116. }
  117. public OSDMap ToOSD()
  118. {
  119. return new OSDMap
  120. {
  121. ["blur_multiplier"] = blurMultiplier,
  122. ["fresnel_offset"] = fresnelOffset,
  123. ["fresnel_scale"] = fresnelScale,
  124. ["normal_scale"] = normScale,
  125. ["normal_map"] = normalMap,
  126. ["scale_above"] = scaleAbove,
  127. ["scale_below"] = scaleBelow,
  128. ["underwater_fog_mod"] = underWaterFogMod,
  129. ["water_fog_color"] = waterFogColor,
  130. ["water_fog_density"] = waterFogDensity,
  131. ["wave1_direction"] = wave1Dir,
  132. ["wave2_direction"] = wave2Dir,
  133. ["transparent_texture"] = transpTexture,
  134. ["type"] = "water"
  135. };
  136. }
  137. public void GatherAssets(Dictionary<UUID, sbyte> uuids)
  138. {
  139. Util.AddToGatheredIds(uuids, normalMap, (sbyte)AssetType.Texture);
  140. Util.AddToGatheredIds(uuids, transpTexture, (sbyte)AssetType.Texture);
  141. }
  142. }
  143. }