PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llwaterparammanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 415 lines | 272 code | 85 blank | 58 comment | 2 complexity | 63d6b9d69c9cfb905ca5a35e1cd55d59 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llwaterparammanager.h
  3. * @brief Implementation for the LLWaterParamManager class.
  4. *
  5. * $LicenseInfo:firstyear=2007&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. #ifndef LL_WATER_PARAMMANAGER_H
  27. #define LL_WATER_PARAMMANAGER_H
  28. #include <list>
  29. #include <map>
  30. #include "llwaterparamset.h"
  31. #include "llviewercamera.h"
  32. #include "v4color.h"
  33. const F32 WATER_FOG_LIGHT_CLAMP = 0.3f;
  34. // color control
  35. struct WaterColorControl {
  36. F32 mR, mG, mB, mA, mI; /// the values
  37. std::string mName; /// name to use to dereference params
  38. std::string mSliderName; /// name of the slider in menu
  39. bool mHasSliderName; /// only set slider name for true color types
  40. inline WaterColorControl(F32 red, F32 green, F32 blue, F32 alpha,
  41. F32 intensity, const std::string& n, const std::string& sliderName = LLStringUtil::null)
  42. : mR(red), mG(green), mB(blue), mA(alpha), mI(intensity), mName(n), mSliderName(sliderName)
  43. {
  44. // if there's a slider name, say we have one
  45. mHasSliderName = false;
  46. if (mSliderName != "") {
  47. mHasSliderName = true;
  48. }
  49. }
  50. inline WaterColorControl & operator = (LLColor4 const & val)
  51. {
  52. mR = val.mV[0];
  53. mG = val.mV[1];
  54. mB = val.mV[2];
  55. mA = val.mV[3];
  56. return *this;
  57. }
  58. inline operator LLColor4 (void) const
  59. {
  60. return LLColor4(mR, mG, mB, mA);
  61. }
  62. inline WaterColorControl & operator = (LLVector4 const & val)
  63. {
  64. mR = val.mV[0];
  65. mG = val.mV[1];
  66. mB = val.mV[2];
  67. mA = val.mV[3];
  68. return *this;
  69. }
  70. inline operator LLVector4 (void) const
  71. {
  72. return LLVector4(mR, mG, mB, mA);
  73. }
  74. inline operator LLVector3 (void) const
  75. {
  76. return LLVector3(mR, mG, mB);
  77. }
  78. inline void update(LLWaterParamSet & params) const
  79. {
  80. params.set(mName, mR, mG, mB, mA);
  81. }
  82. };
  83. struct WaterVector3Control
  84. {
  85. F32 mX;
  86. F32 mY;
  87. F32 mZ;
  88. std::string mName;
  89. // basic constructor
  90. inline WaterVector3Control(F32 valX, F32 valY, F32 valZ, const std::string& n)
  91. : mX(valX), mY(valY), mZ(valZ), mName(n)
  92. {
  93. }
  94. inline WaterVector3Control & operator = (LLVector3 const & val)
  95. {
  96. mX = val.mV[0];
  97. mY = val.mV[1];
  98. mZ = val.mV[2];
  99. return *this;
  100. }
  101. inline void update(LLWaterParamSet & params) const
  102. {
  103. params.set(mName, mX, mY, mZ);
  104. }
  105. };
  106. struct WaterVector2Control
  107. {
  108. F32 mX;
  109. F32 mY;
  110. std::string mName;
  111. // basic constructor
  112. inline WaterVector2Control(F32 valX, F32 valY, const std::string& n)
  113. : mX(valX), mY(valY), mName(n)
  114. {
  115. }
  116. inline WaterVector2Control & operator = (LLVector2 const & val)
  117. {
  118. mX = val.mV[0];
  119. mY = val.mV[1];
  120. return *this;
  121. }
  122. inline void update(LLWaterParamSet & params) const
  123. {
  124. params.set(mName, mX, mY);
  125. }
  126. };
  127. // float slider control
  128. struct WaterFloatControl
  129. {
  130. F32 mX;
  131. std::string mName;
  132. F32 mMult;
  133. inline WaterFloatControl(F32 val, const std::string& n, F32 m=1.0f)
  134. : mX(val), mName(n), mMult(m)
  135. {
  136. }
  137. inline WaterFloatControl & operator = (LLVector4 const & val)
  138. {
  139. mX = val.mV[0];
  140. return *this;
  141. }
  142. inline operator F32 (void) const
  143. {
  144. return mX;
  145. }
  146. inline void update(LLWaterParamSet & params) const
  147. {
  148. params.set(mName, mX);
  149. }
  150. };
  151. // float slider control
  152. struct WaterExpFloatControl
  153. {
  154. F32 mExp;
  155. std::string mName;
  156. F32 mBase;
  157. inline WaterExpFloatControl(F32 val, const std::string& n, F32 b)
  158. : mExp(val), mName(n), mBase(b)
  159. {
  160. }
  161. inline WaterExpFloatControl & operator = (F32 val)
  162. {
  163. mExp = log(val) / log(mBase);
  164. return *this;
  165. }
  166. inline operator F32 (void) const
  167. {
  168. return pow(mBase, mExp);
  169. }
  170. inline void update(LLWaterParamSet & params) const
  171. {
  172. params.set(mName, pow(mBase, mExp));
  173. }
  174. };
  175. /// WindLight parameter manager class - what controls all the wind light shaders
  176. class LLWaterParamManager : public LLSingleton<LLWaterParamManager>
  177. {
  178. LOG_CLASS(LLWaterParamManager);
  179. public:
  180. typedef std::list<std::string> preset_name_list_t;
  181. typedef std::map<std::string, LLWaterParamSet> preset_map_t;
  182. typedef boost::signals2::signal<void()> preset_list_signal_t;
  183. /// save the parameter presets to file
  184. void savePreset(const std::string & name);
  185. /// send the parameters to the shaders
  186. void propagateParameters(void);
  187. // display specified water
  188. void applyParams(const LLSD& params, bool interpolate);
  189. /// update information for the shader
  190. void update(LLViewerCamera * cam);
  191. /// Update shader uniforms that have changed.
  192. void updateShaderUniforms(LLGLSLShader * shader);
  193. /// add a param to the list
  194. bool addParamSet(const std::string& name, LLWaterParamSet& param);
  195. /// add a param to the list
  196. BOOL addParamSet(const std::string& name, LLSD const & param);
  197. /// get a param from the list
  198. bool getParamSet(const std::string& name, LLWaterParamSet& param);
  199. /// check whether the preset is in the list
  200. bool hasParamSet(const std::string& name);
  201. /// set the param in the list with a new param
  202. bool setParamSet(const std::string& name, LLWaterParamSet& param);
  203. /// set the param in the list with a new param
  204. bool setParamSet(const std::string& name, LLSD const & param);
  205. /// gets rid of a parameter and any references to it
  206. /// returns true if successful
  207. bool removeParamSet(const std::string& name, bool delete_from_disk);
  208. /// @return true if the preset comes out of the box
  209. bool isSystemPreset(const std::string& preset_name) const;
  210. /// @return all named water presets.
  211. const preset_map_t& getPresets() const { return mParamList; }
  212. /// @return user and system preset names as a single list
  213. void getPresetNames(preset_name_list_t& presets) const;
  214. /// @return user and system preset names separately
  215. void getPresetNames(preset_name_list_t& user_presets, preset_name_list_t& system_presets) const;
  216. /// @return list of user presets names
  217. void getUserPresetNames(preset_name_list_t& user_presets) const;
  218. /// Emitted when a preset gets added or deleted.
  219. boost::signals2::connection setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb);
  220. /// set the normap map we want for water
  221. bool setNormalMapID(const LLUUID& img);
  222. void setDensitySliderValue(F32 val);
  223. /// getters for all the different things water param manager maintains
  224. LLUUID getNormalMapID(void);
  225. LLVector2 getWave1Dir(void);
  226. LLVector2 getWave2Dir(void);
  227. F32 getScaleAbove(void);
  228. F32 getScaleBelow(void);
  229. LLVector3 getNormalScale(void);
  230. F32 getFresnelScale(void);
  231. F32 getFresnelOffset(void);
  232. F32 getBlurMultiplier(void);
  233. F32 getFogDensity(void);
  234. LLColor4 getFogColor(void);
  235. public:
  236. LLWaterParamSet mCurParams;
  237. /// Atmospherics
  238. WaterColorControl mFogColor;
  239. WaterExpFloatControl mFogDensity;
  240. WaterFloatControl mUnderWaterFogMod;
  241. /// wavelet scales and directions
  242. WaterVector3Control mNormalScale;
  243. WaterVector2Control mWave1Dir;
  244. WaterVector2Control mWave2Dir;
  245. // controls how water is reflected and refracted
  246. WaterFloatControl mFresnelScale;
  247. WaterFloatControl mFresnelOffset;
  248. WaterFloatControl mScaleAbove;
  249. WaterFloatControl mScaleBelow;
  250. WaterFloatControl mBlurMultiplier;
  251. F32 mDensitySliderValue;
  252. private:
  253. friend class LLSingleton<LLWaterParamManager>;
  254. /*virtual*/ void initSingleton();
  255. LLWaterParamManager();
  256. ~LLWaterParamManager();
  257. void loadAllPresets();
  258. void loadPresetsFromDir(const std::string& dir);
  259. bool loadPreset(const std::string& path);
  260. static std::string getSysDir();
  261. static std::string getUserDir();
  262. LLVector4 mWaterPlane;
  263. F32 mWaterFogKS;
  264. // list of all the parameters, listed by name
  265. preset_map_t mParamList;
  266. preset_list_signal_t mPresetListChangeSignal;
  267. };
  268. inline void LLWaterParamManager::setDensitySliderValue(F32 val)
  269. {
  270. val /= 10.0f;
  271. val = 1.0f - val;
  272. val *= val * val;
  273. // val *= val;
  274. mDensitySliderValue = val;
  275. }
  276. inline LLUUID LLWaterParamManager::getNormalMapID()
  277. {
  278. return mCurParams.mParamValues["normalMap"].asUUID();
  279. }
  280. inline bool LLWaterParamManager::setNormalMapID(const LLUUID& id)
  281. {
  282. mCurParams.mParamValues["normalMap"] = id;
  283. return true;
  284. }
  285. inline LLVector2 LLWaterParamManager::getWave1Dir(void)
  286. {
  287. bool err;
  288. return mCurParams.getVector2("wave1Dir", err);
  289. }
  290. inline LLVector2 LLWaterParamManager::getWave2Dir(void)
  291. {
  292. bool err;
  293. return mCurParams.getVector2("wave2Dir", err);
  294. }
  295. inline F32 LLWaterParamManager::getScaleAbove(void)
  296. {
  297. bool err;
  298. return mCurParams.getFloat("scaleAbove", err);
  299. }
  300. inline F32 LLWaterParamManager::getScaleBelow(void)
  301. {
  302. bool err;
  303. return mCurParams.getFloat("scaleBelow", err);
  304. }
  305. inline LLVector3 LLWaterParamManager::getNormalScale(void)
  306. {
  307. bool err;
  308. return mCurParams.getVector3("normScale", err);
  309. }
  310. inline F32 LLWaterParamManager::getFresnelScale(void)
  311. {
  312. bool err;
  313. return mCurParams.getFloat("fresnelScale", err);
  314. }
  315. inline F32 LLWaterParamManager::getFresnelOffset(void)
  316. {
  317. bool err;
  318. return mCurParams.getFloat("fresnelOffset", err);
  319. }
  320. inline F32 LLWaterParamManager::getBlurMultiplier(void)
  321. {
  322. bool err;
  323. return mCurParams.getFloat("blurMultiplier", err);
  324. }
  325. inline LLColor4 LLWaterParamManager::getFogColor(void)
  326. {
  327. bool err;
  328. return LLColor4(mCurParams.getVector4("waterFogColor", err));
  329. }
  330. #endif