aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llvostars.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llvostars.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llvostars.cpp')
-rw-r--r--linden/indra/newview/llvostars.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/linden/indra/newview/llvostars.cpp b/linden/indra/newview/llvostars.cpp
new file mode 100644
index 0000000..d20c5da
--- /dev/null
+++ b/linden/indra/newview/llvostars.cpp
@@ -0,0 +1,199 @@
1/**
2 * @file llvostars.cpp
3 * @brief LLVOStars class implementation
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llvostars.h"
31
32#include "lldrawpoolstars.h"
33#include "llface.h"
34#include "llsky.h"
35#include "llvosky.h"
36#include "llworld.h"
37#include "pipeline.h"
38
39const U32 NUMBER_OF_STARS = 1000;
40const F32 DISTANCE_TO_STARS = HORIZON_DIST - 10.f;
41
42
43LLVOStars::LLVOStars(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
44 : LLViewerObject(id, pcode, regionp)
45{
46 initStars();
47}
48
49LLVOStars::~LLVOStars()
50{
51 delete[] mStarVertices;
52 mStarVertices = NULL;
53 delete[] mStarColors;
54 mStarColors = NULL;
55 delete[] mStarIntensities;
56 mStarIntensities = NULL;
57}
58
59LLDrawable *LLVOStars::createDrawable(LLPipeline *pipeline)
60{
61 pipeline->allocDrawable(this);
62 mDrawable->setLit(FALSE);
63
64 LLDrawPoolStars *poolp = (LLDrawPoolStars*) gPipeline.getPool(LLDrawPool::POOL_STARS);
65
66 mFace = mDrawable->addFace(poolp, NULL);
67 mFace->setPrimType(GL_POINTS);
68 mFace->setSize(NUMBER_OF_STARS, NUMBER_OF_STARS);
69
70 return mDrawable;
71}
72
73BOOL LLVOStars::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
74{
75 return TRUE;
76}
77
78BOOL LLVOStars::updateGeometry(LLDrawable *drawable)
79{
80 updateStarColors();
81 updateStarGeometry(drawable);
82
83 LLPipeline::sCompiles++;
84 return TRUE;
85}
86
87BOOL LLVOStars::updateStarGeometry(LLDrawable *drawable)
88{
89 LLStrider<LLVector3> verticesp;
90 LLStrider<LLVector3> normalsp;
91 LLStrider<LLVector2> texCoordsp;
92 LLStrider<LLColor4U> colorsp;
93 U32 *indicesp;
94 S32 index_offset;
95
96 index_offset = mFace->getGeometryColors(verticesp,normalsp,texCoordsp,colorsp, indicesp);
97
98 if (-1 == index_offset)
99 {
100 return TRUE;
101 }
102 LLVector3 cam_pos = gSky.mVOSkyp ? gSky.mVOSkyp->getPositionAgent() : drawable->getPositionAgent();
103 for (U32 vtx = 0; vtx < NUMBER_OF_STARS; ++vtx)
104 {
105 *(verticesp++) = mStarVertices[vtx] + cam_pos;
106 *(colorsp++) = LLColor4U(mStarColors[vtx]);
107 *(indicesp++) = index_offset + vtx;
108 }
109
110 return TRUE;
111}
112
113
114void LLVOStars::initStars()
115{
116 // Initialize star map
117 mStarVertices = new LLVector3 [NUMBER_OF_STARS];
118 mStarColors = new LLColor4 [NUMBER_OF_STARS];
119 mStarIntensities = new F32 [NUMBER_OF_STARS];
120
121 LLVector3 * v_p = mStarVertices;
122 LLColor4 * v_c = mStarColors;
123 F32 * v_i = mStarIntensities;
124
125 U32 i;
126 for (i = 0; i < NUMBER_OF_STARS; i++ )
127 {
128 v_p->mV[VX] = frand(1.f) - 0.5f;
129 v_p->mV[VY] = frand(1.f) - 0.5f;
130
131 // we only want stars on the top half of the dome!
132
133 v_p->mV[VZ] = frand(1.f)/2.f;
134
135 v_p->normVec();
136 *v_p *= DISTANCE_TO_STARS;
137 *v_i = llmin((F32)pow(frand(1.f),2.f) + 0.1f, 1.f);
138 v_c->mV[VRED] = 0.75f + frand(1.f) * 0.25f ;
139 v_c->mV[VGREEN] = 1.f ;
140 v_c->mV[VBLUE] = 0.75f + frand(1.f) * 0.25f ;
141 v_c->mV[VALPHA] = 1.f;
142 v_c->clamp();
143 v_p++;
144 v_c++;
145 v_i++;
146 }
147}
148
149void LLVOStars::updateStarColors()
150{
151 LLColor4 * v_c;
152 v_c = mStarColors;
153 F32 * v_i = mStarIntensities;
154 LLVector3* v_p = mStarVertices;
155
156 const F32 var = 0.15f;
157 const F32 min = 0.5f; //0.75f;
158 const F32 sunclose_max = 0.6f;
159 const F32 sunclose_range = 1 - sunclose_max;
160
161 F32 below_horizon = - llmin(0.0f, gSky.mVOSkyp->getToSunLast().mV[2]);
162 F32 brightness_factor = llmin(1.0f, below_horizon * 20);
163
164 static S32 swap = 0;
165 swap++;
166
167 if ((swap % 2) == 1)
168 {
169 F32 intensity; // max intensity of each star
170 U32 x;
171 for (x = 0; x < NUMBER_OF_STARS; x++)
172 {
173 F32 sundir_factor = 1;
174 LLVector3 tostar = *v_p;
175 tostar.normVec();
176 const F32 how_close_to_sun = tostar * gSky.mVOSkyp->getToSun();
177 if (how_close_to_sun > sunclose_max)
178 {
179 sundir_factor = (1 - how_close_to_sun) / sunclose_range;
180 }
181 intensity = *(v_i);
182 F32 alpha = v_c->mV[VALPHA] + (frand(1.f) - 0.5f) * var * intensity;
183 if (alpha < min * intensity)
184 {
185 alpha = min * intensity;
186 }
187 if (alpha > intensity)
188 {
189 alpha = intensity;
190 }
191 alpha *= brightness_factor * sundir_factor;
192 alpha = llclamp(alpha, 0.f, 1.f);
193 v_c->mV[VALPHA] = alpha;
194 v_c++;
195 v_i++;
196 v_p++;
197 }
198 }
199}