llwlwaterparammgr.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /**
  2. * @file llwlwaterparammgr.h
  3. * @brief Implementation for the LLWLWaterParamMgr class.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_WLWATERPARAMMGR_H
  33. #define LL_WLWATERPARAMMGR_H
  34. #include <map>
  35. #include "llcolor4.h"
  36. #include "llstringtable.h"
  37. #include "llvector4.h"
  38. class LLViewerCamera;
  39. // A class representing a set of parameter values for the water
  40. class LLWaterParamSet
  41. {
  42. friend class LLWLWaterParamMgr;
  43. public:
  44. LLWaterParamSet();
  45. // Sets the total LLSD
  46. void setAll(const LLSD& val);
  47. // Gets the total LLSD
  48. LL_INLINE const LLSD& getAll() const { return mParamValues; }
  49. // Set a float parameter.
  50. // - param param_name The name of the parameter to set.
  51. // - param x The float value to set.
  52. void set(const std::string& param_name, F32 x);
  53. // Set a float2 parameter.
  54. // - param param_name The name of the parameter to set.
  55. // - param x The x component's value to set.
  56. // - param y The y component's value to set.
  57. void set(const std::string& param_name, F32 x, F32 y);
  58. // Set a float3 parameter.
  59. // - param param_name The name of the parameter to set.
  60. // - param x The x component's value to set.
  61. // - param y The y component's value to set.
  62. // - param z The z component's value to set.
  63. void set(const std::string& param_name, F32 x, F32 y, F32 z);
  64. // Set a float4 parameter.
  65. // - param param_name The name of the parameter to set.
  66. // - param x The x component's value to set.
  67. // - param y The y component's value to set.
  68. // - param z The z component's value to set.
  69. // - param w The w component's value to set.
  70. void set(const std::string& param_name, F32 x, F32 y, F32 z, F32 w);
  71. // Set a float4 parameter.
  72. // - param param_name The name of the parameter to set.
  73. // - param val Array of 4 floats to set the parameter to.
  74. void set(const std::string& param_name, const F32* val);
  75. // Set a float4 parameter.
  76. // - param param_name The name of the parameter to set.
  77. // - param val Struct 4 floats to set the parameter to.
  78. void set(const std::string& param_name, const LLVector4& val);
  79. // Set a float4 parameter.
  80. // - param param_name The name of the parameter to set.
  81. // - param val Struct 4 floats to set the parameter to.
  82. void set(const std::string& param_name, const LLColor4& val);
  83. // Get a float4 parameter.
  84. // - param param_name The name of the parameter to set.
  85. // - param error A flag to set if it's not the proper return type
  86. LLVector4 getVector4(const std::string& param_name, bool& error);
  87. // Get a float3 parameter.
  88. // - param param_name The name of the parameter to set.
  89. // - param error A flag to set if it's not the proper return type
  90. LLVector3 getVector3(const std::string& param_name, bool& error);
  91. // Get a float2 parameter.
  92. // - param param_name The name of the parameter to set.
  93. // - param error A flag to set if it's not the proper return type
  94. LLVector2 getVector2(const std::string& param_name, bool& error);
  95. // Get an integer parameter
  96. // - param param_name The name of the parameter to set.
  97. // - param error A flag to set if it's not the proper return type
  98. F32 getFloat(const std::string& param_name, bool& error);
  99. // interpolate two parameter sets
  100. // - param src The parameter set to start with
  101. // - param dest The parameter set to end with
  102. // - param weight The amount to interpolate
  103. void mix(LLWaterParamSet& src, LLWaterParamSet& dest, F32 weight);
  104. private:
  105. void updateHashedNames();
  106. public:
  107. std::string mName;
  108. private:
  109. LLSD mParamValues;
  110. typedef std::vector<LLStaticHashedString> hash_vector_t;
  111. hash_vector_t mParamHashedNames;
  112. };
  113. // Color control structure
  114. struct WaterColorControl
  115. {
  116. F32 mR, mG, mB, mA, mI; // the values
  117. std::string mName; // name to use to dereference params
  118. std::string mSliderName; // name of the slider in menu
  119. bool mHasSliderName; // only set slider name for true color types
  120. LL_INLINE WaterColorControl(F32 red, F32 green, F32 blue, F32 alpha,
  121. F32 intensity, const std::string& n,
  122. const std::string& sliderName = LLStringUtil::null)
  123. : mR(red),
  124. mG(green),
  125. mB(blue),
  126. mA(alpha),
  127. mI(intensity),
  128. mName(n),
  129. mSliderName(sliderName)
  130. {
  131. // if there's a slider name, say we have one
  132. mHasSliderName = false;
  133. if (mSliderName != "")
  134. {
  135. mHasSliderName = true;
  136. }
  137. }
  138. LL_INLINE WaterColorControl& operator=(const LLColor4& val)
  139. {
  140. mR = val.mV[0];
  141. mG = val.mV[1];
  142. mB = val.mV[2];
  143. mA = val.mV[3];
  144. return *this;
  145. }
  146. LL_INLINE operator LLColor4(void) const
  147. {
  148. return LLColor4(mR, mG, mB, mA);
  149. }
  150. LL_INLINE WaterColorControl& operator=(const LLVector4& val)
  151. {
  152. mR = val.mV[0];
  153. mG = val.mV[1];
  154. mB = val.mV[2];
  155. mA = val.mV[3];
  156. return *this;
  157. }
  158. LL_INLINE operator LLVector4(void) const
  159. {
  160. return LLVector4(mR, mG, mB, mA);
  161. }
  162. LL_INLINE operator LLVector3(void) const
  163. {
  164. return LLVector3(mR, mG, mB);
  165. }
  166. LL_INLINE void update(LLWaterParamSet& params) const
  167. {
  168. params.set(mName, mR, mG, mB, mA);
  169. }
  170. };
  171. struct WaterVector3Control
  172. {
  173. F32 mX;
  174. F32 mY;
  175. F32 mZ;
  176. std::string mName;
  177. // Basic constructor
  178. LL_INLINE WaterVector3Control(F32 valX, F32 valY, F32 valZ,
  179. const std::string& n)
  180. : mX(valX),
  181. mY(valY),
  182. mZ(valZ),
  183. mName(n)
  184. {
  185. }
  186. LL_INLINE WaterVector3Control& operator=(const LLVector3& val)
  187. {
  188. mX = val.mV[0];
  189. mY = val.mV[1];
  190. mZ = val.mV[2];
  191. return *this;
  192. }
  193. LL_INLINE void update(LLWaterParamSet& params) const
  194. {
  195. params.set(mName, mX, mY, mZ);
  196. }
  197. };
  198. struct WaterVector2Control
  199. {
  200. F32 mX;
  201. F32 mY;
  202. std::string mName;
  203. // basic constructor
  204. LL_INLINE WaterVector2Control(F32 valX, F32 valY, const std::string& n)
  205. : mX(valX),
  206. mY(valY),
  207. mName(n)
  208. {
  209. }
  210. LL_INLINE WaterVector2Control& operator=(const LLVector2& val)
  211. {
  212. mX = val.mV[0];
  213. mY = val.mV[1];
  214. return *this;
  215. }
  216. LL_INLINE void update(LLWaterParamSet& params) const
  217. {
  218. params.set(mName, mX, mY);
  219. }
  220. };
  221. // float slider control
  222. struct WaterFloatControl
  223. {
  224. F32 mX;
  225. F32 mMult;
  226. std::string mName;
  227. LL_INLINE WaterFloatControl(F32 val, const std::string& n, F32 m = 1.f)
  228. : mX(val),
  229. mName(n),
  230. mMult(m)
  231. {
  232. }
  233. LL_INLINE WaterFloatControl& operator = (const LLVector4& val)
  234. {
  235. mX = val.mV[0];
  236. return *this;
  237. }
  238. LL_INLINE operator F32(void) const
  239. {
  240. return mX;
  241. }
  242. LL_INLINE void update(LLWaterParamSet& params) const
  243. {
  244. params.set(mName, mX);
  245. }
  246. };
  247. // float slider control
  248. struct WaterExpFloatControl
  249. {
  250. F32 mExp;
  251. F32 mBase;
  252. std::string mName;
  253. LL_INLINE WaterExpFloatControl(F32 val, const std::string& n, F32 b)
  254. : mExp(val),
  255. mName(n),
  256. mBase(b)
  257. {
  258. }
  259. LL_INLINE WaterExpFloatControl& operator=(F32 val)
  260. {
  261. mExp = logf(val) / logf(mBase);
  262. return *this;
  263. }
  264. LL_INLINE operator F32(void) const
  265. {
  266. return powf(mBase, mExp);
  267. }
  268. LL_INLINE void update(LLWaterParamSet& params) const
  269. {
  270. params.set(mName, powf(mBase, mExp));
  271. }
  272. };
  273. // Parameter manager class for the Windlight water
  274. class LLWLWaterParamMgr
  275. {
  276. protected:
  277. LOG_CLASS(LLWLWaterParamMgr);
  278. private:
  279. public:
  280. LLWLWaterParamMgr();
  281. // This method is called in llappviewer.cpp only
  282. void initClass();
  283. // Loads a preset file
  284. void loadAllPresets(const std::string& filename);
  285. // Loads an individual preset for the water. Returns true if successful.
  286. bool loadPreset(const std::string& name, bool propagate = true);
  287. // Saves the parameter presets to file
  288. void savePreset(const std::string& name);
  289. // Propagates the parameters to the environment
  290. void propagateParameters();
  291. // Cleans up global data that is only inited once per class.
  292. static void cleanupClass();
  293. // Adds a param to the list
  294. bool addParamSet(const std::string& name, LLWaterParamSet& param);
  295. // Adds a param to the list
  296. bool addParamSet(const std::string& name, const LLSD& param);
  297. // Geta a param from the list
  298. bool getParamSet(const std::string& name, LLWaterParamSet& param);
  299. // Sets the param in the list with a new param
  300. LL_INLINE bool setParamSet(const std::string& name, LLWaterParamSet& param)
  301. {
  302. mParamList[name] = param;
  303. return true;
  304. }
  305. // Sets the param in the list with a new param
  306. bool setParamSet(const std::string& name, const LLSD& param);
  307. // Gets rid of a parameter and any references to it
  308. // returns true if successful
  309. bool removeParamSet(const std::string& name, bool delete_from_disk);
  310. // Sets the normap map we want for water
  311. LL_INLINE bool setNormalMapID(const LLUUID& id)
  312. {
  313. mCurParams.mParamValues["normalMap"] = id;
  314. return true;
  315. }
  316. LL_INLINE void setDensitySliderValue(F32 val)
  317. {
  318. val = 1.f - 0.1f * val;
  319. mDensitySliderValue = val * val * val;
  320. }
  321. LL_INLINE LLUUID getNormalMapID()
  322. {
  323. return mCurParams.mParamValues["normalMap"].asUUID();
  324. }
  325. LL_INLINE LLVector2 getWave1Dir()
  326. {
  327. bool err;
  328. return mCurParams.getVector2("wave1Dir", err);
  329. }
  330. LL_INLINE LLVector2 getWave2Dir()
  331. {
  332. bool err;
  333. return mCurParams.getVector2("wave2Dir", err);
  334. }
  335. LL_INLINE F32 getScaleAbove()
  336. {
  337. bool err;
  338. return mCurParams.getFloat("scaleAbove", err);
  339. }
  340. LL_INLINE F32 getScaleBelow()
  341. {
  342. bool err;
  343. return mCurParams.getFloat("scaleBelow", err);
  344. }
  345. LL_INLINE LLVector3 getNormalScale()
  346. {
  347. bool err;
  348. return mCurParams.getVector3("normScale", err);
  349. }
  350. LL_INLINE F32 getFresnelScale()
  351. {
  352. bool err;
  353. return mCurParams.getFloat("fresnelScale", err);
  354. }
  355. LL_INLINE F32 getFresnelOffset()
  356. {
  357. bool err;
  358. return mCurParams.getFloat("fresnelOffset", err);
  359. }
  360. LL_INLINE F32 getBlurMultiplier()
  361. {
  362. bool err;
  363. return mCurParams.getFloat("blurMultiplier", err);
  364. }
  365. LL_INLINE LLColor4 getFogColor()
  366. {
  367. bool err;
  368. return LLColor4(mCurParams.getVector4("waterFogColor", err));
  369. }
  370. F32 getFogDensity();
  371. static std::vector<std::string> getLoadedPresetsList();
  372. public:
  373. LLWaterParamSet mCurParams;
  374. // Atmospherics
  375. WaterColorControl mFogColor;
  376. WaterExpFloatControl mFogDensity;
  377. WaterFloatControl mUnderWaterFogMod;
  378. // Wavelet scales and directions
  379. WaterVector3Control mNormalScale;
  380. WaterVector2Control mWave1Dir;
  381. WaterVector2Control mWave2Dir;
  382. // Control how water is reflected and refracted
  383. WaterFloatControl mFresnelScale;
  384. WaterFloatControl mFresnelOffset;
  385. WaterFloatControl mScaleAbove;
  386. WaterFloatControl mScaleBelow;
  387. WaterFloatControl mBlurMultiplier;
  388. // List of all the parameters, listed by name
  389. typedef std::map<std::string, LLWaterParamSet> paramset_map_t;
  390. paramset_map_t mParamList;
  391. F32 mDensitySliderValue;
  392. private:
  393. LLVector4 mWaterPlane;
  394. F32 mWaterFogKS;
  395. };
  396. extern LLWLWaterParamMgr gWLWaterParamMgr;
  397. #endif