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
274
275
276
277
278
279
280
281
282
|
/**
* @file lllegacyatmospherics.h
* @brief LLVOSky class header file
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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$
*/
#ifndef LL_LLLEGACYATMOSPHERICS_H
#define LL_LLLEGACYATMOSPHERICS_H
#include "stdtypes.h"
#include "v3color.h"
#include "v4coloru.h"
#include "llviewertexture.h"
#include "llviewerobject.h"
#include "llframetimer.h"
#include "v3colorutil.h"
#include "llsettingssky.h"
//////////////////////////////////
//
// Lots of constants
//
// Will clean these up at some point...
//
const F32 HORIZON_DIST = 1024.0f;
const F32 ATM_EXP_FALLOFF = 0.000126f;
const F32 ATM_SEA_LEVEL_NDENS = 2.55e25f;
const F32 ATM_HEIGHT = 100000.f;
// constants used in calculation of scattering coeff of clear air
const F32 sigma = 0.035f;
const F32 fsigma = (6.f + 3.f * sigma) / (6.f-7.f*sigma);
const F64 Ndens = 2.55e25;
const F64 Ndens2 = Ndens*Ndens;
class LLFace;
class LLHaze;
LL_FORCE_INLINE LLColor3 refr_ind_calc(const LLColor3 &wave_length)
{
LLColor3 refr_ind;
for (S32 i = 0; i < 3; ++i)
{
const F32 wl2 = wave_length.mV[i] * wave_length.mV[i] * 1e-6f;
refr_ind.mV[i] = 6.43e3f + ( 2.95e6f / ( 146.0f - 1.f/wl2 ) ) + ( 2.55e4f / ( 41.0f - 1.f/wl2 ) );
refr_ind.mV[i] *= 1.0e-8f;
refr_ind.mV[i] += 1.f;
}
return refr_ind;
}
class LLHaze
{
public:
LLHaze() : mG(0), mFalloff(1), mAbsCoef(0.f) {mSigSca.setToBlack();}
LLHaze(const F32 g, const LLColor3& sca, const F32 fo = 2.f) :
mG(g), mSigSca(0.25f/F_PI * sca), mFalloff(fo), mAbsCoef(0.f)
{
mAbsCoef = color_intens(mSigSca) / sAirScaIntense;
}
LLHaze(const F32 g, const F32 sca, const F32 fo = 2.f) : mG(g),
mSigSca(0.25f/F_PI * LLColor3(sca, sca, sca)), mFalloff(fo)
{
mAbsCoef = 0.01f * sca / sAirScaAvg;
}
/* Proportion of light that is scattered into 'path' from 'in' over distance dt. */
/* assumes that vectors 'path' and 'in' are normalized. Scattering coef / 2pi */
LL_FORCE_INLINE LLColor3 calcAirSca(const F32 h)
{
return calcFalloff(h) * sAirScaSeaLevel;
}
LL_FORCE_INLINE void calcAirSca(const F32 h, LLColor3 &result)
{
result = sAirScaSeaLevel;
result *= calcFalloff(h);
}
F32 getG() const { return mG; }
void setG(const F32 g)
{
mG = g;
}
const LLColor3& getSigSca() const // sea level
{
return mSigSca;
}
void setSigSca(const LLColor3& s)
{
mSigSca = s;
mAbsCoef = 0.01f * color_intens(mSigSca) / sAirScaIntense;
}
void setSigSca(const F32 s0, const F32 s1, const F32 s2)
{
mSigSca = sAirScaAvg * LLColor3 (s0, s1, s2);
mAbsCoef = 0.01f * (s0 + s1 + s2) / 3;
}
F32 getFalloff() const
{
return mFalloff;
}
void setFalloff(const F32 fo)
{
mFalloff = fo;
}
F32 getAbsCoef() const
{
return mAbsCoef;
}
inline static F32 calcFalloff(const F32 h)
{
return (h <= 0) ? 1.0f : (F32)LL_FAST_EXP(-ATM_EXP_FALLOFF * h);
}
inline LLColor3 calcSigSca(const F32 h) const
{
return calcFalloff(h * mFalloff) * mSigSca;
}
inline void calcSigSca(const F32 h, LLColor3 &result) const
{
result = mSigSca;
result *= calcFalloff(h * mFalloff);
}
LLColor3 calcSigExt(const F32 h) const
{
return calcFalloff(h * mFalloff) * (1 + mAbsCoef) * mSigSca;
}
F32 calcPhase(const F32 cos_theta) const;
private:
static LLColor3 const sAirScaSeaLevel;
static F32 const sAirScaIntense;
static F32 const sAirScaAvg;
protected:
F32 mG;
LLColor3 mSigSca;
F32 mFalloff; // 1 - slow, >1 - faster
F32 mAbsCoef;
};
class LLCubeMap;
class AtmosphericsVars
{
public:
AtmosphericsVars()
: hazeColor(0,0,0)
, hazeColorBelowCloud(0,0,0)
, cloudColorSun(0,0,0)
, cloudColorAmbient(0,0,0)
, cloudDensity(0.0f)
, blue_density()
, blue_horizon()
, haze_density(0.0f)
, haze_horizon(0.0f)
, density_multiplier(0.0f)
, max_y(0.0f)
, gamma(1.0f)
, sun_norm(0.0f, 1.0f, 0.0f, 1.0f)
, sunlight()
, ambient()
, glow()
, cloud_shadow(1.0f)
, dome_radius(1.0f)
, dome_offset(1.0f)
, light_atten()
, light_transmittance()
{
}
friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b);
// returns true if values are within treshold of each other.
friend bool approximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold);
LLColor3 hazeColor;
LLColor3 hazeColorBelowCloud;
LLColor3 cloudColorSun;
LLColor3 cloudColorAmbient;
F32 cloudDensity;
LLColor3 blue_density;
LLColor3 blue_horizon;
F32 haze_density;
F32 haze_horizon;
F32 density_multiplier;
F32 distance_multiplier;
F32 max_y;
F32 gamma;
LLVector4 sun_norm;
LLColor3 sunlight;
LLColor3 ambient;
LLColor3 glow;
F32 cloud_shadow;
F32 dome_radius;
F32 dome_offset;
LLColor3 light_atten;
LLColor3 light_transmittance;
LLColor3 total_density;
};
class LLAtmospherics
{
public:
LLAtmospherics();
~LLAtmospherics();
void init();
void updateFog(const F32 distance, const LLVector3& tosun);
const LLHaze& getHaze() const { return mHaze; }
LLHaze& getHaze() { return mHaze; }
F32 getHazeConcentration() const { return mHazeConcentration; }
void setHaze(const LLHaze& h) { mHaze = h; }
void setFogRatio(const F32 fog_ratio) { mFogRatio = fog_ratio; }
F32 getFogRatio() const { return mFogRatio; }
LLColor4 getFogColor() const { return mFogColor; }
LLColor4 getGLFogColor() const { return mGLFogCol; }
void setCloudDensity(F32 cloud_density) { mCloudDensity = cloud_density; }
void setWind ( const LLVector3& wind ) { mWind = wind.length(); }
LLColor4 calcSkyColorInDir(const LLSettingsSky::ptr_t &psky, AtmosphericsVars& vars, const LLVector3& dir, bool isShiny = false, const bool low_end = false);
protected:
void calcSkyColorWLVert(const LLSettingsSky::ptr_t &psky, LLVector3 & Pn, AtmosphericsVars& vars);
LLHaze mHaze;
F32 mHazeConcentration;
F32 mCloudDensity;
F32 mWind;
bool mInitialized;
LLVector3 mLastLightingDirection;
LLColor3 mLastTotalAmbient;
F32 mAmbientScale;
LLColor3 mNightColorShift;
F32 mInterpVal;
LLColor4 mFogColor;
LLColor4 mGLFogCol;
F32 mFogRatio;
F32 mWorldScale;
};
#endif
|