PageRenderTime 427ms CodeModel.GetById 232ms RepoModel.GetById 6ms app.codeStats 0ms

/indra/newview/llwaterparamset.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 268 lines | 191 code | 37 blank | 40 comment | 28 complexity | c11b03293e5e8f65ea63e59e6c56791c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwaterparamset.cpp
  3. * @brief Implementation for the LLWaterParamSet class.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llwaterparamset.h"
  28. #include "llsd.h"
  29. #include "llwaterparammanager.h"
  30. #include "lluictrlfactory.h"
  31. #include "llsliderctrl.h"
  32. #include "llviewertexturelist.h"
  33. #include "llviewercontrol.h"
  34. #include "lluuid.h"
  35. #include <llgl.h>
  36. #include <sstream>
  37. LLWaterParamSet::LLWaterParamSet(void) :
  38. mName("Unnamed Preset")
  39. {
  40. LLSD vec4;
  41. LLSD vec3;
  42. LLSD real(0.0f);
  43. vec4 = LLSD::emptyArray();
  44. vec4.append(22.f/255.f);
  45. vec4.append(43.f/255.f);
  46. vec4.append(54.f/255.f);
  47. vec4.append(0.f/255.f);
  48. vec3 = LLSD::emptyArray();
  49. vec3.append(2);
  50. vec3.append(2);
  51. vec3.append(2);
  52. LLSD wave1, wave2;
  53. wave1 = LLSD::emptyArray();
  54. wave2 = LLSD::emptyArray();
  55. wave1.append(0.5f);
  56. wave1.append(-.17f);
  57. wave2.append(0.58f);
  58. wave2.append(-.67f);
  59. mParamValues.insert("waterFogColor", vec4);
  60. mParamValues.insert("waterFogDensity", 16.0f);
  61. mParamValues.insert("underWaterFogMod", 0.25f);
  62. mParamValues.insert("normScale", vec3);
  63. mParamValues.insert("fresnelScale", 0.5f);
  64. mParamValues.insert("fresnelOffset", 0.4f);
  65. mParamValues.insert("scaleAbove", 0.025f);
  66. mParamValues.insert("scaleBelow", 0.2f);
  67. mParamValues.insert("blurMultiplier", 0.01f);
  68. mParamValues.insert("wave1Dir", wave1);
  69. mParamValues.insert("wave2Dir", wave2);
  70. mParamValues.insert("normalMap", DEFAULT_WATER_NORMAL);
  71. }
  72. void LLWaterParamSet::set(const std::string& paramName, float x)
  73. {
  74. // handle case where no array
  75. if(mParamValues[paramName].isReal())
  76. {
  77. mParamValues[paramName] = x;
  78. }
  79. // handle array
  80. else if(mParamValues[paramName].isArray() &&
  81. mParamValues[paramName][0].isReal())
  82. {
  83. mParamValues[paramName][0] = x;
  84. }
  85. }
  86. void LLWaterParamSet::set(const std::string& paramName, float x, float y) {
  87. mParamValues[paramName][0] = x;
  88. mParamValues[paramName][1] = y;
  89. }
  90. void LLWaterParamSet::set(const std::string& paramName, float x, float y, float z)
  91. {
  92. mParamValues[paramName][0] = x;
  93. mParamValues[paramName][1] = y;
  94. mParamValues[paramName][2] = z;
  95. }
  96. void LLWaterParamSet::set(const std::string& paramName, float x, float y, float z, float w)
  97. {
  98. mParamValues[paramName][0] = x;
  99. mParamValues[paramName][1] = y;
  100. mParamValues[paramName][2] = z;
  101. mParamValues[paramName][3] = w;
  102. }
  103. void LLWaterParamSet::set(const std::string& paramName, const float * val)
  104. {
  105. mParamValues[paramName][0] = val[0];
  106. mParamValues[paramName][1] = val[1];
  107. mParamValues[paramName][2] = val[2];
  108. mParamValues[paramName][3] = val[3];
  109. }
  110. void LLWaterParamSet::set(const std::string& paramName, const LLVector4 & val)
  111. {
  112. mParamValues[paramName][0] = val.mV[0];
  113. mParamValues[paramName][1] = val.mV[1];
  114. mParamValues[paramName][2] = val.mV[2];
  115. mParamValues[paramName][3] = val.mV[3];
  116. }
  117. void LLWaterParamSet::set(const std::string& paramName, const LLColor4 & val)
  118. {
  119. mParamValues[paramName][0] = val.mV[0];
  120. mParamValues[paramName][1] = val.mV[1];
  121. mParamValues[paramName][2] = val.mV[2];
  122. mParamValues[paramName][3] = val.mV[3];
  123. }
  124. LLVector4 LLWaterParamSet::getVector4(const std::string& paramName, bool& error)
  125. {
  126. // test to see if right type
  127. LLSD cur_val = mParamValues.get(paramName);
  128. if (!cur_val.isArray() || cur_val.size() != 4)
  129. {
  130. error = true;
  131. return LLVector4(0,0,0,0);
  132. }
  133. LLVector4 val;
  134. val.mV[0] = (F32) cur_val[0].asReal();
  135. val.mV[1] = (F32) cur_val[1].asReal();
  136. val.mV[2] = (F32) cur_val[2].asReal();
  137. val.mV[3] = (F32) cur_val[3].asReal();
  138. error = false;
  139. return val;
  140. }
  141. LLVector3 LLWaterParamSet::getVector3(const std::string& paramName, bool& error)
  142. {
  143. // test to see if right type
  144. LLSD cur_val = mParamValues.get(paramName);
  145. if (!cur_val.isArray()|| cur_val.size() != 3)
  146. {
  147. error = true;
  148. return LLVector3(0,0,0);
  149. }
  150. LLVector3 val;
  151. val.mV[0] = (F32) cur_val[0].asReal();
  152. val.mV[1] = (F32) cur_val[1].asReal();
  153. val.mV[2] = (F32) cur_val[2].asReal();
  154. error = false;
  155. return val;
  156. }
  157. LLVector2 LLWaterParamSet::getVector2(const std::string& paramName, bool& error)
  158. {
  159. // test to see if right type
  160. int ttest;
  161. ttest = mParamValues.size();
  162. LLSD cur_val = mParamValues.get(paramName);
  163. if (!cur_val.isArray() || cur_val.size() != 2)
  164. {
  165. error = true;
  166. return LLVector2(0,0);
  167. }
  168. LLVector2 val;
  169. val.mV[0] = (F32) cur_val[0].asReal();
  170. val.mV[1] = (F32) cur_val[1].asReal();
  171. error = false;
  172. return val;
  173. }
  174. F32 LLWaterParamSet::getFloat(const std::string& paramName, bool& error)
  175. {
  176. // test to see if right type
  177. LLSD cur_val = mParamValues.get(paramName);
  178. if (cur_val.isArray() && cur_val.size() != 0)
  179. {
  180. error = false;
  181. return (F32) cur_val[0].asReal();
  182. }
  183. if(cur_val.isReal())
  184. {
  185. error = false;
  186. return (F32) cur_val.asReal();
  187. }
  188. error = true;
  189. return 0;
  190. }
  191. // Added for interpolation effect in DEV-33645
  192. // Based on LLWLParamSet::mix, but written by Jacob without an intimate knowledge of how WindLight works.
  193. // The function definition existed in the header but was never implemented. If you think there is something
  194. // wrong with this, you're probably right. Ask Jacob, Q, or a member of the original WindLight team.
  195. void LLWaterParamSet::mix(LLWaterParamSet& src, LLWaterParamSet& dest, F32 weight)
  196. {
  197. // Setup
  198. LLSD srcVal, destVal; // LLSD holders for get/set calls, reusable
  199. // Iterate through values
  200. for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
  201. {
  202. // If param exists in both src and dest, set the holder variables, otherwise skip
  203. if(src.mParamValues.has(iter->first) && dest.mParamValues.has(iter->first))
  204. {
  205. srcVal = src.mParamValues[iter->first];
  206. destVal = dest.mParamValues[iter->first];
  207. }
  208. else
  209. {
  210. continue;
  211. }
  212. if(iter->second.isReal()) // If it's a real, interpolate directly
  213. {
  214. iter->second = srcVal.asReal() + ((destVal.asReal() - srcVal.asReal()) * weight);
  215. }
  216. else if(iter->second.isArray() && iter->second[0].isReal() // If it's an array of reals, loop through the reals and interpolate on those
  217. && iter->second.size() == srcVal.size() && iter->second.size() == destVal.size())
  218. {
  219. // Actually do interpolation: old value + (difference in values * factor)
  220. for(int i=0; i < iter->second.size(); ++i)
  221. {
  222. // iter->second[i] = (1.f-weight)*(F32)srcVal[i].asReal() + weight*(F32)destVal[i].asReal(); // old way of doing it -- equivalent but one more operation
  223. iter->second[i] = srcVal[i].asReal() + ((destVal[i].asReal() - srcVal[i].asReal()) * weight);
  224. }
  225. }
  226. else // Else, skip
  227. {
  228. continue;
  229. }
  230. }
  231. }