void LLVOWLSky::initStars() { // Initialize star map mStarVertices.resize(getStarsNumVerts()); mStarColors.resize(getStarsNumVerts()); mStarIntensities.resize(getStarsNumVerts()); std::vector<LLVector3>::iterator v_p = mStarVertices.begin(); std::vector<LLColor4>::iterator v_c = mStarColors.begin(); std::vector<F32>::iterator v_i = mStarIntensities.begin(); U32 i; for (i = 0; i < getStarsNumVerts(); ++i) { v_p->mV[VX] = ll_frand() - 0.5f; v_p->mV[VY] = ll_frand() - 0.5f; // we only want stars on the top half of the dome! v_p->mV[VZ] = ll_frand()/2.f; v_p->normVec(); *v_p *= DISTANCE_TO_STARS; *v_i = llmin((F32)pow(ll_frand(),2.f) + 0.1f, 1.f); v_c->mV[VRED] = 0.75f + ll_frand() * 0.25f ; v_c->mV[VGREEN] = 1.f ; v_c->mV[VBLUE] = 0.75f + ll_frand() * 0.25f ; v_c->mV[VALPHA] = 1.f; v_c->clamp(); v_p++; v_c++; v_i++; } }
BOOL LLVOWLSky::updateStarGeometry(LLDrawable *drawable) { LLStrider<LLVector3> verticesp; LLStrider<LLColor4U> colorsp; LLStrider<LLVector2> texcoordsp; if (mStarsVerts.isNull()) { mStarsVerts = new LLVertexBuffer(LLDrawPoolWLSky::STAR_VERTEX_DATA_MASK, GL_DYNAMIC_DRAW); mStarsVerts->allocateBuffer(getStarsNumVerts()*4, 0, TRUE); } BOOL success = mStarsVerts->getVertexStrider(verticesp) && mStarsVerts->getColorStrider(colorsp) && mStarsVerts->getTexCoord0Strider(texcoordsp); if(!success) { llerrs << "Failed updating star geometry." << llendl; } // *TODO: fix LLStrider with a real prefix increment operator so it can be // used as a model of OutputIterator. -Brad // std::copy(mStarVertices.begin(), mStarVertices.end(), verticesp); if (mStarVertices.size() < getStarsNumVerts()) { llerrs << "Star reference geometry insufficient." << llendl; } for (U32 vtx = 0; vtx < getStarsNumVerts(); ++vtx) { LLVector3 at = mStarVertices[vtx]; at.normVec(); LLVector3 left = at%LLVector3(0,0,1); LLVector3 up = at%left; F32 sc = 0.5f+ll_frand()*1.25f; left *= sc; up *= sc; *(verticesp++) = mStarVertices[vtx]; *(verticesp++) = mStarVertices[vtx]+left; *(verticesp++) = mStarVertices[vtx]+left+up; *(verticesp++) = mStarVertices[vtx]+up; *(texcoordsp++) = LLVector2(0,0); *(texcoordsp++) = LLVector2(0,1); *(texcoordsp++) = LLVector2(1,1); *(texcoordsp++) = LLVector2(1,0); *(colorsp++) = LLColor4U(mStarColors[vtx]); *(colorsp++) = LLColor4U(mStarColors[vtx]); *(colorsp++) = LLColor4U(mStarColors[vtx]); *(colorsp++) = LLColor4U(mStarColors[vtx]); } mStarsVerts->setBuffer(0); return TRUE; }
BOOL LLVOWLSky::updateStarGeometry(LLDrawable *drawable) { LLStrider<LLVector3> verticesp; LLStrider<LLColor4U> colorsp; LLStrider<U16> indicesp; if (mStarsVerts.isNull()) { mStarsVerts = new LLVertexBuffer(LLDrawPoolWLSky::STAR_VERTEX_DATA_MASK, GL_DYNAMIC_DRAW); mStarsVerts->allocateBuffer(getStarsNumVerts(), getStarsNumIndices(), TRUE); } BOOL success = mStarsVerts->getVertexStrider(verticesp) && mStarsVerts->getIndexStrider(indicesp) && mStarsVerts->getColorStrider(colorsp); if(!success) { llerrs << "Failed updating star geometry." << llendl; } // *TODO: fix LLStrider with a real prefix increment operator so it can be // used as a model of OutputIterator. -Brad // std::copy(mStarVertices.begin(), mStarVertices.end(), verticesp); for (U32 vtx = 0; vtx < getStarsNumVerts(); ++vtx) { *(verticesp++) = mStarVertices[vtx]; *(colorsp++) = LLColor4U(mStarColors[vtx]); *(indicesp++) = vtx; } mStarsVerts->setBuffer(0); return TRUE; }
void LLVOWLSky::drawStars(void) { // render the stars as a sphere centered at viewer camera if (mStarsVerts.notNull()) { mStarsVerts->setBuffer(LLDrawPoolWLSky::STAR_VERTEX_DATA_MASK); mStarsVerts->drawArrays(LLRender::TRIANGLES, 0, getStarsNumVerts()*4); } }
void LLVOWLSky::updateStarColors() { std::vector<LLColor4>::iterator v_c = mStarColors.begin(); std::vector<F32>::iterator v_i = mStarIntensities.begin(); std::vector<LLVector3>::iterator v_p = mStarVertices.begin(); const F32 var = 0.15f; const F32 min = 0.5f; //0.75f; const F32 sunclose_max = 0.6f; const F32 sunclose_range = 1 - sunclose_max; //F32 below_horizon = - llmin(0.0f, gSky.mVOSkyp->getToSunLast().mV[2]); //F32 brightness_factor = llmin(1.0f, below_horizon * 20); static S32 swap = 0; swap++; if ((swap % 2) == 1) { F32 intensity; // max intensity of each star U32 x; for (x = 0; x < getStarsNumVerts(); ++x) { F32 sundir_factor = 1; LLVector3 tostar = *v_p; tostar.normVec(); const F32 how_close_to_sun = tostar * gSky.mVOSkyp->getToSunLast(); if (how_close_to_sun > sunclose_max) { sundir_factor = (1 - how_close_to_sun) / sunclose_range; } intensity = *(v_i); F32 alpha = v_c->mV[VALPHA] + (ll_frand() - 0.5f) * var * intensity; if (alpha < min * intensity) { alpha = min * intensity; } if (alpha > intensity) { alpha = intensity; } //alpha *= brightness_factor * sundir_factor; alpha = llclamp(alpha, 0.f, 1.f); v_c->mV[VALPHA] = alpha; v_c++; v_i++; v_p++; } } }