aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwaterparammanager.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llwaterparammanager.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llwaterparammanager.h401
1 files changed, 401 insertions, 0 deletions
diff --git a/linden/indra/newview/llwaterparammanager.h b/linden/indra/newview/llwaterparammanager.h
new file mode 100644
index 0000000..ad40c12
--- /dev/null
+++ b/linden/indra/newview/llwaterparammanager.h
@@ -0,0 +1,401 @@
1/**
2 * @file llwaterparammanager.h
3 * @brief Implementation for the LLWaterParamManager class.
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#ifndef LL_WATER_PARAMMANAGER_H
33#define LL_WATER_PARAMMANAGER_H
34
35#include <vector>
36#include <map>
37#include "llwaterparamset.h"
38#include "llviewercamera.h"
39#include "v4color.h"
40
41const F32 WATER_FOG_LIGHT_CLAMP = 0.3f;
42
43// color control
44struct WaterColorControl {
45
46 F32 mR, mG, mB, mA, mI; /// the values
47 char const * mName; /// name to use to dereference params
48 std::string mSliderName; /// name of the slider in menu
49 bool mHasSliderName; /// only set slider name for true color types
50
51 inline WaterColorControl(F32 red, F32 green, F32 blue, F32 alpha,
52 F32 intensity, char const * n, char const * sliderName = "")
53 : mR(red), mG(green), mB(blue), mA(alpha), mI(intensity), mName(n), mSliderName(sliderName)
54 {
55 // if there's a slider name, say we have one
56 mHasSliderName = false;
57 if (mSliderName != "") {
58 mHasSliderName = true;
59 }
60 }
61
62 inline WaterColorControl & operator = (LLColor4 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
71 inline operator LLColor4 (void) const
72 {
73 return LLColor4(mR, mG, mB, mA);
74 }
75
76 inline WaterColorControl & operator = (LLVector4 const & val)
77 {
78 mR = val.mV[0];
79 mG = val.mV[1];
80 mB = val.mV[2];
81 mA = val.mV[3];
82 return *this;
83 }
84
85 inline operator LLVector4 (void) const
86 {
87 return LLVector4(mR, mG, mB, mA);
88 }
89
90 inline operator LLVector3 (void) const
91 {
92 return LLVector3(mR, mG, mB);
93 }
94
95 inline void update(LLWaterParamSet & params) const
96 {
97 params.set(mName, mR, mG, mB, mA);
98 }
99};
100
101struct WaterVector3Control
102{
103 F32 mX;
104 F32 mY;
105 F32 mZ;
106
107 char const * mName;
108
109 // basic constructor
110 inline WaterVector3Control(F32 valX, F32 valY, F32 valZ, char const * n)
111 : mX(valX), mY(valY), mZ(valZ), mName(n)
112 {
113 }
114
115 inline WaterVector3Control & operator = (LLVector3 const & val)
116 {
117 mX = val.mV[0];
118 mY = val.mV[1];
119 mZ = val.mV[2];
120
121 return *this;
122 }
123
124 inline void update(LLWaterParamSet & params) const
125 {
126 params.set(mName, mX, mY, mZ);
127 }
128
129};
130
131struct WaterVector2Control
132{
133 F32 mX;
134 F32 mY;
135
136 char const * mName;
137
138 // basic constructor
139 inline WaterVector2Control(F32 valX, F32 valY, char const * n)
140 : mX(valX), mY(valY), mName(n)
141 {
142 }
143
144 inline WaterVector2Control & operator = (LLVector2 const & val)
145 {
146 mX = val.mV[0];
147 mY = val.mV[1];
148
149 return *this;
150 }
151
152 inline void update(LLWaterParamSet & params) const
153 {
154 params.set(mName, mX, mY);
155 }
156};
157
158// float slider control
159struct WaterFloatControl
160{
161 F32 mX;
162 char const * mName;
163 F32 mMult;
164
165 inline WaterFloatControl(F32 val, char const * n, F32 m=1.0f)
166 : mX(val), mName(n), mMult(m)
167 {
168 }
169
170 inline WaterFloatControl & operator = (LLVector4 const & val)
171 {
172 mX = val.mV[0];
173
174 return *this;
175 }
176
177 inline operator F32 (void) const
178 {
179 return mX;
180 }
181
182 inline void update(LLWaterParamSet & params) const
183 {
184 params.set(mName, mX);
185 }
186};
187
188// float slider control
189struct WaterExpFloatControl
190{
191 F32 mExp;
192 char const * mName;
193 F32 mBase;
194
195 inline WaterExpFloatControl(F32 val, char const * n, F32 b)
196 : mExp(val), mName(n), mBase(b)
197 {
198 }
199
200 inline WaterExpFloatControl & operator = (F32 val)
201 {
202 mExp = log(val) / log(mBase);
203
204 return *this;
205 }
206
207 inline operator F32 (void) const
208 {
209 return pow(mBase, mExp);
210 }
211
212 inline void update(LLWaterParamSet & params) const
213 {
214 params.set(mName, pow(mBase, mExp));
215 }
216};
217
218
219/// WindLight parameter manager class - what controls all the wind light shaders
220class LLWaterParamManager
221{
222public:
223
224 LLWaterParamManager();
225 ~LLWaterParamManager();
226
227 /// load a preset file
228 void loadAllPresets(const LLString & fileName);
229
230 /// load an individual preset into the sky
231 void loadPreset(const LLString & name);
232
233 /// save the parameter presets to file
234 void savePreset(const LLString & name);
235
236 /// send the parameters to the shaders
237 void propagateParameters(void);
238
239 /// update information for the shader
240 void update(LLViewerCamera * cam);
241
242 /// Update shader uniforms that have changed.
243 void updateShaderUniforms(LLGLSLShader * shader);
244
245 /// Perform global initialization for this class.
246 static void initClass(void);
247
248 // Cleanup of global data that's only inited once per class.
249 static void cleanupClass();
250
251 /// add a param to the list
252 bool addParamSet(const std::string& name, LLWaterParamSet& param);
253
254 /// add a param to the list
255 BOOL addParamSet(const std::string& name, LLSD const & param);
256
257 /// get a param from the list
258 bool getParamSet(const std::string& name, LLWaterParamSet& param);
259
260 /// set the param in the list with a new param
261 bool setParamSet(const std::string& name, LLWaterParamSet& param);
262
263 /// set the param in the list with a new param
264 bool setParamSet(const std::string& name, LLSD const & param);
265
266 /// gets rid of a parameter and any references to it
267 /// returns true if successful
268 bool removeParamSet(const std::string& name, bool delete_from_disk);
269
270 /// set the normap map we want for water
271 bool setNormalMapID(const LLUUID& img);
272
273 void setDensitySliderValue(F32 val);
274
275 /// getters for all the different things water param manager maintains
276 LLUUID getNormalMapID(void);
277 LLVector2 getWave1Dir(void);
278 LLVector2 getWave2Dir(void);
279 F32 getScaleAbove(void);
280 F32 getScaleBelow(void);
281 LLVector3 getNormalScale(void);
282 F32 getFresnelScale(void);
283 F32 getFresnelOffset(void);
284 F32 getBlurMultiplier(void);
285 F32 getFogDensity(void);
286 LLColor4 getFogColor(void);
287
288 // singleton pattern implementation
289 static LLWaterParamManager * instance();
290
291public:
292
293 LLWaterParamSet mCurParams;
294
295 /// Atmospherics
296 WaterColorControl mFogColor;
297 WaterExpFloatControl mFogDensity;
298 WaterFloatControl mUnderWaterFogMod;
299
300 /// wavelet scales and directions
301 WaterVector3Control mNormalScale;
302 WaterVector2Control mWave1Dir;
303 WaterVector2Control mWave2Dir;
304
305 // controls how water is reflected and refracted
306 WaterFloatControl mFresnelScale;
307 WaterFloatControl mFresnelOffset;
308 WaterFloatControl mScaleAbove;
309 WaterFloatControl mScaleBelow;
310 WaterFloatControl mBlurMultiplier;
311
312 // list of all the parameters, listed by name
313 std::map<std::string, LLWaterParamSet> mParamList;
314
315 F32 mDensitySliderValue;
316
317private:
318 // our parameter manager singleton instance
319 static LLWaterParamManager * sInstance;
320
321private:
322
323 LLVector4 mWaterPlane;
324 F32 mWaterFogKS;
325};
326
327inline void LLWaterParamManager::setDensitySliderValue(F32 val)
328{
329 val /= 10;
330 val = 1.0f - val;
331 val *= val * val;
332// val *= val;
333 mDensitySliderValue = val;
334}
335
336inline LLUUID LLWaterParamManager::getNormalMapID()
337{
338 return mCurParams.mParamValues["normalMap"].asUUID();
339}
340
341inline bool LLWaterParamManager::setNormalMapID(const LLUUID& id)
342{
343 mCurParams.mParamValues["normalMap"] = id;
344 return true;
345}
346
347inline LLVector2 LLWaterParamManager::getWave1Dir(void)
348{
349 bool err;
350 return mCurParams.getVector2("wave1Dir", err);
351}
352
353inline LLVector2 LLWaterParamManager::getWave2Dir(void)
354{
355 bool err;
356 return mCurParams.getVector2("wave2Dir", err);
357}
358
359inline F32 LLWaterParamManager::getScaleAbove(void)
360{
361 bool err;
362 return mCurParams.getFloat("scaleAbove", err);
363}
364
365inline F32 LLWaterParamManager::getScaleBelow(void)
366{
367 bool err;
368 return mCurParams.getFloat("scaleBelow", err);
369}
370
371inline LLVector3 LLWaterParamManager::getNormalScale(void)
372{
373 bool err;
374 return mCurParams.getVector3("normScale", err);
375}
376
377inline F32 LLWaterParamManager::getFresnelScale(void)
378{
379 bool err;
380 return mCurParams.getFloat("fresnelScale", err);
381}
382
383inline F32 LLWaterParamManager::getFresnelOffset(void)
384{
385 bool err;
386 return mCurParams.getFloat("fresnelOffset", err);
387}
388
389inline F32 LLWaterParamManager::getBlurMultiplier(void)
390{
391 bool err;
392 return mCurParams.getFloat("blurMultiplier", err);
393}
394
395inline LLColor4 LLWaterParamManager::getFogColor(void)
396{
397 bool err;
398 return LLColor4(mCurParams.getVector4("waterFogColor", err));
399}
400
401#endif