summaryrefslogtreecommitdiff
path: root/indra/newview/llvosky.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llvosky.cpp')
-rw-r--r--indra/newview/llvosky.cpp233
1 files changed, 87 insertions, 146 deletions
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp
index 37b685f731..28ad3d0877 100644
--- a/indra/newview/llvosky.cpp
+++ b/indra/newview/llvosky.cpp
@@ -85,7 +85,7 @@ namespace
LLTrace::BlockTimerStatHandle FTM_VOSKY_CREATETEXTURES("VOSky Update Textures");
LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATEFORCED("VOSky Update Forced");
- F32Seconds UPDATE_EXPRY(2.0f);
+ F32Seconds UPDATE_EXPRY(0.25f);
}
/***************************************
SkyTex
@@ -419,7 +419,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
mCloudDensity(0.2f),
mWind(0.f),
mForceUpdate(FALSE),
- mCubeMapUpdateStage(-1),
+ mNeedUpdate(TRUE),
mWorldScale(1.f),
mBumpSunDir(0.f, 0.f, 1.f)
{
@@ -502,9 +502,13 @@ void LLVOSky::init()
initSkyTextureDirs(side, tile);
createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex);
createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true);
- }
- mSkyTex[side].create(1.0f);
- mShinyTex[side].create(1.0f);
+ }
+ }
+
+ for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
+ {
+ mSkyTex[i].create(1.0f);
+ mShinyTex[i].create(1.0f);
}
initCubeMap();
@@ -608,8 +612,7 @@ void LLVOSky::restoreGL()
initCubeMap();
}
- mForceUpdate = TRUE;
- mCubeMapUpdateStage = -1;
+ forceSkyUpdate();
if (mDrawable)
{
@@ -672,31 +675,29 @@ void LLVOSky::updateDirections(void)
{
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
- mLastSunLightingDirection = mSun.getDirection();
- mLastMoonLightingDirection = mMoon.getDirection();
-
mSun.setDirection(psky->getSunDirection());
mMoon.setDirection(psky->getMoonDirection());
-
mSun.setRotation(psky->getSunRotation());
mMoon.setRotation(psky->getMoonRotation());
-
mSun.renewDirection();
- mSun.renewColor();
mMoon.renewDirection();
- mMoon.renewColor();
}
void LLVOSky::idleUpdate(LLAgent &agent, const F64 &time)
{
}
+void LLVOSky::forceSkyUpdate()
+{
+ mForceUpdate = TRUE;
+
+ memset(&m_lastAtmosphericsVars, 0x00, sizeof(AtmosphericsVars));
+}
+
bool LLVOSky::updateSky()
{
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
- LLColor4 total_ambient = psky->getTotalAmbient();
-
if (mDead || !(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY)))
{
return TRUE;
@@ -713,13 +714,15 @@ bool LLVOSky::updateSky()
return TRUE;
}
+ bool is_alm_wl_sky = gPipeline.canUseWindLightShaders();
+
static S32 next_frame = 0;
const S32 total_no_tiles = NUM_CUBEMAP_FACES * NUM_TILES;
const S32 cycle_frame_no = total_no_tiles + 1;
const S32 frame = next_frame;
- mForceUpdate = mForceUpdate || (total_no_tiles == frame);
+ mNeedUpdate = mForceUpdate || (total_no_tiles == frame);
++next_frame;
next_frame = next_frame % cycle_frame_no;
@@ -728,143 +731,90 @@ bool LLVOSky::updateSky()
LLHeavenBody::setInterpVal( mInterpVal );
updateDirections();
- if (mCubeMapUpdateStage < 0)
- {
- LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC);
- calc();
+ // Note: must be before comparison of old/current env settings below to be an effective optimization
+ calc();
- LLVector3 direction = mSun.getDirection();
- direction.normalize();
- const F32 dot_sun = direction * mLastSunLightingDirection;
- LLVector3 moon_direction = mMoon.getDirection();
- moon_direction.normalize();
- const F32 dot_moon = moon_direction * mLastMoonLightingDirection;
+ bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars;
- LLColor3 delta_color;
- delta_color.setVec(mLastTotalAmbient.mV[0] - total_ambient.mV[0],
- mLastTotalAmbient.mV[1] - total_ambient.mV[1],
- mLastTotalAmbient.mV[2] - total_ambient.mV[2]);
-
- bool sun_direction_changed = (dot_sun < LIGHT_DIRECTION_THRESHOLD);
- bool moon_direction_changed = (dot_moon < LIGHT_DIRECTION_THRESHOLD);
- bool color_changed = (delta_color.length() >= COLOR_CHANGE_THRESHOLD);
-
- mForceUpdate = mForceUpdate || sun_direction_changed;
- mForceUpdate = mForceUpdate || moon_direction_changed;
- mForceUpdate = mForceUpdate || color_changed;
- mForceUpdate = mForceUpdate || !mInitialized;
+ if (mNeedUpdate && mForceUpdateThrottle.hasExpired() && (mForceUpdate || !same_atmospherics))
+ {
+ LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED);
- bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars;
+ mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY);
- if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics)
- {
- // start updating cube map sides
- if (mCubeMap && !direction.isExactlyZero())
- {
- updateFog(LLViewerCamera::getInstance()->getFar());
+ LLSkyTex::stepCurrent();
+
+ m_lastAtmosphericsVars = m_atmosphericsVars;
- mCubeMapUpdateStage = 0;
- }
- else
- {
- mCubeMapUpdateStage = NUM_CUBEMAP_FACES;
- }
- mForceUpdate = FALSE;
- }
- }
- else if (mCubeMapUpdateStage == NUM_CUBEMAP_FACES)
- {
- LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED);
- LLSkyTex::stepCurrent();
+ mInitialized = TRUE;
- LLVector3 direction = mSun.getDirection();
- if (!direction.isExactlyZero())
- {
- bool is_alm_wl_sky = gPipeline.canUseWindLightShaders();
- int tex = mSkyTex[0].getWhich(TRUE);
+ if (mCubeMap)
+ {
+ updateFog(LLViewerCamera::getInstance()->getFar());
- for (int side = 0; side < NUM_CUBEMAP_FACES; side++)
- {
- LLImageRaw* raw1 = nullptr;
- LLImageRaw* raw2 = nullptr;
+ for (int side = 0; side < NUM_CUBEMAP_FACES; side++)
+ {
+ for (int tile = 0; tile < NUM_TILES; tile++)
+ {
+ createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex);
+ createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true);
+ }
+ }
+ }
- if (!is_alm_wl_sky)
- {
- raw1 = mSkyTex[side].getImageRaw(TRUE);
- raw2 = mSkyTex[side].getImageRaw(FALSE);
- raw2->copy(raw1);
- mSkyTex[side].createGLImage(tex);
- }
+ int tex = mSkyTex[0].getWhich(TRUE);
- raw1 = mShinyTex[side].getImageRaw(TRUE);
- raw2 = mShinyTex[side].getImageRaw(FALSE);
- raw2->copy(raw1);
- mShinyTex[side].createGLImage(tex);
- }
- next_frame = 0;
+ for (int side = 0; side < NUM_CUBEMAP_FACES; side++)
+ {
+ LLImageRaw* raw1 = nullptr;
+ LLImageRaw* raw2 = nullptr;
- // update the sky texture
if (!is_alm_wl_sky)
{
- for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
- {
- mSkyTex[i].create(1.0f);
- }
+ raw1 = mSkyTex[side].getImageRaw(TRUE);
+ raw2 = mSkyTex[side].getImageRaw(FALSE);
+ raw2->copy(raw1);
+ mSkyTex[side].createGLImage(tex);
}
- for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
- {
- mShinyTex[i].create(1.0f);
- }
+ raw1 = mShinyTex[side].getImageRaw(TRUE);
+ raw2 = mShinyTex[side].getImageRaw(FALSE);
+ raw2->copy(raw1);
+ mShinyTex[side].createGLImage(tex);
+ }
+ next_frame = 0;
- // update the environment map
- if (mCubeMap)
- {
- std::vector<LLPointer<LLImageRaw> > images;
- images.reserve(NUM_CUBEMAP_FACES);
- for (S32 side = 0; side < NUM_CUBEMAP_FACES; side++)
- {
- images.push_back(mShinyTex[side].getImageRaw(TRUE));
- }
- mCubeMap->init(images);
- gGL.getTexUnit(0)->disable();
- }
+ // update the sky texture
+ if (!is_alm_wl_sky)
+ {
+ for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
+ {
+ mSkyTex[i].create(1.0f);
+ }
}
- m_lastAtmosphericsVars = m_atmosphericsVars;
- mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY);
- gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE);
- mCubeMapUpdateStage = -1;
- }
- else if (mCubeMapUpdateStage >= 0 && mCubeMapUpdateStage < NUM_CUBEMAP_FACES)
- {
- LL_RECORD_BLOCK_TIME(FTM_VOSKY_CREATETEXTURES);
+ for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
+ {
+ mShinyTex[i].create(1.0f);
+ }
- LLVector3 direction = mSun.getDirection();
- if (!direction.isExactlyZero())
- {
- mLastTotalAmbient = total_ambient;
- mInitialized = TRUE;
+ // update the environment map
+ if (mCubeMap)
+ {
+ std::vector<LLPointer<LLImageRaw> > images;
+ images.reserve(6);
+ for (S32 side = 0; side < NUM_CUBEMAP_FACES; side++)
+ {
+ images.push_back(mShinyTex[side].getImageRaw(TRUE));
+ }
+ mCubeMap->init(images);
+ gGL.getTexUnit(0)->disable();
+ }
- if (mCubeMap)
- {
- S32 side = mCubeMapUpdateStage;
- for (int tile = 0; tile < NUM_TILES; tile++)
- {
- createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex);
- createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true);
- }
- mCubeMapUpdateStage++;
- }
- else
- {
- mCubeMapUpdateStage = NUM_CUBEMAP_FACES;
- }
- }
- else
- {
- mCubeMapUpdateStage = NUM_CUBEMAP_FACES;
- }
+ gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE);
+
+ mNeedUpdate = FALSE;
+ mForceUpdate = FALSE;
}
if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer())
@@ -917,7 +867,7 @@ LLDrawable *LLVOSky::createDrawable(LLPipeline *pipeline)
poolp->setSkyTex(mSkyTex);
mDrawable->setRenderType(LLPipeline::RENDER_TYPE_SKY);
- for (S32 i = 0; i < 6; ++i)
+ for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i)
{
mFace[FACE_SIDE0 + i] = mDrawable->addFace(poolp, NULL);
}
@@ -1079,7 +1029,7 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
U16 index_offset;
LLFace *face;
- for (S32 side = 0; side < 6; ++side)
+ for (S32 side = 0; side < NUM_CUBEMAP_FACES; ++side)
{
face = mFace[FACE_SIDE0 + side];
@@ -1635,10 +1585,7 @@ void LLVOSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir_cfr, const LLV
mBumpSunDir = adjustedDir * sunDot + sun_dir_cfr * (1.0f - sunDot);
mBumpSunDir.normalize();
}
-
updateDirections();
-
- mForceUpdate = true;
}
void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr)
@@ -1660,17 +1607,11 @@ void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr)
mBumpSunDir = adjustedDir * sunDot + sun_dir_cfr * (1.0f - sunDot);
mBumpSunDir.normalize();
}
-
updateDirections();
-
- mForceUpdate = true;
}
void LLVOSky::setMoonDirectionCFR(const LLVector3 &moon_dir_cfr)
{
mMoon.setDirection(moon_dir_cfr);
-
updateDirections();
-
- mForceUpdate = true;
}