diff options
Diffstat (limited to 'indra/newview/llvosky.cpp')
-rw-r--r-- | indra/newview/llvosky.cpp | 240 |
1 files changed, 105 insertions, 135 deletions
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 78c782eb5f..19299f55a2 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -64,6 +64,7 @@ namespace const S32 NUM_TILES_X = 8; const S32 NUM_TILES_Y = 4; const S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; + const S32 NUM_CUBEMAP_FACES = 6; // Heavenly body constants const F32 SUN_DISK_RADIUS = 0.5f; @@ -76,13 +77,12 @@ namespace const LLVector2 TEX10 = LLVector2(1.f, 0.f); const LLVector2 TEX11 = LLVector2(1.f, 1.f); - const F32 LIGHT_DIRECTION_THRESHOLD = (F32) cosf(DEG_TO_RAD * 1.f); - const F32 COLOR_CHANGE_THRESHOLD = 0.01f; - LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATETIMER("VOSky Update Timer Tick"); + LLTrace::BlockTimerStatHandle FTM_VOSKY_CALC("VOSky Update Calculations"); + 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 @@ -416,6 +416,8 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mCloudDensity(0.2f), mWind(0.f), mForceUpdate(FALSE), + mNeedUpdate(TRUE), + mCubeMapUpdateStage(-1), mWorldScale(1.f), mBumpSunDir(0.f, 0.f, 1.f) { @@ -428,7 +430,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); mForceUpdateThrottle.reset(); - for (S32 i = 0; i < 6; i++) + for (S32 i = 0; i < NUM_CUBEMAP_FACES; i++) { mSkyTex[i].init(false); mShinyTex[i].init(true); @@ -491,20 +493,16 @@ void LLVOSky::init() m_atmosphericsVars.gamma = psky->getGamma(); // Initialize the cached normalized direction vectors - for (S32 side = 0; side < 6; ++side) + for (S32 side = 0; side < NUM_CUBEMAP_FACES; ++side) { for (S32 tile = 0; tile < NUM_TILES; ++tile) { initSkyTextureDirs(side, tile); createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); - } - } - - for (S32 i = 0; i < 6; ++i) - { - mSkyTex[i].create(1.0f); - mShinyTex[i].create(1.0f); + } + mSkyTex[side].create(1.0f); + mShinyTex[side].create(1.0f); } initCubeMap(); @@ -553,7 +551,7 @@ void LLVOSky::calc() void LLVOSky::initCubeMap() { std::vector<LLPointer<LLImageRaw> > images; - for (S32 side = 0; side < 6; side++) + for (S32 side = 0; side < NUM_CUBEMAP_FACES; side++) { images.push_back(mShinyTex[side].getImageRaw()); } @@ -575,7 +573,7 @@ void LLVOSky::initCubeMap() void LLVOSky::cleanupGL() { S32 i; - for (i = 0; i < 6; i++) + for (i = 0; i < NUM_CUBEMAP_FACES; i++) { mSkyTex[i].cleanupGL(); } @@ -588,7 +586,7 @@ void LLVOSky::cleanupGL() void LLVOSky::restoreGL() { S32 i; - for (i = 0; i < 6; i++) + for (i = 0; i < NUM_CUBEMAP_FACES; i++) { mSkyTex[i].restoreGL(); } @@ -608,7 +606,7 @@ void LLVOSky::restoreGL() initCubeMap(); } - mForceUpdate = TRUE; + forceSkyUpdate(); if (mDrawable) { @@ -671,31 +669,31 @@ 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)); + + mCubeMapUpdateStage = -1; +} + 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; @@ -712,13 +710,13 @@ bool LLVOSky::updateSky() return TRUE; } + bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + static S32 next_frame = 0; - const S32 total_no_tiles = 6 * NUM_TILES; + 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; ++next_frame; next_frame = next_frame % cycle_frame_no; @@ -727,117 +725,98 @@ bool LLVOSky::updateSky() LLHeavenBody::setInterpVal( mInterpVal ); updateDirections(); - LLVector3 direction = mSun.getDirection(); - direction.normalize(); - const F32 dot_sun = direction * mLastSunLightingDirection; - const F32 dot_moon = direction * mLastMoonLightingDirection; - - 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 (!mCubeMap) + { + mCubeMapUpdateStage = NUM_CUBEMAP_FACES; + mForceUpdate = FALSE; + return TRUE; + } - bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + if (mCubeMapUpdateStage < 0) + { + LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC); + calc(); - calc(); + bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; - bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; + mNeedUpdate = mNeedUpdate || !same_atmospherics; - if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics) - { + if (mNeedUpdate && (mForceUpdateThrottle.hasExpired() || mForceUpdate)) + { + // start updating cube map sides + updateFog(LLViewerCamera::getInstance()->getFar()); + mCubeMapUpdateStage = 0; + mForceUpdate = FALSE; + } + } + else if (mCubeMapUpdateStage == NUM_CUBEMAP_FACES) + { LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); + LLSkyTex::stepCurrent(); - mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); - - LLSkyTex::stepCurrent(); - - m_lastAtmosphericsVars = m_atmosphericsVars; - - if (!direction.isExactlyZero()) - { - mLastTotalAmbient = total_ambient; - mInitialized = TRUE; + int tex = mSkyTex[0].getWhich(TRUE); - if (mCubeMap) - { - updateFog(LLViewerCamera::getInstance()->getFar()); - - for (int side = 0; side < 6; side++) - { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); - } - } - } - - int tex = mSkyTex[0].getWhich(TRUE); - - for (int side = 0; side < 6; side++) - { - LLImageRaw* raw1 = nullptr; - LLImageRaw* raw2 = nullptr; + for (int side = 0; side < NUM_CUBEMAP_FACES; side++) + { + LLImageRaw* raw1 = nullptr; + LLImageRaw* raw2 = nullptr; - if (!is_alm_wl_sky) - { - raw1 = mSkyTex[side].getImageRaw(TRUE); - raw2 = mSkyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mSkyTex[side].createGLImage(tex); - } + if (!is_alm_wl_sky) + { + raw1 = mSkyTex[side].getImageRaw(TRUE); + raw2 = mSkyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mSkyTex[side].createGLImage(tex); + } - raw1 = mShinyTex[side].getImageRaw(TRUE); - raw2 = mShinyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mShinyTex[side].createGLImage(tex); - } - next_frame = 0; + raw1 = mShinyTex[side].getImageRaw(TRUE); + raw2 = mShinyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mShinyTex[side].createGLImage(tex); + } + next_frame = 0; - // update the sky texture - if (!is_alm_wl_sky) + // update the sky texture + if (!is_alm_wl_sky) + { + for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) { - for (S32 i = 0; i < 6; ++i) - { - mSkyTex[i].create(1.0f); - } + mSkyTex[i].create(1.0f); } + } - for (S32 i = 0; i < 6; ++i) - { - mShinyTex[i].create(1.0f); - } + for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) + { + mShinyTex[i].create(1.0f); + } - // update the environment map - if (mCubeMap) - { - std::vector<LLPointer<LLImageRaw> > images; - images.reserve(6); - for (S32 side = 0; side < 6; side++) - { - images.push_back(mShinyTex[side].getImageRaw(TRUE)); - } - mCubeMap->init(images); - gGL.getTexUnit(0)->disable(); - } - } + // update the environment map + initCubeMap(); - gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - mForceUpdate = FALSE; - } + m_lastAtmosphericsVars = m_atmosphericsVars; - if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) + mNeedUpdate = FALSE; + mForceUpdate = FALSE; + + mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); + gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); + + if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) + { + gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); + } + mCubeMapUpdateStage = -1; + } + else if (mCubeMapUpdateStage >= 0 && mCubeMapUpdateStage < NUM_CUBEMAP_FACES) { - gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); + LL_RECORD_BLOCK_TIME(FTM_VOSKY_CREATETEXTURES); + 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++; } return TRUE; @@ -885,7 +864,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); } @@ -1047,7 +1026,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]; @@ -1603,10 +1582,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) @@ -1628,17 +1604,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; } |