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