summaryrefslogtreecommitdiff
path: root/indra/newview/llvosky.h
blob: e465dcbe273461b0067a23bfa8ee52ccf3ab8594 (plain)
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/** 
 * @file llvosky.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_LLVOSKY_H
#define LL_LLVOSKY_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"
#include "lllegacyatmospherics.h"

const F32 SKY_BOX_MULT			= 16.0f;
const F32 HEAVENLY_BODY_DIST	= HORIZON_DIST - 10.f;
const F32 HEAVENLY_BODY_FACTOR	= 0.1f;
const F32 HEAVENLY_BODY_SCALE	= HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR;

class LLFace;
class LLHaze;

class LLSkyTex
{
	friend class LLVOSky;
private:
	static S32		sResolution;
	static S32		sComponents;
	LLPointer<LLViewerTexture> mTexture[2];
	LLPointer<LLImageRaw> mImageRaw[2];
	LLColor4		*mSkyData;
	LLVector3		*mSkyDirs;			// Cache of sky direction vectors
	static S32		sCurrent;
	static F32		sInterpVal;

public:
	static F32 getInterpVal()					{ return sInterpVal; }
	static void setInterpVal(const F32 v)		{ sInterpVal = v; }
	static BOOL doInterpolate()					{ return sInterpVal > 0.001f; }

	void bindTexture(BOOL curr = TRUE);
	
protected:
	LLSkyTex();
	void init();
	void cleanupGL();
	void restoreGL();

	~LLSkyTex();


	static S32 getResolution();
	static S32 getCurrent();
	static S32 stepCurrent();
	static S32 getNext();
	static S32 getWhich(const BOOL curr);

	void initEmpty(const S32 tex);
	
	void create(F32 brightness);

	void setDir(const LLVector3 &dir, const S32 i, const S32 j)
	{
		S32 offset = i * sResolution + j;
		mSkyDirs[offset] = dir;
	}

	const LLVector3 &getDir(const S32 i, const S32 j) const
	{
		S32 offset = i * sResolution + j;
		return mSkyDirs[offset];
	}

	void setPixel(const LLColor4 &col, const S32 i, const S32 j)
	{
		S32 offset = i * sResolution + j;
		mSkyData[offset] = col;
	}

	void setPixel(const LLColor4U &col, const S32 i, const S32 j)
	{
		S32 offset = (i * sResolution + j) * sComponents;
		U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]);
		*pix = col.asRGBA();
	}

	LLColor4U getPixel(const S32 i, const S32 j)
	{
		LLColor4U col;
		S32 offset = (i * sResolution + j) * sComponents;
		U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]);
		col.fromRGBA( *pix );
		return col;
	}

	LLImageRaw* getImageRaw(BOOL curr=TRUE);
	void createGLImage(BOOL curr=TRUE);
};

/// TODO Move into the stars draw pool (and rename them appropriately).
class LLHeavenBody
{
protected:
	LLVector3		mDirectionCached;		// hack for events that shouldn't happen every frame

	LLColor3		mColor;
	LLColor3		mColorCached;
	F32				mIntensity;
	LLVector3		mDirection;				// direction of the local heavenly body
	LLVector3		mAngularVelocity;		// velocity of the local heavenly body

	F32				mDiskRadius;
	bool			mDraw;					// FALSE - do not draw.
	F32				mHorizonVisibility;		// number [0, 1] due to how horizon
	F32				mVisibility;			// same but due to other objects being in throng.
	bool			mVisible;
	static F32		sInterpVal;
	LLVector3		mQuadCorner[4];
	LLVector3		mO;

public:
	LLHeavenBody(const F32 rad);
	~LLHeavenBody() {}

	const LLVector3& getDirection()	const;
	void setDirection(const LLVector3 &direction);
	void setAngularVelocity(const LLVector3 &ang_vel);
	const LLVector3& getAngularVelocity() const;

	const LLVector3& getDirectionCached() const;
	void renewDirection();

	const LLColor3& getColorCached() const;
	void setColorCached(const LLColor3& c);
	const LLColor3& getColor() const;
	void setColor(const LLColor3& c);

	void renewColor();

	static F32 interpVal();
	static void setInterpVal(const F32 v);

	LLColor3 getInterpColor() const;

	const F32& getVisibility() const;
	void setVisibility(const F32 c = 1);

	bool isVisible() const;
	void setVisible(const bool v);

	const F32& getIntensity() const;
	void setIntensity(const F32 c);

	void setDiskRadius(const F32 radius);
	F32	getDiskRadius()	const;

	void setDraw(const bool draw);
	bool getDraw() const;

	const LLVector3& corner(const S32 n) const;
	LLVector3& corner(const S32 n);
	const LLVector3* corners() const;
};

class LLCubeMap;

class LLVOSky : public LLStaticViewerObject
{
public:	
	enum
	{
		FACE_SIDE0,
		FACE_SIDE1,
		FACE_SIDE2,
		FACE_SIDE3,
		FACE_SIDE4,
		FACE_SIDE5,
		FACE_SUN, // was 6
		FACE_MOON, // was 7
		FACE_BLOOM, // was 8
		FACE_REFLECTION, // was 10
		FACE_COUNT
	};
	
	LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);

	// Initialize/delete data that's only inited once per class.
	void init();
	void initCubeMap();
	void initEmpty();
	
	void cleanupGL();
	void restoreGL();

	/*virtual*/ void idleUpdate(LLAgent &agent, const F64 &time);
	bool updateSky();
	
	// Graphical stuff for objects - maybe broken out into render class
	// later?
	/*virtual*/ void updateTextures();
	/*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
	/*virtual*/ BOOL		updateGeometry(LLDrawable *drawable);

	const LLHeavenBody& getSun() const						{ return mSun;  }
	const LLHeavenBody& getMoon() const						{ return mMoon; }

	bool isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; }

    // directions provided should already be in CFR coord sys (+x at, +z up, +y right)
    void setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir, const LLVector3 &moon_dir);
    void setSunDirectionCFR(const LLVector3 &sun_direction);
    void setMoonDirectionCFR(const LLVector3 &moon_direction);

	bool updateHeavenlyBodyGeometry(LLDrawable *drawable, F32 scale, const S32 side, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right);
	void updateReflectionGeometry(LLDrawable *drawable, F32 H, const LLHeavenBody& HB);
	
	F32 getWorldScale() const							{ return mWorldScale; }
	void setWorldScale(const F32 s)						{ mWorldScale = s; }
	void updateFog(const F32 distance);

    void setFogRatio(const F32 fog_ratio)               { m_legacyAtmospherics.setFogRatio(fog_ratio); }
    F32  getFogRatio() const                            { return m_legacyAtmospherics.getFogRatio(); }

    LLColor4 getSkyFogColor() const                        { return m_legacyAtmospherics.getFogColor(); }
    LLColor4 getGLFogColor() const                      { return m_legacyAtmospherics.getGLFogColor(); }

    LLColor4U getFadeColor() const;

	void setCloudDensity(F32 cloud_density)				{ mCloudDensity = cloud_density; }
	void setWind ( const LLVector3& wind )				{ mWind = wind.length(); }

	const LLVector3 &getCameraPosAgent() const			{ return mCameraPosAgent; }
	LLVector3 getEarthCenter() const					{ return mEarthCenter; }

	LLCubeMap *getCubeMap() const						{ return mCubeMap; }
	S32 getDrawRefl() const								{ return mDrawRefl; }
	void setDrawRefl(const S32 r)						{ mDrawRefl = r; }
	bool isReflFace(const LLFace* face) const			{ return face == mFace[FACE_REFLECTION]; }
	LLFace* getReflFace() const							{ return mFace[FACE_REFLECTION]; }

	LLViewerTexture*	getSunTex() const					{ return mSunTexturep[0]; }
	LLViewerTexture*	getMoonTex() const					{ return mMoonTexturep[0]; }
	LLViewerTexture*	getBloomTex() const					{ return mBloomTexturep[0]; }
    LLViewerTexture*	getCloudNoiseTex() const			{ return mCloudNoiseTexturep[0]; }

    LLViewerTexture*	getSunTexNext() const					{ return mSunTexturep[1]; }
	LLViewerTexture*	getMoonTexNext() const					{ return mMoonTexturep[1]; }
	LLViewerTexture*	getBloomTexNext() const					{ return mBloomTexturep[1]; }
    LLViewerTexture*	getCloudNoiseTexNext() const			{ return mCloudNoiseTexturep[1]; }

    void setSunTextures(const LLUUID& sun_texture, const LLUUID& sun_texture_next);
    void setMoonTextures(const LLUUID& moon_texture, const LLUUID& moon_texture_next);
    void setCloudNoiseTextures(const LLUUID& cloud_noise_texture, const LLUUID& cloud_noise_texture_next);
    void setBloomTextures(const LLUUID& bloom_texture, const LLUUID& bloom_texture_next);

    void setSunScale(F32 sun_scale);
    void setMoonScale(F32 sun_scale);

	void forceSkyUpdate(void)							{ mForceUpdate = TRUE; }

public:
	LLFace	*mFace[FACE_COUNT];
	LLVector3	mBumpSunDir;

protected:
	~LLVOSky();

	void updateDirections(void);

	void initSkyTextureDirs(const S32 side, const S32 tile);
	void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, bool skip_sky_tex);

	LLPointer<LLViewerFetchedTexture> mSunTexturep[2];
	LLPointer<LLViewerFetchedTexture> mMoonTexturep[2];
    LLPointer<LLViewerFetchedTexture> mCloudNoiseTexturep[2];
	LLPointer<LLViewerFetchedTexture> mBloomTexturep[2];

    F32 mSunScale  = 1.0f;
    F32 mMoonScale = 1.0f;

	static S32			sResolution;
	static S32			sTileResX;
	static S32			sTileResY;
	LLSkyTex			mSkyTex[6];
	LLSkyTex			mShinyTex[6];
	LLHeavenBody		mSun;
	LLHeavenBody		mMoon;
	LLVector3			mSunDefaultPosition;
	LLVector3			mSunAngVel;
	F32					mAtmHeight;
	LLVector3			mEarthCenter;
	LLVector3			mCameraPosAgent;
	F32					mBrightnessScale;
	LLColor3			mBrightestPoint;
	F32					mBrightnessScaleNew;
	LLColor3			mBrightestPointNew;
	F32					mBrightnessScaleGuess;
	LLColor3			mBrightestPointGuess;
	bool				mWeatherChange;
	F32					mCloudDensity;
	F32					mWind;
	
	bool				mInitialized;
	bool				mForceUpdate;				//flag to force instantaneous update of cubemap
	LLVector3			mLastLightingDirection;
	LLColor3			mLastTotalAmbient;
	F32					mAmbientScale;
	LLColor3			mNightColorShift;
	F32					mInterpVal;
	F32					mWorldScale;

	LLPointer<LLCubeMap> mCubeMap;					// Cube map for the environment
	S32					 mDrawRefl;

	LLFrameTimer		mUpdateTimer;
    LLTimer             mForceUpdateThrottle;
	bool                mHeavenlyBodyUpdated ;

    LLAtmospherics      m_legacyAtmospherics;
};

#endif