1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
/**
* @file llsettingswater.h
* @author optional
* @brief A base class for asset based settings groups.
*
* $LicenseInfo:2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2017, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llviewercontrol.h"
#include "llsettingswater.h"
#include <algorithm>
#include <boost/make_shared.hpp>
#include "lltrace.h"
#include "llfasttimer.h"
#include "v3colorutil.h"
#include "llglslshader.h"
#include "llviewershadermgr.h"
#include "llenvironment.h"
#include "llagent.h"
#include "pipeline.h"
//=========================================================================
namespace
{
LLTrace::BlockTimerStatHandle FTM_BLEND_WATERVALUES("Blending Water Environment");
LLTrace::BlockTimerStatHandle FTM_UPDATE_WATERVALUES("Update Water Environment");
}
//=========================================================================
const std::string LLSettingsWater::SETTING_BLUR_MULTIPILER("blur_multiplier");
const std::string LLSettingsWater::SETTING_FOG_COLOR("water_fog_color");
const std::string LLSettingsWater::SETTING_FOG_DENSITY("water_fog_density");
const std::string LLSettingsWater::SETTING_FOG_MOD("underwater_fog_mod");
const std::string LLSettingsWater::SETTING_FRESNEL_OFFSET("fresnel_offset");
const std::string LLSettingsWater::SETTING_FRESNEL_SCALE("fresnel_scale");
const std::string LLSettingsWater::SETTING_NORMAL_MAP("normal_map");
const std::string LLSettingsWater::SETTING_NORMAL_SCALE("normal_scale");
const std::string LLSettingsWater::SETTING_SCALE_ABOVE("scale_above");
const std::string LLSettingsWater::SETTING_SCALE_BELOW("scale_below");
const std::string LLSettingsWater::SETTING_WAVE1_DIR("wave1_direction");
const std::string LLSettingsWater::SETTING_WAVE2_DIR("wave2_direction");
const std::string LLSettingsWater::SETTING_LEGACY_BLUR_MULTIPILER("blurMultiplier");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_COLOR("waterFogColor");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_DENSITY("waterFogDensity");
const std::string LLSettingsWater::SETTING_LEGACY_FOG_MOD("underWaterFogMod");
const std::string LLSettingsWater::SETTING_LEGACY_FRESNEL_OFFSET("fresnelOffset");
const std::string LLSettingsWater::SETTING_LEGACY_FRESNEL_SCALE("fresnelScale");
const std::string LLSettingsWater::SETTING_LEGACY_NORMAL_MAP("normalMap");
const std::string LLSettingsWater::SETTING_LEGACY_NORMAL_SCALE("normScale");
const std::string LLSettingsWater::SETTING_LEGACY_SCALE_ABOVE("scaleAbove");
const std::string LLSettingsWater::SETTING_LEGACY_SCALE_BELOW("scaleBelow");
const std::string LLSettingsWater::SETTING_LEGACY_WAVE1_DIR("wave1Dir");
const std::string LLSettingsWater::SETTING_LEGACY_WAVE2_DIR("wave2Dir");
const F32 LLSettingsWater::WATER_FOG_LIGHT_CLAMP(0.3f);
const LLUUID LLSettingsWater::DEFAULT_WATER_NORMAL_ID(DEFAULT_WATER_NORMAL);
//=========================================================================
LLSettingsWater::LLSettingsWater(const LLSD &data) :
LLSettingsBase(data)
{
}
LLSettingsWater::LLSettingsWater() :
LLSettingsBase()
{
}
//=========================================================================
LLSD LLSettingsWater::defaults()
{
LLSD dfltsetting;
// Magic constants copied form defaults.xml
dfltsetting[SETTING_BLUR_MULTIPILER] = LLSD::Real(0.04000f);
dfltsetting[SETTING_FOG_COLOR] = LLColor3(0.0156f, 0.1490f, 0.2509f).getValue();
dfltsetting[SETTING_FOG_DENSITY] = LLSD::Real(2.0f);
dfltsetting[SETTING_FOG_MOD] = LLSD::Real(0.25f);
dfltsetting[SETTING_FRESNEL_OFFSET] = LLSD::Real(0.5f);
dfltsetting[SETTING_FRESNEL_SCALE] = LLSD::Real(0.3999);
dfltsetting[SETTING_NORMAL_MAP] = LLSD::UUID(DEFAULT_WATER_NORMAL_ID);
dfltsetting[SETTING_NORMAL_SCALE] = LLVector3(2.0f, 2.0f, 2.0f).getValue();
dfltsetting[SETTING_SCALE_ABOVE] = LLSD::Real(0.0299f);
dfltsetting[SETTING_SCALE_BELOW] = LLSD::Real(0.2000f);
dfltsetting[SETTING_WAVE1_DIR] = LLVector2(1.04999f, -0.42000f).getValue();
dfltsetting[SETTING_WAVE2_DIR] = LLVector2(1.10999f, -1.16000f).getValue();
return dfltsetting;
}
LLSettingsWater::ptr_t LLSettingsWater::buildFromLegacyPreset(const std::string &name, const LLSD &oldsettings)
{
LLSD newsettings(defaults());
newsettings[SETTING_NAME] = name;
if (oldsettings.has(SETTING_LEGACY_BLUR_MULTIPILER))
{
newsettings[SETTING_BLUR_MULTIPILER] = LLSD::Real(oldsettings[SETTING_LEGACY_BLUR_MULTIPILER].asReal());
}
if (oldsettings.has(SETTING_LEGACY_FOG_COLOR))
{
newsettings[SETTING_FOG_COLOR] = LLColor3(oldsettings[SETTING_LEGACY_FOG_COLOR]).getValue();
}
if (oldsettings.has(SETTING_LEGACY_FOG_DENSITY))
{
newsettings[SETTING_FOG_DENSITY] = LLSD::Real(oldsettings[SETTING_LEGACY_FOG_DENSITY]);
}
if (oldsettings.has(SETTING_LEGACY_FOG_MOD))
{
newsettings[SETTING_FOG_MOD] = LLSD::Real(oldsettings[SETTING_LEGACY_FOG_MOD].asReal());
}
if (oldsettings.has(SETTING_LEGACY_FRESNEL_OFFSET))
{
newsettings[SETTING_FRESNEL_OFFSET] = LLSD::Real(oldsettings[SETTING_LEGACY_FRESNEL_OFFSET].asReal());
}
if (oldsettings.has(SETTING_LEGACY_FRESNEL_SCALE))
{
newsettings[SETTING_FRESNEL_SCALE] = LLSD::Real(oldsettings[SETTING_LEGACY_FRESNEL_SCALE].asReal());
}
if (oldsettings.has(SETTING_LEGACY_NORMAL_MAP))
{
newsettings[SETTING_NORMAL_MAP] = LLSD::UUID(oldsettings[SETTING_LEGACY_NORMAL_MAP].asUUID());
}
if (oldsettings.has(SETTING_LEGACY_NORMAL_SCALE))
{
newsettings[SETTING_NORMAL_SCALE] = LLVector3(oldsettings[SETTING_LEGACY_NORMAL_SCALE]).getValue();
}
if (oldsettings.has(SETTING_LEGACY_SCALE_ABOVE))
{
newsettings[SETTING_SCALE_ABOVE] = LLSD::Real(oldsettings[SETTING_LEGACY_SCALE_ABOVE].asReal());
}
if (oldsettings.has(SETTING_LEGACY_SCALE_BELOW))
{
newsettings[SETTING_SCALE_BELOW] = LLSD::Real(oldsettings[SETTING_LEGACY_SCALE_BELOW].asReal());
}
if (oldsettings.has(SETTING_LEGACY_WAVE1_DIR))
{
newsettings[SETTING_WAVE1_DIR] = LLVector2(oldsettings[SETTING_LEGACY_WAVE1_DIR]).getValue();
}
if (oldsettings.has(SETTING_LEGACY_WAVE2_DIR))
{
newsettings[SETTING_WAVE2_DIR] = LLVector2(oldsettings[SETTING_LEGACY_WAVE2_DIR]).getValue();
}
LLSettingsWater::ptr_t waterp = boost::make_shared<LLSettingsWater>(newsettings);
return waterp;
}
LLSettingsWater::ptr_t LLSettingsWater::buildDefaultWater()
{
LLSD settings = LLSettingsWater::defaults();
LLSettingsWater::ptr_t skyp = boost::make_shared<LLSettingsWater>(settings);
return skyp;
}
LLSettingsWater::ptr_t LLSettingsWater::buildClone()
{
LLSD settings = cloneSettings();
LLSettingsWater::ptr_t skyp = boost::make_shared<LLSettingsWater>(settings);
return skyp;
}
void LLSettingsWater::blend(const LLSettingsBase::ptr_t &end, F32 blendf)
{
LLSettingsWater::ptr_t other = boost::static_pointer_cast<LLSettingsWater>(end);
LLSD blenddata = interpolateSDMap(mSettings, other->mSettings, blendf);
replaceSettings(blenddata);
}
//=========================================================================
LLSettingsWater::parammapping_t LLSettingsWater::getParameterMap() const
{
static parammapping_t param_map;
if (param_map.empty())
{
param_map[SETTING_FOG_COLOR] = LLShaderMgr::WATER_FOGCOLOR;
param_map[SETTING_FOG_DENSITY] = LLShaderMgr::WATER_FOGDENSITY;
}
return param_map;
}
void LLSettingsWater::applySpecial(void *ptarget)
{
LLGLSLShader *shader = (LLGLSLShader *)ptarget;
shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, getWaterPlane().mV);
shader->uniform1f(LLShaderMgr::WATER_FOGKS, getWaterFogKS());
shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, LLEnvironment::instance().getRotatedLight().mV);
shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
shader->uniform1f(LLViewerShaderMgr::DISTANCE_MULTIPLIER, 0);
}
//=========================================================================
void LLSettingsWater::updateSettings()
{
// LL_RECORD_BLOCK_TIME(FTM_UPDATE_WATERVALUES);
// LL_INFOS("WINDLIGHT", "WATER", "EEP") << "Water Parameters are dirty. Reticulating Splines..." << LL_ENDL;
// base class clears dirty flag so as to not trigger recursive update
LLSettingsBase::updateSettings();
// only do this if we're dealing with shaders
if (gPipeline.canUseVertexShaders())
{
//transform water plane to eye space
glh::vec3f norm(0.f, 0.f, 1.f);
glh::vec3f p(0.f, 0.f, LLEnvironment::instance().getWaterHeight() + 0.1f);
F32 modelView[16];
for (U32 i = 0; i < 16; i++)
{
modelView[i] = (F32)gGLModelView[i];
}
glh::matrix4f mat(modelView);
glh::matrix4f invtrans = mat.inverse().transpose();
glh::vec3f enorm;
glh::vec3f ep;
invtrans.mult_matrix_vec(norm, enorm);
enorm.normalize();
mat.mult_matrix_vec(p, ep);
mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
LLVector4 light_direction = LLEnvironment::instance().getLightDirection();
mWaterFogKS = 1.f / llmax(light_direction.mV[2], WATER_FOG_LIGHT_CLAMP);
}
}
|