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