PageRenderTime 36ms CodeModel.GetById 2ms app.highlight 30ms RepoModel.GetById 1ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llwaterparamset.h"
 30#include "llsd.h"
 31
 32#include "llwaterparammanager.h"
 33#include "lluictrlfactory.h"
 34#include "llsliderctrl.h"
 35#include "llviewertexturelist.h"
 36#include "llviewercontrol.h"
 37#include "lluuid.h"
 38
 39#include <llgl.h>
 40
 41#include <sstream>
 42
 43LLWaterParamSet::LLWaterParamSet(void) :
 44	mName("Unnamed Preset")
 45{
 46	LLSD vec4;
 47	LLSD vec3;
 48	LLSD real(0.0f);
 49
 50	vec4 = LLSD::emptyArray();
 51	vec4.append(22.f/255.f);
 52	vec4.append(43.f/255.f);
 53	vec4.append(54.f/255.f);
 54	vec4.append(0.f/255.f);
 55
 56	vec3 = LLSD::emptyArray();
 57	vec3.append(2);
 58	vec3.append(2);
 59	vec3.append(2);
 60
 61	LLSD wave1, wave2;
 62	wave1 = LLSD::emptyArray();
 63	wave2 = LLSD::emptyArray();
 64	wave1.append(0.5f);
 65	wave1.append(-.17f);
 66	wave2.append(0.58f);
 67	wave2.append(-.67f);
 68
 69	mParamValues.insert("waterFogColor", vec4);
 70	mParamValues.insert("waterFogDensity", 16.0f);
 71	mParamValues.insert("underWaterFogMod", 0.25f);
 72	mParamValues.insert("normScale", vec3);
 73	mParamValues.insert("fresnelScale", 0.5f);
 74	mParamValues.insert("fresnelOffset", 0.4f);
 75	mParamValues.insert("scaleAbove", 0.025f);
 76	mParamValues.insert("scaleBelow", 0.2f);
 77	mParamValues.insert("blurMultiplier", 0.01f);
 78	mParamValues.insert("wave1Dir", wave1);
 79	mParamValues.insert("wave2Dir", wave2);
 80	mParamValues.insert("normalMap", DEFAULT_WATER_NORMAL);
 81
 82}
 83
 84void LLWaterParamSet::set(const std::string& paramName, float x) 
 85{	
 86	// handle case where no array
 87	if(mParamValues[paramName].isReal()) 
 88	{
 89		mParamValues[paramName] = x;
 90	} 
 91	
 92	// handle array
 93	else if(mParamValues[paramName].isArray() &&
 94			mParamValues[paramName][0].isReal())
 95	{
 96		mParamValues[paramName][0] = x;
 97	}
 98}
 99
100void LLWaterParamSet::set(const std::string& paramName, float x, float y) {
101	mParamValues[paramName][0] = x;
102	mParamValues[paramName][1] = y;
103}
104
105void LLWaterParamSet::set(const std::string& paramName, float x, float y, float z)
106{
107	mParamValues[paramName][0] = x;
108	mParamValues[paramName][1] = y;
109	mParamValues[paramName][2] = z;
110}
111
112void LLWaterParamSet::set(const std::string& paramName, float x, float y, float z, float w) 
113{
114	mParamValues[paramName][0] = x;
115	mParamValues[paramName][1] = y;
116	mParamValues[paramName][2] = z;
117	mParamValues[paramName][3] = w;
118}
119
120void LLWaterParamSet::set(const std::string& paramName, const float * val) 
121{
122	mParamValues[paramName][0] = val[0];
123	mParamValues[paramName][1] = val[1];
124	mParamValues[paramName][2] = val[2];
125	mParamValues[paramName][3] = val[3];
126}
127
128void LLWaterParamSet::set(const std::string& paramName, const LLVector4 & val) 
129{
130	mParamValues[paramName][0] = val.mV[0];
131	mParamValues[paramName][1] = val.mV[1];
132	mParamValues[paramName][2] = val.mV[2];
133	mParamValues[paramName][3] = val.mV[3];
134}
135
136void LLWaterParamSet::set(const std::string& paramName, const LLColor4 & val) 
137{
138	mParamValues[paramName][0] = val.mV[0];
139	mParamValues[paramName][1] = val.mV[1];
140	mParamValues[paramName][2] = val.mV[2];
141	mParamValues[paramName][3] = val.mV[3];
142}
143
144LLVector4 LLWaterParamSet::getVector4(const std::string& paramName, bool& error) 
145{
146	
147	// test to see if right type
148	LLSD cur_val = mParamValues.get(paramName);
149	if (!cur_val.isArray() || cur_val.size() != 4) 
150	{
151		error = true;
152		return LLVector4(0,0,0,0);
153	}
154	
155	LLVector4 val;
156	val.mV[0] = (F32) cur_val[0].asReal();
157	val.mV[1] = (F32) cur_val[1].asReal();
158	val.mV[2] = (F32) cur_val[2].asReal();
159	val.mV[3] = (F32) cur_val[3].asReal();
160	
161	error = false;
162	return val;
163}
164
165LLVector3 LLWaterParamSet::getVector3(const std::string& paramName, bool& error) 
166{
167	
168	// test to see if right type
169	LLSD cur_val = mParamValues.get(paramName);
170	if (!cur_val.isArray()|| cur_val.size() != 3) 
171	{
172		error = true;
173		return LLVector3(0,0,0);
174	}
175	
176	LLVector3 val;
177	val.mV[0] = (F32) cur_val[0].asReal();
178	val.mV[1] = (F32) cur_val[1].asReal();
179	val.mV[2] = (F32) cur_val[2].asReal();
180	
181	error = false;
182	return val;
183}
184
185LLVector2 LLWaterParamSet::getVector2(const std::string& paramName, bool& error) 
186{
187	// test to see if right type
188	int ttest;
189	ttest = mParamValues.size();
190	LLSD cur_val = mParamValues.get(paramName);
191	if (!cur_val.isArray() || cur_val.size() != 2) 
192	{
193		error = true;
194		return LLVector2(0,0);
195	}
196	
197	LLVector2 val;
198	val.mV[0] = (F32) cur_val[0].asReal();
199	val.mV[1] = (F32) cur_val[1].asReal();
200	
201	error = false;
202	return val;
203}
204
205F32 LLWaterParamSet::getFloat(const std::string& paramName, bool& error) 
206{
207	
208	// test to see if right type
209	LLSD cur_val = mParamValues.get(paramName);
210	if (cur_val.isArray() && cur_val.size() != 0)
211	{
212		error = false;
213		return (F32) cur_val[0].asReal();	
214	}
215	
216	if(cur_val.isReal())
217	{
218		error = false;
219		return (F32) cur_val.asReal();
220	}
221	
222	error = true;
223	return 0;
224}
225
226// Added for interpolation effect in DEV-33645
227// Based on LLWLParamSet::mix, but written by Jacob without an intimate knowledge of how WindLight works.
228// The function definition existed in the header but was never implemented.  If you think there is something
229// wrong with this, you're probably right.  Ask Jacob, Q, or a member of the original WindLight team.
230void LLWaterParamSet::mix(LLWaterParamSet& src, LLWaterParamSet& dest, F32 weight)
231{
232	// Setup
233	LLSD srcVal, destVal;													// LLSD holders for get/set calls, reusable
234
235	// Iterate through values
236	for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter)
237	{
238		// If param exists in both src and dest, set the holder variables, otherwise skip
239		if(src.mParamValues.has(iter->first) && dest.mParamValues.has(iter->first))
240		{
241			srcVal = src.mParamValues[iter->first];
242			destVal = dest.mParamValues[iter->first];
243		}
244		else
245		{
246			continue;
247		}
248		
249		if(iter->second.isReal())									// If it's a real, interpolate directly
250		{
251			iter->second = srcVal.asReal() + ((destVal.asReal() - srcVal.asReal()) * weight);
252		}		
253		else if(iter->second.isArray() && iter->second[0].isReal()	// If it's an array of reals, loop through the reals and interpolate on those
254				&& iter->second.size() == srcVal.size() && iter->second.size() == destVal.size())
255		{
256			// Actually do interpolation: old value + (difference in values * factor)
257			for(int i=0; i < iter->second.size(); ++i) 
258			{
259				// 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
260				iter->second[i] = srcVal[i].asReal() + ((destVal[i].asReal() - srcVal[i].asReal()) * weight);
261			}
262		}
263		else														// Else, skip
264		{
265			continue;
266		}
267	}
268}