From a0a1d93fb6a74149bbef57f1d1489510247110ca Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Nov 2018 09:49:36 -0800 Subject: Merge 6ish --- indra/newview/llvosky.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index c131cb886f..54ec238fde 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -54,6 +54,10 @@ #undef min #undef max +#if LL_WINDOWS +#pragma optimize("", off) +#endif + static const S32 NUM_TILES_X = 8; static const S32 NUM_TILES_Y = 4; static const S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; -- cgit v1.3 From 30fc38603a6031f1f9ed1b4f33beca9e469b5ed3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 3 Jan 2019 11:22:46 -0800 Subject: Fix two files stomped my merging VR before a downstream branch. --- indra/newview/lldrawpoolwater.cpp | 314 +++--- indra/newview/llvosky.cpp | 2248 ++++++++++++++----------------------- 2 files changed, 981 insertions(+), 1581 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 9316890156..ee37f36cbd 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -46,14 +46,9 @@ #include "llworld.h" #include "pipeline.h" #include "llviewershadermgr.h" -#include "llwaterparammanager.h" - -#if LL_WINDOWS -#pragma optimize("", off) -#endif - -const LLUUID TRANSPARENT_WATER_TEXTURE("2bfd3884-7e27-69b9-ba3a-3e673f680004"); -const LLUUID OPAQUE_WATER_TEXTURE("43c32285-d658-1793-c123-bf86315de055"); +#include "llenvironment.h" +#include "llsettingssky.h" +#include "llsettingswater.h" static float sTime; @@ -62,42 +57,51 @@ BOOL deferred_render = FALSE; BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE; BOOL LLDrawPoolWater::sNeedsReflectionUpdate = TRUE; BOOL LLDrawPoolWater::sNeedsDistortionUpdate = TRUE; -LLColor4 LLDrawPoolWater::sWaterFogColor = LLColor4(0.2f, 0.5f, 0.5f, 0.f); F32 LLDrawPoolWater::sWaterFogEnd = 0.f; -LLVector3 LLDrawPoolWater::sLightDir; - -LLDrawPoolWater::LLDrawPoolWater() : - LLFacePool(POOL_WATER) +LLDrawPoolWater::LLDrawPoolWater() : LLFacePool(POOL_WATER) { - mHBTex[0] = LLViewerTextureManager::getFetchedTexture(gSunTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - gGL.getTexUnit(0)->bind(mHBTex[0]) ; - mHBTex[0]->setAddressMode(LLTexUnit::TAM_CLAMP); - - mHBTex[1] = LLViewerTextureManager::getFetchedTexture(gMoonTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - gGL.getTexUnit(0)->bind(mHBTex[1]); - mHBTex[1]->setAddressMode(LLTexUnit::TAM_CLAMP); +} +LLDrawPoolWater::~LLDrawPoolWater() +{ +} - mWaterImagep = LLViewerTextureManager::getFetchedTexture(TRANSPARENT_WATER_TEXTURE); - llassert(mWaterImagep); - mWaterImagep->setNoDelete(); - mOpaqueWaterImagep = LLViewerTextureManager::getFetchedTexture(OPAQUE_WATER_TEXTURE); - llassert(mOpaqueWaterImagep); - mWaterNormp = LLViewerTextureManager::getFetchedTexture(DEFAULT_WATER_NORMAL); - mWaterNormp->setNoDelete(); +void LLDrawPoolWater::setTransparentTextures(const LLUUID& transparentTextureId, const LLUUID& nextTransparentTextureId) +{ + LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); + mWaterImagep[0] = LLViewerTextureManager::getFetchedTexture(!transparentTextureId.isNull() ? transparentTextureId : pwater->GetDefaultTransparentTextureAssetId()); + mWaterImagep[1] = LLViewerTextureManager::getFetchedTexture(!nextTransparentTextureId.isNull() ? nextTransparentTextureId : (!transparentTextureId.isNull() ? transparentTextureId : pwater->GetDefaultTransparentTextureAssetId())); + mWaterImagep[0]->addTextureStats(1024.f*1024.f); + mWaterImagep[1]->addTextureStats(1024.f*1024.f); +} - restoreGL(); +void LLDrawPoolWater::setOpaqueTexture(const LLUUID& opaqueTextureId) +{ + LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); + mOpaqueWaterImagep = LLViewerTextureManager::getFetchedTexture(opaqueTextureId); + mOpaqueWaterImagep->addTextureStats(1024.f*1024.f); } -LLDrawPoolWater::~LLDrawPoolWater() +void LLDrawPoolWater::setNormalMaps(const LLUUID& normalMapId, const LLUUID& nextNormalMapId) { + LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); + mWaterNormp[0] = LLViewerTextureManager::getFetchedTexture(!normalMapId.isNull() ? normalMapId : pwater->GetDefaultWaterNormalAssetId()); + mWaterNormp[1] = LLViewerTextureManager::getFetchedTexture(!nextNormalMapId.isNull() ? nextNormalMapId : (!normalMapId.isNull() ? normalMapId : pwater->GetDefaultWaterNormalAssetId())); + mWaterNormp[0]->addTextureStats(1024.f*1024.f); + mWaterNormp[1]->addTextureStats(1024.f*1024.f); } //static void LLDrawPoolWater::restoreGL() { - + /*LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater(); + if (pwater) + { + setTransparentTextures(pwater->getTransparentTextureID(), pwater->getNextTransparentTextureID()); + setOpaqueTexture(pwater->GetDefaultOpaqueTextureAssetId()); + setNormalMaps(pwater->getNormalMapID(), pwater->getNextNormalMapID()); + }*/ } LLDrawPool *LLDrawPoolWater::instancePool() @@ -109,14 +113,7 @@ LLDrawPool *LLDrawPoolWater::instancePool() void LLDrawPoolWater::prerender() { - mVertexShaderLevel = (gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) ? - LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_WATER) : 0; - - // got rid of modulation by light color since it got a little too - // green at sunset and sl-57047 (underwater turns black at 8:00) - sWaterFogColor = LLWaterParamManager::instance().getFogColor(); - sWaterFogColor.mV[3] = 0; - + mShaderLevel = (gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) ? LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_WATER) : 0; } S32 LLDrawPoolWater::getNumPasses() @@ -182,7 +179,7 @@ void LLDrawPoolWater::render(S32 pass) LLGLEnable blend(GL_BLEND); - if ((mVertexShaderLevel > 0) && !sSkipScreenCopy) + if ((mShaderLevel > 0) && !sSkipScreenCopy) { shade(); return; @@ -207,10 +204,13 @@ void LLDrawPoolWater::render(S32 pass) LLGLDisable cullFace(GL_CULL_FACE); // Set up second pass first - mWaterImagep->addTextureStats(1024.f*1024.f); gGL.getTexUnit(1)->activate(); gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE); - gGL.getTexUnit(1)->bind(mWaterImagep) ; + gGL.getTexUnit(1)->bind(mWaterImagep[0]) ; + + gGL.getTexUnit(2)->activate(); + gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE); + gGL.getTexUnit(2)->bind(mWaterImagep[1]) ; LLVector3 camera_up = LLViewerCamera::getInstance()->getUpAxis(); F32 up_dot = camera_up * LLVector3::z_axis; @@ -267,6 +267,14 @@ void LLDrawPoolWater::render(S32 pass) gGL.getTexUnit(1)->activate(); gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(1)->disable(); + + glDisable(GL_TEXTURE_GEN_S); //texture unit 1 + glDisable(GL_TEXTURE_GEN_T); //texture unit 1 + + gGL.getTexUnit(1)->activate(); + gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE); + gGL.getTexUnit(1)->disable(); + glDisable(GL_TEXTURE_GEN_S); //texture unit 1 glDisable(GL_TEXTURE_GEN_T); //texture unit 1 @@ -366,8 +374,6 @@ void LLDrawPoolWater::renderOpaqueLegacyWater() gPipeline.disableLights(); - mOpaqueWaterImagep->addTextureStats(1024.f*1024.f); - // Activate the texture binding and bind one // texture since all images will have the same texture gGL.getTexUnit(0)->activate(); @@ -465,7 +471,7 @@ void LLDrawPoolWater::renderReflection(LLFace* face) LLGLSNoFog noFog; - gGL.getTexUnit(0)->bind(mHBTex[dr]); + gGL.getTexUnit(0)->bind((dr == 0) ? voskyp->getSunTex() : voskyp->getMoonTex()); LLOverrideFaceColor override(this, LLColor4(face->getFaceColor().mV)); face->renderIndexed(); @@ -490,30 +496,32 @@ void LLDrawPoolWater::shade() LLColor3 light_diffuse(0,0,0); F32 light_exp = 0.0f; LLVector3 light_dir; - LLColor3 light_color; - - if (gSky.getSunDirection().mV[2] > LLSky::NIGHTTIME_ELEVATION_COS) - { - light_dir = gSky.getSunDirection(); - light_dir.normVec(); - light_color = gSky.getSunDiffuseColor(); - if(gSky.mVOSkyp) { - light_diffuse = gSky.mVOSkyp->getSun().getColorCached(); - light_diffuse.normVec(); - } - light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0); - light_diffuse *= light_exp + 0.25f; - } - else - { - light_dir = gSky.getMoonDirection(); - light_dir.normVec(); - light_color = gSky.getMoonDiffuseColor(); - light_diffuse = gSky.mVOSkyp->getMoon().getColorCached(); - light_diffuse.normVec(); - light_diffuse *= 0.5f; - light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0); + + LLEnvironment& environment = LLEnvironment::instance(); + LLSettingsWater::ptr_t pwater = environment.getCurrentWater(); + LLSettingsSky::ptr_t psky = environment.getCurrentSky(); + + light_dir = environment.getLightDirection(); + light_dir.normalize(); + + bool sun_up = environment.getIsSunUp(); + bool moon_up = environment.getIsMoonUp(); + + if (sun_up) + { + light_diffuse += voskyp->getSun().getColorCached(); } + // moonlight is several orders of magnitude less bright than sunlight, + // so only use this color when the moon alone is showing + else if (moon_up) + { + light_diffuse += psky->getMoonDiffuse(); + } + + light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0.f); + + light_diffuse.normalize(); + light_diffuse *= (light_exp + 0.25f); light_exp *= light_exp; light_exp *= light_exp; @@ -522,20 +530,22 @@ void LLDrawPoolWater::shade() light_exp *= 256.f; light_exp = light_exp > 32.f ? light_exp : 32.f; + light_diffuse *= 6.f; + LLGLSLShader* shader; - F32 eyedepth = LLViewerCamera::getInstance()->getOrigin().mV[2] - gAgent.getRegion()->getWaterHeight(); + F32 eyedepth = LLViewerCamera::getInstance()->getOrigin().mV[2] - LLEnvironment::instance().getWaterHeight(); if (eyedepth < 0.f && LLPipeline::sWaterReflections) { - if (deferred_render) - { - shader = &gDeferredUnderWaterProgram; - } + if (deferred_render) + { + shader = &gDeferredUnderWaterProgram; + } else - { - shader = &gUnderWaterProgram; - } + { + shader = &gUnderWaterProgram; + } } else if (deferred_render) { @@ -546,16 +556,18 @@ void LLDrawPoolWater::shade() shader = &gWaterProgram; } + shader->bind(); + if (deferred_render) { - gPipeline.bindDeferredShader(*shader); - } - else - { - shader->bind(); + if (shader->getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0) + { + glh::matrix4f norm_mat = get_current_modelview().inverse().transpose(); + shader->uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.m); + } } - sTime = (F32)LLFrameTimer::getElapsedSeconds()*0.5f; + sTime = (F32)LLFrameTimer::getElapsedSeconds() * 0.5f; S32 reftex = shader->enableTexture(LLShaderMgr::WATER_REFTEX); @@ -569,43 +581,48 @@ void LLDrawPoolWater::shade() //bind normal map S32 bumpTex = shader->enableTexture(LLViewerShaderMgr::BUMP_MAP); - LLWaterParamManager * param_mgr = &LLWaterParamManager::instance(); + if (mWaterNormp[0]) + { + gGL.getTexUnit(bumpTex)->bind(mWaterNormp[0]) ; - // change mWaterNormp if needed - if (mWaterNormp->getID() != param_mgr->getNormalMapID()) - { - mWaterNormp = LLViewerTextureManager::getFetchedTexture(param_mgr->getNormalMapID()); + if (gSavedSettings.getBOOL("RenderWaterMipNormal")) + { + mWaterNormp[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); + } + else + { + mWaterNormp[0]->setFilteringOption(LLTexUnit::TFO_POINT); + } } - mWaterNormp->addTextureStats(1024.f*1024.f); - gGL.getTexUnit(bumpTex)->bind(mWaterNormp) ; - if (gSavedSettings.getBOOL("RenderWaterMipNormal")) - { - mWaterNormp->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); - } - else - { - mWaterNormp->setFilteringOption(LLTexUnit::TFO_POINT); - } - - S32 screentex = shader->enableTexture(LLShaderMgr::WATER_SCREENTEX); - - if (screentex > -1) - { - shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, sWaterFogColor.mV); - shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, - param_mgr->getFogDensity()); - gPipeline.mWaterDis.bindTexture(0, screentex); + if (mWaterNormp[1]) + { + bumpTex = shader->enableTexture(LLViewerShaderMgr::BUMP_MAP2); + + gGL.getTexUnit(bumpTex)->bind(mWaterNormp[1]) ; + + if (gSavedSettings.getBOOL("RenderWaterMipNormal")) + { + mWaterNormp[1]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); + } + else + { + mWaterNormp[1]->setFilteringOption(LLTexUnit::TFO_POINT); + } } + + shader->uniform3fv(LLShaderMgr::WATER_FOGCOLOR, 1, pwater->getWaterFogColor().mV); + shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, pwater->getWaterFogDensity()); - stop_glerror(); - + // bind reflection texture from RenderTarget + S32 screentex = shader->enableTexture(LLShaderMgr::WATER_SCREENTEX); gGL.getTexUnit(screentex)->bind(&gPipeline.mWaterDis); - if (mVertexShaderLevel == 1) + if (mShaderLevel == 1) { - sWaterFogColor.mV[3] = param_mgr->mDensitySliderValue; - shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, sWaterFogColor.mV); + LLColor4 fog_color(pwater->getWaterFogColor(), 0.f); + fog_color[3] = pwater->getWaterFogDensity(); + shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, fog_color.mV); } F32 screenRes[] = @@ -619,25 +636,30 @@ void LLDrawPoolWater::shade() S32 diffTex = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP); stop_glerror(); - light_dir.normVec(); - sLightDir = light_dir; - - light_diffuse *= 6.f; - //shader->uniformMatrix4fv("inverse_ref", 1, GL_FALSE, (GLfloat*) gGLObliqueProjectionInverse.mMatrix); shader->uniform1f(LLShaderMgr::WATER_WATERHEIGHT, eyedepth); shader->uniform1f(LLShaderMgr::WATER_TIME, sTime); shader->uniform3fv(LLShaderMgr::WATER_EYEVEC, 1, LLViewerCamera::getInstance()->getOrigin().mV); shader->uniform3fv(LLShaderMgr::WATER_SPECULAR, 1, light_diffuse.mV); shader->uniform1f(LLShaderMgr::WATER_SPECULAR_EXP, light_exp); - shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR1, 1, param_mgr->getWave1Dir().mV); - shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR2, 1, param_mgr->getWave2Dir().mV); + if (LLEnvironment::instance().isCloudScrollPaused()) + { + static const std::array zerowave{ {0.0f, 0.0f} }; + + shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR1, 1, zerowave.data()); + shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR2, 1, zerowave.data()); + } + else + { + shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR1, 1, pwater->getWave1Dir().mV); + shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR2, 1, pwater->getWave2Dir().mV); + } shader->uniform3fv(LLShaderMgr::WATER_LIGHT_DIR, 1, light_dir.mV); - shader->uniform3fv(LLShaderMgr::WATER_NORM_SCALE, 1, param_mgr->getNormalScale().mV); - shader->uniform1f(LLShaderMgr::WATER_FRESNEL_SCALE, param_mgr->getFresnelScale()); - shader->uniform1f(LLShaderMgr::WATER_FRESNEL_OFFSET, param_mgr->getFresnelOffset()); - shader->uniform1f(LLShaderMgr::WATER_BLUR_MULTIPLIER, param_mgr->getBlurMultiplier()); + shader->uniform3fv(LLShaderMgr::WATER_NORM_SCALE, 1, pwater->getNormalScale().mV); + shader->uniform1f(LLShaderMgr::WATER_FRESNEL_SCALE, pwater->getFresnelScale()); + shader->uniform1f(LLShaderMgr::WATER_FRESNEL_OFFSET, pwater->getFresnelOffset()); + shader->uniform1f(LLShaderMgr::WATER_BLUR_MULTIPLIER, pwater->getBlurMultiplier()); F32 sunAngle = llmax(0.f, light_dir.mV[2]); F32 scaledAngle = 1.f - sunAngle; @@ -652,12 +674,12 @@ void LLDrawPoolWater::shade() if (LLViewerCamera::getInstance()->cameraUnderWater()) { water_color.setVec(1.f, 1.f, 1.f, 0.4f); - shader->uniform1f(LLShaderMgr::WATER_REFSCALE, param_mgr->getScaleBelow()); + shader->uniform1f(LLShaderMgr::WATER_REFSCALE, pwater->getScaleBelow()); } else { water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot)); - shader->uniform1f(LLShaderMgr::WATER_REFSCALE, param_mgr->getScaleAbove()); + shader->uniform1f(LLShaderMgr::WATER_REFSCALE, pwater->getScaleAbove()); } if (water_color.mV[3] > 0.9f) @@ -665,40 +687,19 @@ void LLDrawPoolWater::shade() water_color.mV[3] = 0.9f; } - { - LLGLEnable depth_clamp(gGLManager.mHasDepthClamp ? GL_DEPTH_CLAMP : 0); + { LLGLDisable cullface(GL_CULL_FACE); - for (std::vector::iterator iter = mDrawFace.begin(); - iter != mDrawFace.end(); iter++) - { - LLFace *face = *iter; - if (voskyp->isReflFace(face)) - { - continue; - } + sNeedsReflectionUpdate = TRUE; + sNeedsDistortionUpdate = TRUE; - LLVOWater* water = (LLVOWater*) face->getViewerObject(); + for (std::vector::iterator iter = mDrawFace.begin(); iter != mDrawFace.end(); iter++) + { + LLFace *face = *iter; gGL.getTexUnit(diffTex)->bind(face->getTexture()); - - sNeedsReflectionUpdate = TRUE; - - if (water->getUseTexture() || !water->getIsEdgePatch()) - { - sNeedsDistortionUpdate = TRUE; - face->renderIndexed(); - } - else if (gGLManager.mHasDepthClamp || deferred_render) - { - face->renderIndexed(); - } - else - { - LLGLSquashToFarClip far_clip(glh_get_current_projection()); - face->renderIndexed(); - } + face->renderIndexed(); } - } + } shader->disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP); shader->disableTexture(LLShaderMgr::WATER_SCREENTEX); @@ -707,14 +708,7 @@ void LLDrawPoolWater::shade() shader->disableTexture(LLShaderMgr::WATER_REFTEX); shader->disableTexture(LLShaderMgr::WATER_SCREENDEPTH); - if (deferred_render) - { - gPipeline.unbindDeferredShader(*shader); - } - else - { - shader->unbind(); - } + shader->unbind(); gGL.getTexUnit(0)->activate(); gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 54ec238fde..af078251b3 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -48,156 +48,42 @@ #include "llworld.h" #include "pipeline.h" #include "lldrawpoolwlsky.h" -#include "llwlparammanager.h" -#include "llwaterparammanager.h" +#include "v3colorutil.h" -#undef min -#undef max - -#if LL_WINDOWS -#pragma optimize("", off) -#endif - -static const S32 NUM_TILES_X = 8; -static const S32 NUM_TILES_Y = 4; -static const S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; +#include "llsettingssky.h" +#include "llenvironment.h" -// Heavenly body constants -static const F32 SUN_DISK_RADIUS = 0.5f; -static const F32 MOON_DISK_RADIUS = SUN_DISK_RADIUS * 0.9f; -static const F32 SUN_INTENSITY = 1e5; +#include "lltrace.h" +#include "llfasttimer.h" -// Texture coordinates: -static const LLVector2 TEX00 = LLVector2(0.f, 0.f); -static const LLVector2 TEX01 = LLVector2(0.f, 1.f); -static const LLVector2 TEX10 = LLVector2(1.f, 0.f); -static const LLVector2 TEX11 = LLVector2(1.f, 1.f); - -// Exported globals -LLUUID gSunTextureID = IMG_SUN; -LLUUID gMoonTextureID = IMG_MOON; +#undef min +#undef max -class LLFastLn +namespace { -public: - LLFastLn() - { - mTable[0] = 0; - for( S32 i = 1; i < 257; i++ ) - { - mTable[i] = log((F32)i); - } - } - - F32 ln( F32 x ) - { - const F32 OO_255 = 0.003921568627450980392156862745098f; - const F32 LN_255 = 5.5412635451584261462455391880218f; - - if( x < OO_255 ) - { - return log(x); - } - else - if( x < 1 ) - { - x *= 255.f; - S32 index = llfloor(x); - F32 t = x - index; - F32 low = mTable[index]; - F32 high = mTable[index + 1]; - return low + t * (high - low) - LN_255; - } - else - if( x <= 255 ) - { - S32 index = llfloor(x); - F32 t = x - index; - F32 low = mTable[index]; - F32 high = mTable[index + 1]; - return low + t * (high - low); - } - else - { - return log( x ); - } - } - - F32 pow( F32 x, F32 y ) - { - return (F32)LL_FAST_EXP(y * ln(x)); - } - - -private: - F32 mTable[257]; // index 0 is unused -}; - -static LLFastLn gFastLn; - + const S32 NUM_TILES_X = 8; + const S32 NUM_TILES_Y = 4; + const S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; -// Functions used a lot. + // Heavenly body constants + const F32 SUN_DISK_RADIUS = 0.5f; + const F32 MOON_DISK_RADIUS = SUN_DISK_RADIUS * 0.9f; + const F32 SUN_INTENSITY = 1e5; -inline F32 LLHaze::calcPhase(const F32 cos_theta) const -{ - const F32 g2 = mG * mG; - const F32 den = 1 + g2 - 2 * mG * cos_theta; - return (1 - g2) * gFastLn.pow(den, -1.5); -} + // Texture coordinates: + const LLVector2 TEX00 = LLVector2(0.f, 0.f); + const LLVector2 TEX01 = LLVector2(0.f, 1.f); + const LLVector2 TEX10 = LLVector2(1.f, 0.f); + const LLVector2 TEX11 = LLVector2(1.f, 1.f); -inline void color_pow(LLColor3 &col, const F32 e) -{ - col.mV[0] = gFastLn.pow(col.mV[0], e); - col.mV[1] = gFastLn.pow(col.mV[1], e); - col.mV[2] = gFastLn.pow(col.mV[2], e); -} + const F32 LIGHT_DIRECTION_THRESHOLD = (F32) cosf(DEG_TO_RAD * 1.f); + const F32 COLOR_CHANGE_THRESHOLD = 0.01f; -inline LLColor3 color_norm(const LLColor3 &col) -{ - const F32 m = color_max(col); - if (m > 1.f) - { - return 1.f/m * col; - } - else return col; -} - -inline void color_gamma_correct(LLColor3 &col) -{ - const F32 gamma_inv = 1.f/1.2f; - if (col.mV[0] != 0.f) - { - col.mV[0] = gFastLn.pow(col.mV[0], gamma_inv); - } - if (col.mV[1] != 0.f) - { - col.mV[1] = gFastLn.pow(col.mV[1], gamma_inv); - } - if (col.mV[2] != 0.f) - { - col.mV[2] = gFastLn.pow(col.mV[2], gamma_inv); - } -} + LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATETIMER("VOSky Update Timer Tick"); + LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATEFORCED("VOSky Update Forced"); -static LLColor3 calc_air_sca_sea_level() -{ - static LLColor3 WAVE_LEN(675, 520, 445); - static LLColor3 refr_ind = refr_ind_calc(WAVE_LEN); - static LLColor3 n21 = refr_ind * refr_ind - LLColor3(1, 1, 1); - static LLColor3 n4 = n21 * n21; - static LLColor3 wl2 = WAVE_LEN * WAVE_LEN * 1e-6f; - static LLColor3 wl4 = wl2 * wl2; - static LLColor3 mult_const = fsigma * 2.0f/ 3.0f * 1e24f * (F_PI * F_PI) * n4; - static F32 dens_div_N = F32( ATM_SEA_LEVEL_NDENS / Ndens2); - return dens_div_N * color_div ( mult_const, wl4 ); + F32Seconds UPDATE_EXPRY(2.0f); } - -// static constants. -LLColor3 const LLHaze::sAirScaSeaLevel = calc_air_sca_sea_level(); -F32 const LLHaze::sAirScaIntense = color_intens(LLHaze::sAirScaSeaLevel); -F32 const LLHaze::sAirScaAvg = LLHaze::sAirScaIntense / 3.f; - - /*************************************** SkyTex ***************************************/ @@ -253,6 +139,32 @@ LLSkyTex::~LLSkyTex() mSkyDirs = NULL; } +S32 LLSkyTex::getResolution() +{ + return sResolution; +} + +S32 LLSkyTex::getCurrent() +{ + return sCurrent; +} + +S32 LLSkyTex::stepCurrent() { + sCurrent++; + sCurrent &= 1; + return sCurrent; +} + +S32 LLSkyTex::getNext() +{ + return ((sCurrent+1) & 1); +} + +S32 LLSkyTex::getWhich(const BOOL curr) +{ + int tex = curr ? sCurrent : getNext(); + return tex; +} void LLSkyTex::initEmpty(const S32 tex) { @@ -293,9 +205,6 @@ void LLSkyTex::create(const F32 brightness) createGLImage(sCurrent); } - - - void LLSkyTex::createGLImage(S32 which) { mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); @@ -304,15 +213,176 @@ void LLSkyTex::createGLImage(S32 which) void LLSkyTex::bindTexture(BOOL curr) { - gGL.getTexUnit(0)->bind(mTexture[getWhich(curr)], true); + int tex = getWhich(curr); + gGL.getTexUnit(0)->bind(mTexture[tex], true); +} + +LLImageRaw* LLSkyTex::getImageRaw(BOOL curr) +{ + int tex = getWhich(curr); + return mImageRaw[tex]; } /*************************************** - Sky + LLHeavenBody ***************************************/ F32 LLHeavenBody::sInterpVal = 0; +LLHeavenBody::LLHeavenBody(const F32 rad) +: mDirectionCached(LLVector3(0,0,0)), + mDirection(LLVector3(0,0,0)), + mIntensity(0.f), + mDiskRadius(rad), + mDraw(FALSE), + mHorizonVisibility(1.f), + mVisibility(1.f), + mVisible(FALSE) +{ + mColor.setToBlack(); + mColorCached.setToBlack(); +} + +const LLVector3& LLHeavenBody::getDirection() const +{ + return mDirection; +} + +void LLHeavenBody::setDirection(const LLVector3 &direction) +{ + mDirection = direction; +} + +void LLHeavenBody::setAngularVelocity(const LLVector3 &ang_vel) +{ + mAngularVelocity = ang_vel; +} + +const LLVector3& LLHeavenBody::getAngularVelocity() const +{ + return mAngularVelocity; +} + +const LLVector3& LLHeavenBody::getDirectionCached() const +{ + return mDirectionCached; +} + +void LLHeavenBody::renewDirection() +{ + mDirectionCached = mDirection; +} + +const LLColor3& LLHeavenBody::getColorCached() const +{ + return mColorCached; +} + +void LLHeavenBody::setColorCached(const LLColor3& c) +{ + mColorCached = c; +} + +const LLColor3& LLHeavenBody::getColor() const +{ + return mColor; +} + +void LLHeavenBody::setColor(const LLColor3& c) +{ + mColor = c; +} + +void LLHeavenBody::renewColor() +{ + mColorCached = mColor; +} + +F32 LLHeavenBody::interpVal() +{ + return sInterpVal; +} + +void LLHeavenBody::setInterpVal(const F32 v) +{ + sInterpVal = v; +} + +LLColor3 LLHeavenBody::getInterpColor() const +{ + return sInterpVal * mColor + (1 - sInterpVal) * mColorCached; +} + +const F32& LLHeavenBody::getVisibility() const +{ + return mVisibility; +} + +void LLHeavenBody::setVisibility(const F32 c) +{ + mVisibility = c; +} + +bool LLHeavenBody::isVisible() const +{ + return mVisible; +} + +void LLHeavenBody::setVisible(const bool v) +{ + mVisible = v; +} + +const F32& LLHeavenBody::getIntensity() const +{ + return mIntensity; +} + +void LLHeavenBody::setIntensity(const F32 c) +{ + mIntensity = c; +} + +void LLHeavenBody::setDiskRadius(const F32 radius) +{ + mDiskRadius = radius; +} + +F32 LLHeavenBody::getDiskRadius() const +{ + return mDiskRadius; +} + +void LLHeavenBody::setDraw(const bool draw) +{ + mDraw = draw; +} + +bool LLHeavenBody::getDraw() const +{ + return mDraw; +} + +const LLVector3& LLHeavenBody::corner(const S32 n) const +{ + return mQuadCorner[n]; +} + +LLVector3& LLHeavenBody::corner(const S32 n) +{ + return mQuadCorner[n]; +} + +const LLVector3* LLHeavenBody::corners() const +{ + return mQuadCorner; +} + +/*************************************** + Sky +***************************************/ + + S32 LLVOSky::sResolution = LLSkyTex::getResolution(); S32 LLVOSky::sTileResX = sResolution/NUM_TILES_X; S32 LLVOSky::sTileResY = sResolution/NUM_TILES_Y; @@ -330,32 +400,15 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mWorldScale(1.f), mBumpSunDir(0.f, 0.f, 1.f) { - bool error = false; - /// WL PARAMS - dome_radius = 1.f; - dome_offset_ratio = 0.f; - sunlight_color = LLColor3(); - ambient = LLColor3(); - gamma = 1.f; - lightnorm = LLVector4(); - blue_density = LLColor3(); - blue_horizon = LLColor3(); - haze_density = 0.f; - haze_horizon = 1.f; - density_multiplier = 0.f; - max_y = 0.f; - glow = LLColor3(); - cloud_shadow = 0.f; - cloud_color = LLColor3(); - cloud_scale = 0.f; - cloud_pos_density1 = LLColor3(); - cloud_pos_density2 = LLColor3(); mInitialized = FALSE; mbCanSelect = FALSE; mUpdateTimer.reset(); + mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); + mForceUpdateThrottle.reset(); + for (S32 i = 0; i < 6; i++) { mSkyTex[i].init(); @@ -370,33 +423,13 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mAtmHeight = ATM_HEIGHT; mEarthCenter = LLVector3(mCameraPosAgent.mV[0], mCameraPosAgent.mV[1], -EARTH_RADIUS); - mSunDefaultPosition = LLVector3(LLWLParamManager::getInstance()->mCurParams.getVector("lightnorm", error)); - if (gSavedSettings.getBOOL("SkyOverrideSimSunPosition")) - { - initSunDirection(mSunDefaultPosition, LLVector3(0, 0, 0)); - } - mAmbientScale = gSavedSettings.getF32("SkyAmbientScale"); - mNightColorShift = gSavedSettings.getColor3("SkyNightColorShift"); - mFogColor.mV[VRED] = mFogColor.mV[VGREEN] = mFogColor.mV[VBLUE] = 0.5f; - mFogColor.mV[VALPHA] = 0.0f; - mFogRatio = 1.2f; - mSun.setIntensity(SUN_INTENSITY); mMoon.setIntensity(0.1f * SUN_INTENSITY); - mSunTexturep = LLViewerTextureManager::getFetchedTexture(gSunTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - mSunTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - mMoonTexturep = LLViewerTextureManager::getFetchedTexture(gMoonTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - mMoonTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - mBloomTexturep = LLViewerTextureManager::getFetchedTexture(IMG_BLOOM1); - mBloomTexturep->setNoDelete() ; - mBloomTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - mHeavenlyBodyUpdated = FALSE ; mDrawRefl = 0; - mHazeConcentration = 0.f; - mInterpVal = 0.f; + mInterpVal = 0.f; } @@ -410,11 +443,32 @@ LLVOSky::~LLVOSky() void LLVOSky::init() { - const F32 haze_int = color_intens(mHaze.calcSigSca(0)); - mHazeConcentration = haze_int / - (color_intens(LLHaze::calcAirSca(0)) + haze_int); - - calcAtmospherics(); + llassert(!mInitialized); + + // Update sky at least once to get correct initial sun/moon directions and lighting calcs performed + LLEnvironment::instance().getCurrentSky()->update(); + + updateDirections(); + + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + // invariants across whole sky tex process... + m_atmosphericsVars.blue_density = psky->getBlueDensity(); + m_atmosphericsVars.blue_horizon = psky->getBlueHorizon(); + m_atmosphericsVars.haze_density = psky->getHazeDensity(); + m_atmosphericsVars.haze_horizon = psky->getHazeHorizon(); + m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); + m_atmosphericsVars.max_y = psky->getMaxY(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); + m_atmosphericsVars.sunlight = psky->getSunlightColor(); + m_atmosphericsVars.ambient = psky->getAmbientColor(); + m_atmosphericsVars.glow = psky->getGlow(); + m_atmosphericsVars.cloud_shadow = psky->getCloudShadow(); + m_atmosphericsVars.dome_radius = psky->getDomeRadius(); + m_atmosphericsVars.dome_offset = psky->getDomeOffset(); + m_atmosphericsVars.light_atten = psky->getLightAttenuation(m_atmosphericsVars.max_y); + m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(); + m_atmosphericsVars.gamma = psky->getGamma(); // Initialize the cached normalized direction vectors for (S32 side = 0; side < 6; ++side) @@ -422,7 +476,7 @@ void LLVOSky::init() for (S32 tile = 0; tile < NUM_TILES; ++tile) { initSkyTextureDirs(side, tile); - createSkyTexture(side, tile); + createSkyTexture(m_atmosphericsVars, side, tile, false); } } @@ -433,9 +487,107 @@ void LLVOSky::init() } initCubeMap(); + mInitialized = true; mHeavenlyBodyUpdated = FALSE ; + + mRainbowMap = LLViewerTextureManager::getFetchedTexture(psky->getRainbowTextureId(), FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + mHaloMap = LLViewerTextureManager::getFetchedTexture(psky->getHaloTextureId(), FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); +} + + +void LLVOSky::calc() +{ + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + // invariants across whole sky tex process... + m_atmosphericsVars.blue_density = psky->getBlueDensity(); + m_atmosphericsVars.blue_horizon = psky->getBlueHorizon(); + m_atmosphericsVars.haze_density = psky->getHazeDensity(); + m_atmosphericsVars.haze_horizon = psky->getHazeHorizon(); + m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); + m_atmosphericsVars.max_y = psky->getMaxY(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); + m_atmosphericsVars.sunlight = psky->getSunlightColor(); + m_atmosphericsVars.ambient = psky->getAmbientColor(); + m_atmosphericsVars.glow = psky->getGlow(); + m_atmosphericsVars.cloud_shadow = psky->getCloudShadow(); + m_atmosphericsVars.dome_radius = psky->getDomeRadius(); + m_atmosphericsVars.dome_offset = psky->getDomeOffset(); + m_atmosphericsVars.light_atten = psky->getLightAttenuation(m_atmosphericsVars.max_y); + m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(); + m_atmosphericsVars.gamma = psky->getGamma(); + + LLColor3 vary_HazeColor; + LLColor3 vary_SunlightColor; + LLColor3 vary_AmbientColor; + { + // Initialize temp variables + LLColor3 sunlight = m_atmosphericsVars.sunlight; + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + LLColor3 light_atten = + (m_atmosphericsVars.blue_density * 1.0 + smear(m_atmosphericsVars.haze_density * 0.25f)) * (m_atmosphericsVars.density_multiplier * m_atmosphericsVars.max_y); + + // Calculate relative weights + LLColor3 temp2(0.f, 0.f, 0.f); + LLColor3 temp1 = m_atmosphericsVars.blue_density + smear(m_atmosphericsVars.haze_density); + LLColor3 blue_weight = componentDiv(m_atmosphericsVars.blue_density, temp1); + LLColor3 haze_weight = componentDiv(smear(m_atmosphericsVars.haze_density), temp1); + + // Compute sunlight from P & lightnorm (for long rays like sky) + /// USE only lightnorm. + // temp2[1] = llmax(0.f, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); + F32 lighty = getSun().getDirection().mV[2]; + temp2.mV[1] = llmax(0.f, lighty); + if(temp2.mV[1] > 0.f) + { + temp2.mV[1] = 1.f / temp2.mV[1]; + } + componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + + // Distance + temp2.mV[2] = m_atmosphericsVars.density_multiplier; + + // Transparency (-> temp1) + temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); + + // vary_AtmosAttenuation = temp1; + + //increase ambient when there are more clouds + LLColor3 tmpAmbient = m_atmosphericsVars.ambient + (smear(1.f) - m_atmosphericsVars.ambient) * m_atmosphericsVars.cloud_shadow * 0.5f; + + //haze color + vary_HazeColor = + (m_atmosphericsVars.blue_horizon * blue_weight * (sunlight * (1.f - m_atmosphericsVars.cloud_shadow) + tmpAmbient) + + componentMult(m_atmosphericsVars.haze_horizon * haze_weight, sunlight * (1.f - m_atmosphericsVars.cloud_shadow) * temp2.mV[0] + tmpAmbient) + ); + + //brightness of surface both sunlight and ambient + vary_SunlightColor = componentMult(sunlight, temp1) * 1.f; + vary_SunlightColor.clamp(); + vary_SunlightColor = smear(1.0f) - vary_SunlightColor; + vary_SunlightColor = componentPow(vary_SunlightColor, m_atmosphericsVars.gamma); + vary_SunlightColor = smear(1.0f) - vary_SunlightColor; + vary_AmbientColor = componentMult(tmpAmbient, temp1) * 0.5; + vary_AmbientColor.clamp(); + vary_AmbientColor = smear(1.0f) - vary_AmbientColor; + vary_AmbientColor = componentPow(vary_AmbientColor, m_atmosphericsVars.gamma); + vary_AmbientColor = smear(1.0f) - vary_AmbientColor; + + componentMultBy(vary_HazeColor, LLColor3(1.f, 1.f, 1.f) - temp1); + + } + + mSun.setColor(vary_SunlightColor); + mMoon.setColor(LLColor3(1.0f, 1.0f, 1.0f)); + + mSun.renewDirection(); + mSun.renewColor(); + mMoon.renewDirection(); + mMoon.renewColor(); } void LLVOSky::initCubeMap() @@ -478,15 +630,16 @@ void LLVOSky::restoreGL() { mSkyTex[i].restoreGL(); } - mSunTexturep = LLViewerTextureManager::getFetchedTexture(gSunTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - mSunTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - mMoonTexturep = LLViewerTextureManager::getFetchedTexture(gMoonTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - mMoonTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - mBloomTexturep = LLViewerTextureManager::getFetchedTexture(IMG_BLOOM1); - mBloomTexturep->setNoDelete() ; - mBloomTexturep->setAddressMode(LLTexUnit::TAM_CLAMP); - calcAtmospherics(); + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + if (psky) + { + setSunTextures(psky->getSunTextureId(), psky->getNextSunTextureId()); + setMoonTextures(psky->getMoonTextureId(), psky->getNextMoonTextureId()); + } + + updateDirections(); if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) @@ -502,10 +655,11 @@ void LLVOSky::restoreGL() if(cube_map) { cube_map->init(images); - mForceUpdate = TRUE; } } + mForceUpdate = TRUE; + if (mDrawable) { gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); @@ -545,7 +699,7 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) } } -void LLVOSky::createSkyTexture(const S32 side, const S32 tile) +void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, bool skip_sky_tex) { S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; @@ -554,495 +708,55 @@ void LLVOSky::createSkyTexture(const S32 side, const S32 tile) S32 tile_y_pos = tile_y * sTileResY; S32 x, y; + if (!skip_sky_tex) + { + for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) + { + for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) + { + mSkyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, mSkyTex[side].getDir(x, y)), x, y); + } + } + } + for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) { for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) { - mSkyTex[side].setPixel(calcSkyColorInDir(mSkyTex[side].getDir(x, y)), x, y); - mShinyTex[side].setPixel(calcSkyColorInDir(mSkyTex[side].getDir(x, y), true), x, y); + mShinyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, mSkyTex[side].getDir(x, y), true), x, y); } } } -static inline LLColor3 componentDiv(LLColor3 const &left, LLColor3 const & right) +void LLVOSky::updateDirections(void) { - return LLColor3(left.mV[0]/right.mV[0], - left.mV[1]/right.mV[1], - left.mV[2]/right.mV[2]); -} + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + mLastSunLightingDirection = mSun.getDirection(); + mLastMoonLightingDirection = mMoon.getDirection(); -static inline LLColor3 componentMult(LLColor3 const &left, LLColor3 const & right) -{ - return LLColor3(left.mV[0]*right.mV[0], - left.mV[1]*right.mV[1], - left.mV[2]*right.mV[2]); -} + mSun.setDirection(psky->getSunDirection()); + mMoon.setDirection(psky->getMoonDirection()); - -static inline LLColor3 componentExp(LLColor3 const &v) -{ - return LLColor3(exp(v.mV[0]), - exp(v.mV[1]), - exp(v.mV[2])); -} - -static inline LLColor3 componentPow(LLColor3 const &v, F32 exponent) -{ - return LLColor3(pow(v.mV[0], exponent), - pow(v.mV[1], exponent), - pow(v.mV[2], exponent)); -} - -static inline LLColor3 componentSaturate(LLColor3 const &v) -{ - return LLColor3(std::max(std::min(v.mV[0], 1.f), 0.f), - std::max(std::min(v.mV[1], 1.f), 0.f), - std::max(std::min(v.mV[2], 1.f), 0.f)); -} - - -static inline LLColor3 componentSqrt(LLColor3 const &v) -{ - return LLColor3(sqrt(v.mV[0]), - sqrt(v.mV[1]), - sqrt(v.mV[2])); -} - -static inline void componentMultBy(LLColor3 & left, LLColor3 const & right) -{ - left.mV[0] *= right.mV[0]; - left.mV[1] *= right.mV[1]; - left.mV[2] *= right.mV[2]; -} - -static inline LLColor3 colorMix(LLColor3 const & left, LLColor3 const & right, F32 amount) -{ - return (left + ((right - left) * amount)); -} - -static inline LLColor3 smear(F32 val) -{ - return LLColor3(val, val, val); -} - -void LLVOSky::initAtmospherics(void) -{ - bool error; - - // uniform parameters for convenience - dome_radius = LLWLParamManager::getInstance()->getDomeRadius(); - dome_offset_ratio = LLWLParamManager::getInstance()->getDomeOffset(); - sunlight_color = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("sunlight_color", error)); - ambient = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("ambient", error)); - //lightnorm = LLWLParamManager::getInstance()->mCurParams.getVector("lightnorm", error); - gamma = LLWLParamManager::getInstance()->mCurParams.getFloat("gamma", error); - blue_density = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("blue_density", error)); - blue_horizon = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("blue_horizon", error)); - haze_density = LLWLParamManager::getInstance()->mCurParams.getFloat("haze_density", error); - haze_horizon = LLWLParamManager::getInstance()->mCurParams.getFloat("haze_horizon", error); - density_multiplier = LLWLParamManager::getInstance()->mCurParams.getFloat("density_multiplier", error); - max_y = LLWLParamManager::getInstance()->mCurParams.getFloat("max_y", error); - glow = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("glow", error)); - cloud_shadow = LLWLParamManager::getInstance()->mCurParams.getFloat("cloud_shadow", error); - cloud_color = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("cloud_color", error)); - cloud_scale = LLWLParamManager::getInstance()->mCurParams.getFloat("cloud_scale", error); - cloud_pos_density1 = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("cloud_pos_density1", error)); - cloud_pos_density2 = LLColor3(LLWLParamManager::getInstance()->mCurParams.getVector("cloud_pos_density2", error)); - - // light norm is different. We need the sun's direction, not the light direction - // which could be from the moon. And we need to clamp it - // just like for the gpu - LLVector3 sunDir = gSky.getSunDirection(); - - // CFR_TO_OGL - lightnorm = LLVector4(sunDir.mV[1], sunDir.mV[2], sunDir.mV[0], 0); - unclamped_lightnorm = lightnorm; - if(lightnorm.mV[1] < -0.1f) - { - lightnorm.mV[1] = -0.1f; - } - -} - -LLColor4 LLVOSky::calcSkyColorInDir(const LLVector3 &dir, bool isShiny) -{ - F32 saturation = 0.3f; - if (dir.mV[VZ] < -0.02f) - { - LLColor4 col = LLColor4(llmax(mFogColor[0],0.2f), llmax(mFogColor[1],0.2f), llmax(mFogColor[2],0.22f),0.f); - if (isShiny) - { - LLColor3 desat_fog = LLColor3(mFogColor); - F32 brightness = desat_fog.brightness(); - // So that shiny somewhat shows up at night. - if (brightness < 0.15f) - { - brightness = 0.15f; - desat_fog = smear(0.15f); - } - LLColor3 greyscale = smear(brightness); - desat_fog = desat_fog * saturation + greyscale * (1.0f - saturation); - if (!gPipeline.canUseWindLightShaders()) - { - col = LLColor4(desat_fog, 0.f); - } - else - { - col = LLColor4(desat_fog * 0.5f, 0.f); - } - } - float x = 1.0f-fabsf(-0.1f-dir.mV[VZ]); - x *= x; - col.mV[0] *= x*x; - col.mV[1] *= powf(x, 2.5f); - col.mV[2] *= x*x*x; - return col; - } - - // undo OGL_TO_CFR_ROTATION and negate vertical direction. - LLVector3 Pn = LLVector3(-dir[1] , -dir[2], -dir[0]); - - LLColor3 vary_HazeColor(0,0,0); - LLColor3 vary_CloudColorSun(0,0,0); - LLColor3 vary_CloudColorAmbient(0,0,0); - F32 vary_CloudDensity(0); - LLVector2 vary_HorizontalProjection[2]; - vary_HorizontalProjection[0] = LLVector2(0,0); - vary_HorizontalProjection[1] = LLVector2(0,0); - - calcSkyColorWLVert(Pn, vary_HazeColor, vary_CloudColorSun, vary_CloudColorAmbient, - vary_CloudDensity, vary_HorizontalProjection); - - LLColor3 sky_color = calcSkyColorWLFrag(Pn, vary_HazeColor, vary_CloudColorSun, vary_CloudColorAmbient, - vary_CloudDensity, vary_HorizontalProjection); - if (isShiny) - { - F32 brightness = sky_color.brightness(); - LLColor3 greyscale = smear(brightness); - sky_color = sky_color * saturation + greyscale * (1.0f - saturation); - sky_color *= (0.5f + 0.5f * brightness); - } - return LLColor4(sky_color, 0.0f); -} - -// turn on floating point precision -// in vs2003 for this function. Otherwise -// sky is aliased looking 7:10 - 8:50 -#if LL_MSVC && __MSVC_VER__ < 8 -#pragma optimize("p", on) -#endif - -void LLVOSky::calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]) -{ - // project the direction ray onto the sky dome. - F32 phi = acos(Pn[1]); - F32 sinA = sin(F_PI - phi); - if (fabsf(sinA) < 0.01f) - { //avoid division by zero - sinA = 0.01f; - } - - F32 Plen = dome_radius * sin(F_PI + phi + asin(dome_offset_ratio * sinA)) / sinA; - - Pn *= Plen; - - vary_HorizontalProjection[0] = LLVector2(Pn[0], Pn[2]); - vary_HorizontalProjection[0] /= - 2.f * Plen; - - // Set altitude - if (Pn[1] > 0.f) - { - Pn *= (max_y / Pn[1]); - } - else - { - Pn *= (-32000.f / Pn[1]); - } - - Plen = Pn.length(); - Pn /= Plen; - - // Initialize temp variables - LLColor3 sunlight = sunlight_color; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - LLColor3 light_atten = - (blue_density * 1.0 + smear(haze_density * 0.25f)) * (density_multiplier * max_y); - - // Calculate relative weights - LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = blue_density + smear(haze_density); - LLColor3 blue_weight = componentDiv(blue_density, temp1); - LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Distance - temp2.mV[2] = Plen * density_multiplier; - - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); - - - // Compute haze glow - temp2.mV[0] = Pn * LLVector3(lightnorm); - - temp2.mV[0] = 1.f - temp2.mV[0]; - // temp2.x is 0 at the sun and increases away from sun - temp2.mV[0] = llmax(temp2.mV[0], .001f); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.mV[0] *= glow.mV[0]; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.mV[0] = pow(temp2.mV[0], glow.mV[2]); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.mV[0] += .25f; - - - // Haze color above cloud - vary_HazeColor = (blue_horizon * blue_weight * (sunlight + ambient) - + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + ambient) - ); - - // Increase ambient when there are more clouds - LLColor3 tmpAmbient = ambient + (LLColor3::white - ambient) * cloud_shadow * 0.5f; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1.f - cloud_shadow); - - // Haze color below cloud - LLColor3 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) - + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + tmpAmbient) - ); - - // Final atmosphere additive - componentMultBy(vary_HazeColor, LLColor3::white - temp1); - - sunlight = sunlight_color; - temp2.mV[1] = llmax(0.f, lightnorm[1] * 2.f); - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Attenuate cloud color by atmosphere - temp1 = componentSqrt(temp1); //less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - vary_HazeColor += - componentMult(additiveColorBelowCloud - vary_HazeColor, LLColor3::white - componentSqrt(temp1)); - - if (Pn[1] < 0.f) - { - // Eric's original: - // LLColor3 dark_brown(0.143f, 0.129f, 0.114f); - LLColor3 dark_brown(0.082f, 0.076f, 0.066f); - LLColor3 brown(0.430f, 0.386f, 0.322f); - LLColor3 sky_lighting = sunlight + ambient; - F32 haze_brightness = vary_HazeColor.brightness(); - - if (Pn[1] < -0.05f) - { - vary_HazeColor = colorMix(dark_brown, brown, -Pn[1] * 0.9f) * sky_lighting * haze_brightness; - } - - if (Pn[1] > -0.1f) - { - vary_HazeColor = colorMix(LLColor3::white * haze_brightness, vary_HazeColor, fabs((Pn[1] + 0.05f) * -20.f)); - } - } -} - -#if LL_MSVC && __MSVC_VER__ < 8 -#pragma optimize("p", off) -#endif - -LLColor3 LLVOSky::calcSkyColorWLFrag(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLColor3 & vary_CloudColorSun, - LLColor3 & vary_CloudColorAmbient, F32 & vary_CloudDensity, - LLVector2 vary_HorizontalProjection[2]) -{ - LLColor3 res; - - LLColor3 color0 = vary_HazeColor; - - if (!gPipeline.canUseWindLightShaders()) - { - LLColor3 color1 = color0 * 2.0f; - color1 = smear(1.f) - componentSaturate(color1); - componentPow(color1, gamma); - res = smear(1.f) - color1; - } - else - { - res = color0; - } - -# ifndef LL_RELEASE_FOR_DOWNLOAD - - LLColor3 color2 = 2.f * color0; - - LLColor3 color3 = LLColor3(1.f, 1.f, 1.f) - componentSaturate(color2); - componentPow(color3, gamma); - color3 = LLColor3(1.f, 1.f, 1.f) - color3; - - static enum { - OUT_DEFAULT = 0, - OUT_SKY_BLUE = 1, - OUT_RED = 2, - OUT_PN = 3, - OUT_HAZE = 4, - } debugOut = OUT_DEFAULT; - - switch(debugOut) - { - case OUT_DEFAULT: - break; - case OUT_SKY_BLUE: - res = LLColor3(0.4f, 0.4f, 0.9f); - break; - case OUT_RED: - res = LLColor3(1.f, 0.f, 0.f); - break; - case OUT_PN: - res = LLColor3(Pn[0], Pn[1], Pn[2]); - break; - case OUT_HAZE: - res = vary_HazeColor; - break; - } -# endif // LL_RELEASE_FOR_DOWNLOAD - return res; -} - -LLColor3 LLVOSky::createDiffuseFromWL(LLColor3 diffuse, LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient) -{ - return componentMult(diffuse, sundiffuse) * 4.0f + - componentMult(ambient, sundiffuse) * 2.0f + sunambient; -} - -LLColor3 LLVOSky::createAmbientFromWL(LLColor3 ambient, LLColor3 sundiffuse, LLColor3 sunambient) -{ - return (componentMult(ambient, sundiffuse) + sunambient) * 0.8f; -} - - -void LLVOSky::calcAtmospherics(void) -{ - initAtmospherics(); - - LLColor3 vary_HazeColor; - LLColor3 vary_SunlightColor; - LLColor3 vary_AmbientColor; - { - // Initialize temp variables - LLColor3 sunlight = sunlight_color; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - LLColor3 light_atten = - (blue_density * 1.0 + smear(haze_density * 0.25f)) * (density_multiplier * max_y); - - // Calculate relative weights - LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = blue_density + smear(haze_density); - LLColor3 blue_weight = componentDiv(blue_density, temp1); - LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); - - // Compute sunlight from P & lightnorm (for long rays like sky) - /// USE only lightnorm. - // temp2[1] = llmax(0.f, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - - // and vary_sunlight will work properly with moon light - F32 lighty = unclamped_lightnorm[1]; - if(lighty < LLSky::NIGHTTIME_ELEVATION_COS) - { - lighty = -lighty; - } - - temp2.mV[1] = llmax(0.f, lighty); - if(temp2.mV[1] > 0.f) - { - temp2.mV[1] = 1.f / temp2.mV[1]; - } - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Distance - temp2.mV[2] = density_multiplier; - - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); - - // vary_AtmosAttenuation = temp1; - - //increase ambient when there are more clouds - LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5f; - - //haze color - vary_HazeColor = - (blue_horizon * blue_weight * (sunlight*(1.f - cloud_shadow) + tmpAmbient) - + componentMult(haze_horizon * haze_weight, sunlight*(1.f - cloud_shadow) * temp2.mV[0] + tmpAmbient) - ); - - //brightness of surface both sunlight and ambient - vary_SunlightColor = componentMult(sunlight, temp1) * 1.f; - vary_SunlightColor.clamp(); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_SunlightColor = componentPow(vary_SunlightColor, gamma); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_AmbientColor = componentMult(tmpAmbient, temp1) * 0.5; - vary_AmbientColor.clamp(); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; - vary_AmbientColor = componentPow(vary_AmbientColor, gamma); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; - - componentMultBy(vary_HazeColor, LLColor3(1.f, 1.f, 1.f) - temp1); - - } - - mSun.setColor(vary_SunlightColor); - mMoon.setColor(LLColor3(1.0f, 1.0f, 1.0f)); + mSun.setColor(psky->getSunlightColor()); + mMoon.setColor(psky->getMoonDiffuse()); mSun.renewDirection(); mSun.renewColor(); mMoon.renewDirection(); mMoon.renewColor(); - - float dp = getToSunLast() * LLVector3(0,0,1.f); - if (dp < 0) - { - dp = 0; - } - - // Since WL scales everything by 2, there should always be at least a 2:1 brightness ratio - // between sunlight and point lights in windlight to normalize point lights. - F32 sun_dynamic_range = llmax(gSavedSettings.getF32("RenderSunDynamicRange"), 0.0001f); - LLWLParamManager::getInstance()->mSceneLightStrength = 2.0f * (1.0f + sun_dynamic_range * dp); - - mSunDiffuse = vary_SunlightColor; - mSunAmbient = vary_AmbientColor; - mMoonDiffuse = vary_SunlightColor; - mMoonAmbient = vary_AmbientColor; - - mTotalAmbient = vary_AmbientColor; - mTotalAmbient.setAlpha(1); - - mFadeColor = mTotalAmbient + (mSunDiffuse + mMoonDiffuse) * 0.5f; - mFadeColor.setAlpha(0); } void LLVOSky::idleUpdate(LLAgent &agent, const F64 &time) { } -BOOL LLVOSky::updateSky() -{ +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; @@ -1062,11 +776,13 @@ BOOL LLVOSky::updateSky() const S32 total_no_tiles = 6 * NUM_TILES; const S32 cycle_frame_no = total_no_tiles + 1; - if (mUpdateTimer.getElapsedTimeF32() > 0.001f) + if (mUpdateTimer.getElapsedTimeF32() > 0.025f) { - mUpdateTimer.reset(); + mUpdateTimer.reset(); const S32 frame = next_frame; + mForceUpdate = mForceUpdate || (total_no_tiles == frame); + ++next_frame; next_frame = next_frame % cycle_frame_no; @@ -1074,117 +790,150 @@ BOOL LLVOSky::updateSky() // sInterpVal = (F32)next_frame / cycle_frame_no; LLSkyTex::setInterpVal( mInterpVal ); LLHeavenBody::setInterpVal( mInterpVal ); - calcAtmospherics(); + updateDirections(); - if (mForceUpdate || total_no_tiles == frame) + 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; + + bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + + calc(); + + if (mForceUpdate && mForceUpdateThrottle.hasExpired()) { + LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); + + mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); + LLSkyTex::stepCurrent(); - - const static F32 LIGHT_DIRECTION_THRESHOLD = (F32) cos(DEG_TO_RAD * 1.f); - const static F32 COLOR_CHANGE_THRESHOLD = 0.01f; - - LLVector3 direction = mSun.getDirection(); - direction.normalize(); - const F32 dot_lighting = direction * mLastLightingDirection; - - LLColor3 delta_color; - delta_color.setVec(mLastTotalAmbient.mV[0] - mTotalAmbient.mV[0], - mLastTotalAmbient.mV[1] - mTotalAmbient.mV[1], - mLastTotalAmbient.mV[2] - mTotalAmbient.mV[2]); - - if ( mForceUpdate - || (((dot_lighting < LIGHT_DIRECTION_THRESHOLD) - || (delta_color.length() > COLOR_CHANGE_THRESHOLD) - || !mInitialized) - && !direction.isExactlyZero())) + + if (!direction.isExactlyZero()) { - mLastLightingDirection = direction; - mLastTotalAmbient = mTotalAmbient; + mLastTotalAmbient = total_ambient; mInitialized = TRUE; if (mCubeMap) { - if (mForceUpdate) - { - updateFog(LLViewerCamera::getInstance()->getFar()); - for (int side = 0; side < 6; side++) - { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(side, tile); - } - } - - calcAtmospherics(); + updateFog(LLViewerCamera::getInstance()->getFar()); - for (int side = 0; side < 6; side++) + for (int side = 0; side < 6; side++) + { + for (int tile = 0; tile < NUM_TILES; tile++) { - LLImageRaw* raw1 = mSkyTex[side].getImageRaw(TRUE); - LLImageRaw* raw2 = mSkyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mSkyTex[side].createGLImage(mSkyTex[side].getWhich(FALSE)); - - raw1 = mShinyTex[side].getImageRaw(TRUE); - raw2 = mShinyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mShinyTex[side].createGLImage(mShinyTex[side].getWhich(FALSE)); + createSkyTexture(m_atmosphericsVars, side, tile, is_alm_wl_sky); } - next_frame = 0; } - } - } - /// *TODO really, sky texture and env map should be shared on a single texture - /// I'll let Brad take this at some point + int tex = mSkyTex[0].getWhich(TRUE); - // update the sky texture - for (S32 i = 0; i < 6; ++i) - { - mSkyTex[i].create(1.0f); - mShinyTex[i].create(1.0f); - } - - // update the environment map - if (mCubeMap) - { - std::vector > images; - images.reserve(6); - for (S32 side = 0; side < 6; side++) - { - images.push_back(mShinyTex[side].getImageRaw(TRUE)); + for (int side = 0; side < 6; 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); + } + + 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) + { + for (S32 i = 0; i < 6; ++i) + { + mSkyTex[i].create(1.0f); + } + } + + for (S32 i = 0; i < 6; ++i) + { + mShinyTex[i].create(1.0f); + } + + // update the environment map + if (mCubeMap) + { + std::vector > 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(); + } } - mCubeMap->init(images); - gGL.getTexUnit(0)->disable(); - } + } gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - // *TODO: decide whether we need to update the stars vertex buffer in LLVOWLSky -Brad. - //gPipeline.markRebuild(gSky.mVOWLSkyp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - mForceUpdate = FALSE; } - else - { - const S32 side = frame / NUM_TILES; - const S32 tile = frame % NUM_TILES; - createSkyTexture(side, tile); - } } if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) { gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); } + return TRUE; } void LLVOSky::updateTextures() { - if (mSunTexturep) + if (mSunTexturep[0]) { - mSunTexturep->addTextureStats( (F32)MAX_IMAGE_AREA ); - mMoonTexturep->addTextureStats( (F32)MAX_IMAGE_AREA ); - mBloomTexturep->addTextureStats( (F32)MAX_IMAGE_AREA ); + mSunTexturep[0]->addTextureStats( (F32)MAX_IMAGE_AREA ); + } + + if (mSunTexturep[1]) + { + mSunTexturep[1]->addTextureStats( (F32)MAX_IMAGE_AREA ); + } + + if (mMoonTexturep[0]) + { + mMoonTexturep[0]->addTextureStats( (F32)MAX_IMAGE_AREA ); + } + + if (mMoonTexturep[1]) + { + mMoonTexturep[1]->addTextureStats( (F32)MAX_IMAGE_AREA ); + } + + if (mBloomTexturep[0]) + { + mBloomTexturep[0]->addTextureStats( (F32)MAX_IMAGE_AREA ); + } + + if (mBloomTexturep[1]) + { + mBloomTexturep[1]->addTextureStats( (F32)MAX_IMAGE_AREA ); } } @@ -1202,60 +951,121 @@ LLDrawable *LLVOSky::createDrawable(LLPipeline *pipeline) mFace[FACE_SIDE0 + i] = mDrawable->addFace(poolp, NULL); } - mFace[FACE_SUN] = mDrawable->addFace(poolp, mSunTexturep); - mFace[FACE_MOON] = mDrawable->addFace(poolp, mMoonTexturep); - mFace[FACE_BLOOM] = mDrawable->addFace(poolp, mBloomTexturep); + mFace[FACE_SUN] = mDrawable->addFace(poolp, nullptr); + mFace[FACE_MOON] = mDrawable->addFace(poolp, nullptr); + mFace[FACE_BLOOM] = mDrawable->addFace(poolp, nullptr); return mDrawable; } -//by bao -//fake vertex buffer updating -//to guarantee at least updating one VBO buffer every frame -//to walk around the bug caused by ATI card --> DEV-3855 -// -void LLVOSky::createDummyVertexBuffer() +void LLVOSky::setSunScale(F32 sun_scale) { - if(!mFace[FACE_DUMMY]) - { - LLDrawPoolSky *poolp = (LLDrawPoolSky*) gPipeline.getPool(LLDrawPool::POOL_SKY); - mFace[FACE_DUMMY] = mDrawable->addFace(poolp, NULL); - } + mSunScale = sun_scale; +} - if(!mFace[FACE_DUMMY]->getVertexBuffer()) - { - LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolSky::VERTEX_DATA_MASK, GL_DYNAMIC_DRAW_ARB); - buff->allocateBuffer(1, 1, TRUE); - mFace[FACE_DUMMY]->setVertexBuffer(buff); - } +void LLVOSky::setMoonScale(F32 moon_scale) +{ + mMoonScale = moon_scale; } -static LLTrace::BlockTimerStatHandle FTM_RENDER_FAKE_VBO_UPDATE("Fake VBO Update"); +void LLVOSky::setSunTextures(const LLUUID& sun_texture, const LLUUID& sun_texture_next) +{ + // We test the UUIDs here because we explicitly do not want the default image returned by getFetchedTexture in that case... + mSunTexturep[0] = sun_texture.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(sun_texture, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + mSunTexturep[1] = sun_texture_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(sun_texture_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + + if (mFace[FACE_SUN]) + { + if (mSunTexturep[0]) + { + mSunTexturep[0]->setAddressMode(LLTexUnit::TAM_CLAMP); + } + + LLViewerTexture* current_tex0 = mFace[FACE_SUN]->getTexture(LLRender::DIFFUSE_MAP); + LLViewerTexture* current_tex1 = mFace[FACE_SUN]->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP); + + if (current_tex0 && (mSunTexturep[0] != current_tex0) && current_tex0->isViewerMediaTexture()) + { + static_cast(current_tex0)->removeMediaFromFace(mFace[FACE_SUN]); + } + + if (current_tex1 && (mSunTexturep[1] != current_tex1) && current_tex1->isViewerMediaTexture()) + { + static_cast(current_tex1)->removeMediaFromFace(mFace[FACE_SUN]); + } + + mFace[FACE_SUN]->setTexture(LLRender::DIFFUSE_MAP, mSunTexturep[0]); + + if (mSunTexturep[1]) + { + mSunTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); + } + mFace[FACE_SUN]->setTexture(LLRender::ALTERNATE_DIFFUSE_MAP, mSunTexturep[1]); + } +} -void LLVOSky::updateDummyVertexBuffer() -{ - if(!LLVertexBuffer::sEnableVBOs) - return ; +void LLVOSky::setMoonTextures(const LLUUID& moon_texture, const LLUUID& moon_texture_next) +{ + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + mMoonTexturep[0] = moon_texture.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(moon_texture, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + mMoonTexturep[1] = moon_texture_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(moon_texture_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + + if (mFace[FACE_MOON]) + { + if (mMoonTexturep[0]) + { + mMoonTexturep[0]->setAddressMode(LLTexUnit::TAM_CLAMP); + } + mFace[FACE_MOON]->setTexture(LLRender::DIFFUSE_MAP, mMoonTexturep[0]); + + if (mMoonTexturep[1]) + { + mMoonTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); + mFace[FACE_MOON]->setTexture(LLRender::ALTERNATE_DIFFUSE_MAP, mMoonTexturep[1]); + } + } +} - if(mHeavenlyBodyUpdated) - { - mHeavenlyBodyUpdated = FALSE ; - return ; - } +void LLVOSky::setCloudNoiseTextures(const LLUUID& cloud_noise_texture, const LLUUID& cloud_noise_texture_next) +{ + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + mCloudNoiseTexturep[0] = cloud_noise_texture.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(cloud_noise_texture, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + mCloudNoiseTexturep[1] = cloud_noise_texture_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(cloud_noise_texture_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + + if (mCloudNoiseTexturep[0]) + { + mCloudNoiseTexturep[0]->setAddressMode(LLTexUnit::TAM_WRAP); + } + + if (mCloudNoiseTexturep[1]) + { + mCloudNoiseTexturep[1]->setAddressMode(LLTexUnit::TAM_WRAP); + } +} + +void LLVOSky::setBloomTextures(const LLUUID& bloom_texture, const LLUUID& bloom_texture_next) +{ + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + + LLUUID bloom_tex = bloom_texture.isNull() ? psky->GetDefaultBloomTextureId() : bloom_texture; + LLUUID bloom_tex_next = bloom_texture_next.isNull() ? (bloom_texture.isNull() ? psky->GetDefaultBloomTextureId() : bloom_texture) : bloom_texture_next; - LL_RECORD_BLOCK_TIME(FTM_RENDER_FAKE_VBO_UPDATE) ; + mBloomTexturep[0] = bloom_tex.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(bloom_tex, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + mBloomTexturep[1] = bloom_tex_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(bloom_tex_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); - if(!mFace[FACE_DUMMY] || !mFace[FACE_DUMMY]->getVertexBuffer()) - createDummyVertexBuffer() ; + if (mBloomTexturep[0]) + { + mBloomTexturep[0]->setAddressMode(LLTexUnit::TAM_CLAMP); + } - LLStrider vertices ; - mFace[FACE_DUMMY]->getVertexBuffer()->getVertexStrider(vertices, 0); - *vertices = mCameraPosAgent ; - mFace[FACE_DUMMY]->getVertexBuffer()->flush(); + if (mBloomTexturep[1]) + { + mBloomTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); + } } -//---------------------------------- -//end of fake vertex buffer updating -//---------------------------------- + static LLTrace::BlockTimerStatHandle FTM_GEO_SKY("Sky Geometry"); BOOL LLVOSky::updateGeometry(LLDrawable *drawable) @@ -1264,13 +1074,14 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable) if (mFace[FACE_REFLECTION] == NULL) { LLDrawPoolWater *poolp = (LLDrawPoolWater*) gPipeline.getPool(LLDrawPool::POOL_WATER); - if (gPipeline.getPool(LLDrawPool::POOL_WATER)->getVertexShaderLevel() != 0) + if (gPipeline.getPool(LLDrawPool::POOL_WATER)->getShaderLevel() != 0) { mFace[FACE_REFLECTION] = drawable->addFace(poolp, NULL); } } mCameraPosAgent = drawable->getPositionAgent(); + mEarthCenter.mV[0] = mCameraPosAgent.mV[0]; mEarthCenter.mV[1] = mCameraPosAgent.mV[1]; @@ -1344,64 +1155,40 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable) LLVector3 up = right % look_at; right.normalize(); up.normalize(); + + bool draw_sun = updateHeavenlyBodyGeometry(drawable, mSunScale, FACE_SUN, mSun, up, right); + bool draw_moon = updateHeavenlyBodyGeometry(drawable, mMoonScale, FACE_MOON, mMoon, up, right); - const static F32 elevation_factor = 0.0f/sResolution; - const F32 cos_max_angle = cosHorizon(elevation_factor); - mSun.setDraw(updateHeavenlyBodyGeometry(drawable, FACE_SUN, TRUE, mSun, cos_max_angle, up, right)); - mMoon.setDraw(updateHeavenlyBodyGeometry(drawable, FACE_MOON, FALSE, mMoon, cos_max_angle, up, right)); + draw_sun &= LLEnvironment::getInstance()->getIsSunUp(); + draw_moon &= LLEnvironment::getInstance()->getIsMoonUp(); + + mSun.setDraw(draw_sun); + mMoon.setDraw(draw_moon); const F32 water_height = gAgent.getRegion()->getWaterHeight() + 0.01f; // LLWorld::getInstance()->getWaterHeight() + 0.01f; const F32 camera_height = mCameraPosAgent.mV[2]; const F32 height_above_water = camera_height - water_height; - BOOL sun_flag = FALSE; - + bool sun_flag = FALSE; if (mSun.isVisible()) - { - if (mMoon.isVisible()) - { - sun_flag = look_at * mSun.getDirection() > 0; - } - else - { - sun_flag = TRUE; - } + { + sun_flag = !mMoon.isVisible() || ((look_at * mSun.getDirection()) > 0); } - if (height_above_water > 0) - { - BOOL render_ref = gPipeline.getPool(LLDrawPool::POOL_WATER)->getVertexShaderLevel() == 0; - - if (sun_flag) - { - setDrawRefl(0); - if (render_ref) - { - updateReflectionGeometry(drawable, height_above_water, mSun); - } - } - else - { - setDrawRefl(1); - if (render_ref) - { - updateReflectionGeometry(drawable, height_above_water, mMoon); - } - } - } - else - { - setDrawRefl(-1); - } + bool above_water = (height_above_water > 0); + bool render_ref = above_water && gPipeline.getPool(LLDrawPool::POOL_WATER)->getShaderLevel() == 0; + setDrawRefl(above_water ? (sun_flag ? 0 : 1) : -1); + if (render_ref) + { + updateReflectionGeometry(drawable, height_above_water, mSun); + } LLPipeline::sCompiles++; return TRUE; } -BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, const BOOL is_sun, - LLHeavenBody& hb, const F32 cos_max_angle, - const LLVector3 &up, const LLVector3 &right) +bool LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, F32 scale, const S32 f, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right) { mHeavenlyBodyUpdated = TRUE ; @@ -1412,52 +1199,28 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, cons S32 index_offset; LLFace *facep; - LLVector3 to_dir = hb.getDirection(); - - if (!is_sun) - { - to_dir.mV[2] = llmax(to_dir.mV[2]+0.1f, 0.1f); - } + LLVector3 to_dir = hb.getDirection(); LLVector3 draw_pos = to_dir * HEAVENLY_BODY_DIST; - LLVector3 hb_right = to_dir % LLVector3::z_axis; LLVector3 hb_up = hb_right % to_dir; hb_right.normalize(); hb_up.normalize(); - //const static F32 cos_max_turn = sqrt(3.f) / 2; // 30 degrees - //const F32 cos_turn_right = 1. / (llmax(cos_max_turn, hb_right * right)); - //const F32 cos_turn_up = 1. / llmax(cos_max_turn, hb_up * up); - - const F32 enlargm_factor = ( 1 - to_dir.mV[2] ); + const F32 enlargm_factor = ( 1 - to_dir.mV[2] ); F32 horiz_enlargement = 1 + enlargm_factor * 0.3f; F32 vert_enlargement = 1 + enlargm_factor * 0.2f; - // Parameters for the water reflection - hb.setU(HEAVENLY_BODY_FACTOR * horiz_enlargement * hb.getDiskRadius() * hb_right); - hb.setV(HEAVENLY_BODY_FACTOR * vert_enlargement * hb.getDiskRadius() * hb_up); - // End of parameters for the water reflection - - const LLVector3 scaled_right = HEAVENLY_BODY_DIST * hb.getU(); - const LLVector3 scaled_up = HEAVENLY_BODY_DIST * hb.getV(); + const LLVector3 scaled_right = horiz_enlargement * scale * HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR * hb.getDiskRadius() * hb_right; + const LLVector3 scaled_up = vert_enlargement * scale * HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR * hb.getDiskRadius() * hb_up; - //const LLVector3 scaled_right = horiz_enlargement * HEAVENLY_BODY_SCALE * hb.getDiskRadius() * hb_right;//right; - //const LLVector3 scaled_up = vert_enlargement * HEAVENLY_BODY_SCALE * hb.getDiskRadius() * hb_up;//up; LLVector3 v_clipped[4]; - hb.corner(0) = draw_pos - scaled_right + scaled_up; - hb.corner(1) = draw_pos - scaled_right - scaled_up; - hb.corner(2) = draw_pos + scaled_right + scaled_up; - hb.corner(3) = draw_pos + scaled_right - scaled_up; + v_clipped[0] = draw_pos - scaled_right + scaled_up; + v_clipped[1] = draw_pos - scaled_right - scaled_up; + v_clipped[2] = draw_pos + scaled_right + scaled_up; + v_clipped[3] = draw_pos + scaled_right - scaled_up; - - F32 t_left, t_right; - if (!clip_quad_to_horizon(t_left, t_right, v_clipped, hb.corners(), cos_max_angle)) - { - hb.setVisible(FALSE); - return FALSE; - } hb.setVisible(TRUE); facep = mFace[f]; @@ -1507,164 +1270,9 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, cons facep->getVertexBuffer()->flush(); - if (is_sun) - { - if ((t_left > 0) && (t_right > 0)) - { - F32 t = (t_left + t_right) * 0.5f; - mSun.setHorizonVisibility(0.5f * (1 + cos(t * F_PI))); - } - else - { - mSun.setHorizonVisibility(); - } - updateSunHaloGeometry(drawable); - } - - return TRUE; -} - - - - -// Clips quads with top and bottom sides parallel to horizon. - -BOOL clip_quad_to_horizon(F32& t_left, F32& t_right, LLVector3 v_clipped[4], - const LLVector3 v_corner[4], const F32 cos_max_angle) -{ - t_left = clip_side_to_horizon(v_corner[1], v_corner[0], cos_max_angle); - t_right = clip_side_to_horizon(v_corner[3], v_corner[2], cos_max_angle); - - if ((t_left >= 1) || (t_right >= 1)) - { - return FALSE; - } - - //const BOOL left_clip = (t_left > 0); - //const BOOL right_clip = (t_right > 0); - - //if (!left_clip && !right_clip) - { - for (S32 vtx = 0; vtx < 4; ++vtx) - { - v_clipped[vtx] = v_corner[vtx]; - } - } -/* else - { - v_clipped[0] = v_corner[0]; - v_clipped[1] = left_clip ? ((1 - t_left) * v_corner[1] + t_left * v_corner[0]) - : v_corner[1]; - v_clipped[2] = v_corner[2]; - v_clipped[3] = right_clip ? ((1 - t_right) * v_corner[3] + t_right * v_corner[2]) - : v_corner[3]; - }*/ - return TRUE; } - -F32 clip_side_to_horizon(const LLVector3& V0, const LLVector3& V1, const F32 cos_max_angle) -{ - const LLVector3 V = V1 - V0; - const F32 k2 = 1.f/(cos_max_angle * cos_max_angle) - 1; - const F32 A = V.mV[0] * V.mV[0] + V.mV[1] * V.mV[1] - k2 * V.mV[2] * V.mV[2]; - const F32 B = V0.mV[0] * V.mV[0] + V0.mV[1] * V.mV[1] - k2 * V0.mV[2] * V.mV[2]; - const F32 C = V0.mV[0] * V0.mV[0] + V0.mV[1] * V0.mV[1] - k2 * V0.mV[2] * V0.mV[2]; - - if (fabs(A) < 1e-7) - { - return -0.1f; // v0 is cone origin and v1 is on the surface of the cone. - } - - const F32 det = sqrt(B*B - A*C); - const F32 t1 = (-B - det) / A; - const F32 t2 = (-B + det) / A; - const F32 z1 = V0.mV[2] + t1 * V.mV[2]; - const F32 z2 = V0.mV[2] + t2 * V.mV[2]; - if (z1 * cos_max_angle < 0) - { - return t2; - } - else if (z2 * cos_max_angle < 0) - { - return t1; - } - else if ((t1 < 0) || (t1 > 1)) - { - return t2; - } - else - { - return t1; - } -} - - -void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable ) -{ -#if 0 - const LLVector3* v_corner = mSun.corners(); - - LLStrider verticesp; - LLStrider normalsp; - LLStrider texCoordsp; - LLStrider indicesp; - S32 index_offset; - LLFace *face; - - const LLVector3 right = 2 * (v_corner[2] - v_corner[0]); - LLVector3 up = 2 * (v_corner[2] - v_corner[3]); - up.normalize(); - F32 size = right.length(); - up = size * up; - const LLVector3 draw_pos = 0.25 * (v_corner[0] + v_corner[1] + v_corner[2] + v_corner[3]); - - LLVector3 v_glow_corner[4]; - - v_glow_corner[0] = draw_pos - right + up; - v_glow_corner[1] = draw_pos - right - up; - v_glow_corner[2] = draw_pos + right + up; - v_glow_corner[3] = draw_pos + right - up; - - face = mFace[FACE_BLOOM]; - - if (face->mVertexBuffer.isNull()) - { - face->setSize(4, 6); - face->setGeomIndex(0); - face->setIndicesIndex(0); - face->mVertexBuffer = new LLVertexBuffer(LLDrawPoolWater::VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB); - face->mVertexBuffer->allocateBuffer(4, 6, TRUE); - } - - index_offset = face->getGeometry(verticesp,normalsp,texCoordsp, indicesp); - if (-1 == index_offset) - { - return; - } - - for (S32 vtx = 0; vtx < 4; ++vtx) - { - *(verticesp++) = v_glow_corner[vtx] + mCameraPosAgent; - } - - *(texCoordsp++) = TEX01; - *(texCoordsp++) = TEX00; - *(texCoordsp++) = TEX11; - *(texCoordsp++) = TEX10; - - *indicesp++ = index_offset + 0; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 1; - - *indicesp++ = index_offset + 1; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 3; -#endif -} - - F32 dtReflection(const LLVector3& p, F32 cos_dir_from_top, F32 sin_dir_from_top, F32 diff_angl_dir) { LLVector3 P = p; @@ -1726,9 +1334,6 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, LLVector3 look_at_right = look_at % LLVector3::z_axis; look_at_right.normalize(); - const static F32 cos_horizon_angle = cosHorizon(0.0f/sResolution); - //const static F32 horizon_angle = acos(cos_horizon_angle); - const F32 enlargm_factor = ( 1 - to_dir.mV[2] ); F32 horiz_enlargement = 1 + enlargm_factor * 0.3f; F32 vert_enlargement = 1 + enlargm_factor * 0.2f; @@ -1743,22 +1348,10 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, LLVector3 top_hb = v_corner[0] = stretch_corner[0] = hb_pos - Right + Up; v_corner[1] = stretch_corner[1] = hb_pos - Right - Up; - F32 dt_hor, dt; - dt_hor = clip_side_to_horizon(v_corner[1], v_corner[0], cos_horizon_angle); - LLVector2 TEX0t = TEX00; LLVector2 TEX1t = TEX10; LLVector3 lower_corner = v_corner[1]; - if ((dt_hor > 0) && (dt_hor < 1)) - { - TEX0t = LLVector2(0, dt_hor); - TEX1t = LLVector2(1, dt_hor); - lower_corner = (1 - dt_hor) * v_corner[1] + dt_hor * v_corner[0]; - } - else - dt_hor = llmax(0.0f, llmin(1.0f, dt_hor)); - top_hb.normalize(); const F32 cos_angle_of_view = fabs(top_hb.mV[VZ]); const F32 extension = llmin (5.0f, 1.0f / cos_angle_of_view); @@ -1770,9 +1363,6 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, stretch_corner[0] = lower_corner + extension * (stretch_corner[0] - lower_corner); stretch_corner[1] = lower_corner + extension * (stretch_corner[1] - lower_corner); - dt = dt_hor; - - F32 cos_dir_from_top[2]; LLVector3 dir = stretch_corner[0]; @@ -1861,9 +1451,8 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, F32 dt_tex = dtReflection(P, cos_dir_from_top[0], sin_dir_from_top, diff_angl_dir); - dt = dt_tex; - TEX0tt = LLVector2(0, dt); - TEX1tt = LLVector2(1, dt); + TEX0tt = LLVector2(0, dt_tex); + TEX1tt = LLVector2(1, dt_tex); quads++; } else @@ -1874,408 +1463,225 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H, LLFace *face = mFace[FACE_REFLECTION]; - if (!face->getVertexBuffer() || quads*4 != face->getGeomCount()) - { - face->setSize(quads * 4, quads * 6); - LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolWater::VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB); - if (!buff->allocateBuffer(face->getGeomCount(), face->getIndicesCount(), TRUE)) - { - LL_WARNS() << "Failed to allocate Vertex Buffer for vosky to " - << face->getGeomCount() << " vertices and " - << face->getIndicesCount() << " indices" << LL_ENDL; - } - face->setIndicesIndex(0); - face->setGeomIndex(0); - face->setVertexBuffer(buff); - } - - LLStrider verticesp; - LLStrider normalsp; - LLStrider texCoordsp; - LLStrider indicesp; - S32 index_offset; - - index_offset = face->getGeometry(verticesp,normalsp,texCoordsp, indicesp); - if (-1 == index_offset) - { - return; - } - - LLColor3 hb_col3 = HB.getInterpColor(); - hb_col3.clamp(); - const LLColor4 hb_col = LLColor4(hb_col3); - - const F32 min_attenuation = 0.4f; - const F32 max_attenuation = 0.7f; - const F32 attenuation = min_attenuation - + cos_angle_of_view * (max_attenuation - min_attenuation); - - LLColor4 hb_refl_col = (1-attenuation) * hb_col + attenuation * mFogColor; - face->setFaceColor(hb_refl_col); - - LLVector3 v_far[2]; - v_far[0] = v_refl_corner[1]; - v_far[1] = v_refl_corner[3]; - - if(dt_clip > 0) - { - if (dt_clip >= 1) - { - for (S32 vtx = 0; vtx < 4; ++vtx) - { - F32 ratio = far_clip / v_refl_corner[vtx].length(); - *(verticesp++) = v_refl_corner[vtx] = ratio * v_refl_corner[vtx] + mCameraPosAgent; - } - const LLVector3 draw_pos = 0.25 * - (v_refl_corner[0] + v_refl_corner[1] + v_refl_corner[2] + v_refl_corner[3]); - face->mCenterAgent = draw_pos; - } - else - { - F32 ratio = far_clip / v_refl_corner[1].length(); - v_sprite_corner[1] = v_refl_corner[1] * ratio; - - ratio = far_clip / v_refl_corner[3].length(); - v_sprite_corner[3] = v_refl_corner[3] * ratio; - - v_refl_corner[1] = (1 - dt_clip) * v_refl_corner[1] + dt_clip * v_refl_corner[0]; - v_refl_corner[3] = (1 - dt_clip) * v_refl_corner[3] + dt_clip * v_refl_corner[2]; - v_sprite_corner[0] = v_refl_corner[1]; - v_sprite_corner[2] = v_refl_corner[3]; - - for (S32 vtx = 0; vtx < 4; ++vtx) - { - *(verticesp++) = v_sprite_corner[vtx] + mCameraPosAgent; - } - - const LLVector3 draw_pos = 0.25 * - (v_refl_corner[0] + v_sprite_corner[1] + v_refl_corner[2] + v_sprite_corner[3]); - face->mCenterAgent = draw_pos; - } - - *(texCoordsp++) = TEX0tt; - *(texCoordsp++) = TEX0t; - *(texCoordsp++) = TEX1tt; - *(texCoordsp++) = TEX1t; - - *indicesp++ = index_offset + 0; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 1; - - *indicesp++ = index_offset + 1; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 3; - - index_offset += 4; - } - - if (dt_clip < 1) - { - if (dt_clip <= 0) - { - const LLVector3 draw_pos = 0.25 * - (v_refl_corner[0] + v_refl_corner[1] + v_refl_corner[2] + v_refl_corner[3]); - face->mCenterAgent = draw_pos; - } - - const F32 raws_inv = 1.f/raws; - const F32 cols_inv = 1.f/cols; - LLVector3 left = v_refl_corner[0] - v_refl_corner[1]; - LLVector3 right = v_refl_corner[2] - v_refl_corner[3]; - left *= raws_inv; - right *= raws_inv; - - F32 dt_raw = dt; - - for (S32 raw = 0; raw < raws; ++raw) - { - F32 dt_v0 = raw * raws_inv; - F32 dt_v1 = (raw + 1) * raws_inv; - const LLVector3 BL = v_refl_corner[1] + (F32)raw * left; - const LLVector3 BR = v_refl_corner[3] + (F32)raw * right; - const LLVector3 EL = BL + left; - const LLVector3 ER = BR + right; - dt_v0 = dt_raw; - dt_raw = dt_v1 = dtReflection(EL, cos_dir_from_top[0], sin_dir_from_top, diff_angl_dir); - for (S32 col = 0; col < cols; ++col) + if (face) + { + if (!face->getVertexBuffer() || quads * 4 != face->getGeomCount()) + { + face->setSize(quads * 4, quads * 6); + LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolWater::VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB); + if (!buff->allocateBuffer(face->getGeomCount(), face->getIndicesCount(), TRUE)) { - F32 dt_h0 = col * cols_inv; - *(verticesp++) = (1 - dt_h0) * EL + dt_h0 * ER + mCameraPosAgent; - *(verticesp++) = (1 - dt_h0) * BL + dt_h0 * BR + mCameraPosAgent; - F32 dt_h1 = (col + 1) * cols_inv; - *(verticesp++) = (1 - dt_h1) * EL + dt_h1 * ER + mCameraPosAgent; - *(verticesp++) = (1 - dt_h1) * BL + dt_h1 * BR + mCameraPosAgent; - - *(texCoordsp++) = LLVector2(dt_h0, dt_v1); - *(texCoordsp++) = LLVector2(dt_h0, dt_v0); - *(texCoordsp++) = LLVector2(dt_h1, dt_v1); - *(texCoordsp++) = LLVector2(dt_h1, dt_v0); - - *indicesp++ = index_offset + 0; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 1; - - *indicesp++ = index_offset + 1; - *indicesp++ = index_offset + 2; - *indicesp++ = index_offset + 3; - - index_offset += 4; + LL_WARNS() << "Failed to allocate Vertex Buffer for vosky to " + << face->getGeomCount() << " vertices and " + << face->getIndicesCount() << " indices" << LL_ENDL; } - } - } - - face->getVertexBuffer()->flush(); + face->setIndicesIndex(0); + face->setGeomIndex(0); + face->setVertexBuffer(buff); + } + + LLStrider verticesp; + LLStrider normalsp; + LLStrider texCoordsp; + LLStrider indicesp; + S32 index_offset; + + index_offset = face->getGeometry(verticesp, normalsp, texCoordsp, indicesp); + if (-1 == index_offset) + { + return; + } + + LLColor3 hb_col3 = HB.getInterpColor(); + hb_col3.clamp(); + const LLColor4 hb_col = LLColor4(hb_col3); + + const F32 min_attenuation = 0.4f; + const F32 max_attenuation = 0.7f; + const F32 attenuation = min_attenuation + + cos_angle_of_view * (max_attenuation - min_attenuation); + + LLColor4 hb_refl_col = (1 - attenuation) * hb_col + attenuation * getSkyFogColor(); + face->setFaceColor(hb_refl_col); + + LLVector3 v_far[2]; + v_far[0] = v_refl_corner[1]; + v_far[1] = v_refl_corner[3]; + + if (dt_clip > 0) + { + if (dt_clip >= 1) + { + for (S32 vtx = 0; vtx < 4; ++vtx) + { + F32 ratio = far_clip / v_refl_corner[vtx].length(); + *(verticesp++) = v_refl_corner[vtx] = ratio * v_refl_corner[vtx] + mCameraPosAgent; + } + const LLVector3 draw_pos = 0.25 * + (v_refl_corner[0] + v_refl_corner[1] + v_refl_corner[2] + v_refl_corner[3]); + face->mCenterAgent = draw_pos; + } + else + { + F32 ratio = far_clip / v_refl_corner[1].length(); + v_sprite_corner[1] = v_refl_corner[1] * ratio; + + ratio = far_clip / v_refl_corner[3].length(); + v_sprite_corner[3] = v_refl_corner[3] * ratio; + + v_refl_corner[1] = (1 - dt_clip) * v_refl_corner[1] + dt_clip * v_refl_corner[0]; + v_refl_corner[3] = (1 - dt_clip) * v_refl_corner[3] + dt_clip * v_refl_corner[2]; + v_sprite_corner[0] = v_refl_corner[1]; + v_sprite_corner[2] = v_refl_corner[3]; + + for (S32 vtx = 0; vtx < 4; ++vtx) + { + *(verticesp++) = v_sprite_corner[vtx] + mCameraPosAgent; + } + + const LLVector3 draw_pos = 0.25 * + (v_refl_corner[0] + v_sprite_corner[1] + v_refl_corner[2] + v_sprite_corner[3]); + face->mCenterAgent = draw_pos; + } + + *(texCoordsp++) = TEX0tt; + *(texCoordsp++) = TEX0t; + *(texCoordsp++) = TEX1tt; + *(texCoordsp++) = TEX1t; + + *indicesp++ = index_offset + 0; + *indicesp++ = index_offset + 2; + *indicesp++ = index_offset + 1; + + *indicesp++ = index_offset + 1; + *indicesp++ = index_offset + 2; + *indicesp++ = index_offset + 3; + + index_offset += 4; + } + + if (dt_clip < 1) + { + if (dt_clip <= 0) + { + const LLVector3 draw_pos = 0.25 * + (v_refl_corner[0] + v_refl_corner[1] + v_refl_corner[2] + v_refl_corner[3]); + face->mCenterAgent = draw_pos; + } + + const F32 raws_inv = 1.f / raws; + const F32 cols_inv = 1.f / cols; + LLVector3 left = v_refl_corner[0] - v_refl_corner[1]; + LLVector3 right = v_refl_corner[2] - v_refl_corner[3]; + left *= raws_inv; + right *= raws_inv; + + for (S32 raw = 0; raw < raws; ++raw) + { + F32 dt_v0 = raw * raws_inv; + F32 dt_v1 = (raw + 1) * raws_inv; + const LLVector3 BL = v_refl_corner[1] + (F32)raw * left; + const LLVector3 BR = v_refl_corner[3] + (F32)raw * right; + const LLVector3 EL = BL + left; + const LLVector3 ER = BR + right; + dt_v0 = dt_v1 = dtReflection(EL, cos_dir_from_top[0], sin_dir_from_top, diff_angl_dir); + for (S32 col = 0; col < cols; ++col) + { + F32 dt_h0 = col * cols_inv; + *(verticesp++) = (1 - dt_h0) * EL + dt_h0 * ER + mCameraPosAgent; + *(verticesp++) = (1 - dt_h0) * BL + dt_h0 * BR + mCameraPosAgent; + F32 dt_h1 = (col + 1) * cols_inv; + *(verticesp++) = (1 - dt_h1) * EL + dt_h1 * ER + mCameraPosAgent; + *(verticesp++) = (1 - dt_h1) * BL + dt_h1 * BR + mCameraPosAgent; + + *(texCoordsp++) = LLVector2(dt_h0, dt_v1); + *(texCoordsp++) = LLVector2(dt_h0, dt_v0); + *(texCoordsp++) = LLVector2(dt_h1, dt_v1); + *(texCoordsp++) = LLVector2(dt_h1, dt_v0); + + *indicesp++ = index_offset + 0; + *indicesp++ = index_offset + 2; + *indicesp++ = index_offset + 1; + + *indicesp++ = index_offset + 1; + *indicesp++ = index_offset + 2; + *indicesp++ = index_offset + 3; + + index_offset += 4; + } + } + } + + face->getVertexBuffer()->flush(); + } } - - - void LLVOSky::updateFog(const F32 distance) { - if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOG)) - { - if (!LLGLSLShader::sNoFixedFunction) - { - glFogf(GL_FOG_DENSITY, 0); - glFogfv(GL_FOG_COLOR, (F32 *) &LLColor4::white.mV); - glFogf(GL_FOG_END, 1000000.f); - } - return; - } - - const BOOL hide_clip_plane = TRUE; - LLColor4 target_fog(0.f, 0.2f, 0.5f, 0.f); - - const F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : 0.f; - // LLWorld::getInstance()->getWaterHeight(); - F32 camera_height = gAgentCamera.getCameraPositionAgent().mV[2]; - - F32 near_clip_height = LLViewerCamera::getInstance()->getAtAxis().mV[VZ] * LLViewerCamera::getInstance()->getNear(); - camera_height += near_clip_height; - - F32 fog_distance = 0.f; - LLColor3 res_color[3]; - - LLColor3 sky_fog_color = LLColor3::white; - LLColor3 render_fog_color = LLColor3::white; - - LLVector3 tosun = getToSunLast(); - const F32 tosun_z = tosun.mV[VZ]; - tosun.mV[VZ] = 0.f; - tosun.normalize(); - LLVector3 perp_tosun; - perp_tosun.mV[VX] = -tosun.mV[VY]; - perp_tosun.mV[VY] = tosun.mV[VX]; - LLVector3 tosun_45 = tosun + perp_tosun; - tosun_45.normalize(); - - F32 delta = 0.06f; - tosun.mV[VZ] = delta; - perp_tosun.mV[VZ] = delta; - tosun_45.mV[VZ] = delta; - tosun.normalize(); - perp_tosun.normalize(); - tosun_45.normalize(); - - // Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun. - initAtmospherics(); - res_color[0] = calcSkyColorInDir(tosun); - res_color[1] = calcSkyColorInDir(perp_tosun); - res_color[2] = calcSkyColorInDir(tosun_45); - - sky_fog_color = color_norm(res_color[0] + res_color[1] + res_color[2]); - - F32 full_off = -0.25f; - F32 full_on = 0.00f; - F32 on = (tosun_z - full_off) / (full_on - full_off); - on = llclamp(on, 0.01f, 1.f); - sky_fog_color *= 0.5f * on; - - - // We need to clamp these to non-zero, in order for the gamma correction to work. 0^y = ??? - S32 i; - for (i = 0; i < 3; i++) - { - sky_fog_color.mV[i] = llmax(0.0001f, sky_fog_color.mV[i]); - } - - color_gamma_correct(sky_fog_color); - - render_fog_color = sky_fog_color; - - F32 fog_density = 0.f; - fog_distance = mFogRatio * distance; - - if (camera_height > water_height) - { - LLColor4 fog(render_fog_color); - if (!LLGLSLShader::sNoFixedFunction) - { - glFogfv(GL_FOG_COLOR, fog.mV); - } - mGLFogCol = fog; - - if (hide_clip_plane) - { - // For now, set the density to extend to the cull distance. - const F32 f_log = 2.14596602628934723963618357029f; // sqrt(fabs(log(0.01f))) - fog_density = f_log/fog_distance; - if (!LLGLSLShader::sNoFixedFunction) - { - glFogi(GL_FOG_MODE, GL_EXP2); - } - } - else - { - const F32 f_log = 4.6051701859880913680359829093687f; // fabs(log(0.01f)) - fog_density = (f_log)/fog_distance; - if (!LLGLSLShader::sNoFixedFunction) - { - glFogi(GL_FOG_MODE, GL_EXP); - } - } - } - else - { - F32 depth = water_height - camera_height; - - // get the water param manager variables - float water_fog_density = LLWaterParamManager::getInstance()->getFogDensity(); - LLColor4 water_fog_color(LLDrawPoolWater::sWaterFogColor.mV); - - // adjust the color based on depth. We're doing linear approximations - float depth_scale = gSavedSettings.getF32("WaterGLFogDepthScale"); - float depth_modifier = 1.0f - llmin(llmax(depth / depth_scale, 0.01f), - gSavedSettings.getF32("WaterGLFogDepthFloor")); + LLEnvironment& environment = LLEnvironment::instance(); + if (environment.getCurrentSky() != nullptr) + { + LLVector3 light_dir = LLVector3(environment.getClampedLightNorm()); + m_legacyAtmospherics.updateFog(distance, light_dir); + } +} - LLColor4 fogCol = water_fog_color * depth_modifier; - fogCol.setAlpha(1); +void LLVOSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir_cfr, const LLVector3 &moon_dir_cfr) +{ + mSun.setDirection(sun_dir_cfr); + mMoon.setDirection(moon_dir_cfr); - // set the gl fog color - mGLFogCol = fogCol; + // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping + // on the upward facing faces of cubes. + { + // Same as dot product with the up direction + clamp. + F32 sunDot = llmax(0.f, sun_dir_cfr.mV[2]); + sunDot *= sunDot; - // set the density based on what the shaders use - fog_density = water_fog_density * gSavedSettings.getF32("WaterGLFogDensityScale"); + // Create normalized vector that has the sunDir pushed south about an hour and change. + LLVector3 adjustedDir = (sun_dir_cfr + LLVector3(0.f, -0.70711f, 0.70711f)) * 0.5f; - if (!LLGLSLShader::sNoFixedFunction) - { - glFogfv(GL_FOG_COLOR, (F32 *) &fogCol.mV); - glFogi(GL_FOG_MODE, GL_EXP2); - } - } + // Blend between normal sun dir and adjusted sun dir based on how close we are + // to having the sun overhead. + mBumpSunDir = adjustedDir * sunDot + sun_dir_cfr * (1.0f - sunDot); + mBumpSunDir.normalize(); + } - mFogColor = sky_fog_color; - mFogColor.setAlpha(1); - LLDrawPoolWater::sWaterFogEnd = fog_distance*2.2f; + updateDirections(); - if (!LLGLSLShader::sNoFixedFunction) - { - LLGLSFog gls_fog; - glFogf(GL_FOG_END, fog_distance*2.2f); - glFogf(GL_FOG_DENSITY, fog_density); - glHint(GL_FOG_HINT, GL_NICEST); - } - stop_glerror(); + mForceUpdate = true; } - -// Functions used a lot. -F32 color_norm_pow(LLColor3& col, F32 e, BOOL postmultiply) +void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr) { - F32 mv = color_max(col); - if (0 == mv) - { - return 0; - } + mSun.setDirection(sun_dir_cfr); - col *= 1.f / mv; - color_pow(col, e); - if (postmultiply) - { - col *= mv; - } - return mv; -} + // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping + // on the upward facing faces of cubes. + { + // Same as dot product with the up direction + clamp. + F32 sunDot = llmax(0.f, sun_dir_cfr.mV[2]); + sunDot *= sunDot; -// Returns angle (RADIANs) between the horizontal projection of "v" and the x_axis. -// Range of output is 0.0f to 2pi //359.99999...f -// Returns 0.0f when "v" = +/- z_axis. -F32 azimuth(const LLVector3 &v) -{ - F32 azimuth = 0.0f; - if (v.mV[VX] == 0.0f) - { - if (v.mV[VY] > 0.0f) - { - azimuth = F_PI * 0.5f; - } - else if (v.mV[VY] < 0.0f) - { - azimuth = F_PI * 1.5f;// 270.f; - } - } - else - { - azimuth = (F32) atan(v.mV[VY] / v.mV[VX]); - if (v.mV[VX] < 0.0f) - { - azimuth += F_PI; - } - else if (v.mV[VY] < 0.0f) - { - azimuth += F_PI * 2; - } - } - return azimuth; -} + // Create normalized vector that has the sunDir pushed south about an hour and change. + LLVector3 adjustedDir = (sun_dir_cfr + LLVector3(0.f, -0.70711f, 0.70711f)) * 0.5f; -void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) -{ - LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir; - sun_direction.normalize(); - mSun.setDirection(sun_direction); - mSun.renewDirection(); - mSun.setAngularVelocity(sun_ang_velocity); - mMoon.setDirection(-mSun.getDirection()); - mMoon.renewDirection(); - mLastLightingDirection = mSun.getDirection(); + // Blend between normal sun dir and adjusted sun dir based on how close we are + // to having the sun overhead. + mBumpSunDir = adjustedDir * sunDot + sun_dir_cfr * (1.0f - sunDot); + mBumpSunDir.normalize(); + } - calcAtmospherics(); + updateDirections(); - if ( !mInitialized ) - { - init(); - LLSkyTex::stepCurrent(); - } + mForceUpdate = true; } -void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity) +void LLVOSky::setMoonDirectionCFR(const LLVector3 &moon_dir_cfr) { - LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir; - sun_direction.normalize(); + mMoon.setDirection(moon_dir_cfr); - // Push the sun "South" as it approaches directly overhead so that we can always see bump mapping - // on the upward facing faces of cubes. - LLVector3 newDir = sun_direction; - - // Same as dot product with the up direction + clamp. - F32 sunDot = llmax(0.f, newDir.mV[2]); - sunDot *= sunDot; - - // Create normalized vector that has the sunDir pushed south about an hour and change. - LLVector3 adjustedDir = (newDir + LLVector3(0.f, -0.70711f, 0.70711f)) * 0.5f; - - // Blend between normal sun dir and adjusted sun dir based on how close we are - // to having the sun overhead. - mBumpSunDir = adjustedDir * sunDot + newDir * (1.0f - sunDot); - mBumpSunDir.normalize(); - - F32 dp = mLastLightingDirection * sun_direction; - mSun.setDirection(sun_direction); - mSun.setAngularVelocity(sun_ang_velocity); - mMoon.setDirection(-sun_direction); - calcAtmospherics(); - if (dp < 0.995f) { //the sun jumped a great deal, update immediately - mForceUpdate = TRUE; - } + updateDirections(); + + mForceUpdate = true; } -- cgit v1.3 From 966dc7fc8fb1fade861e8070e9c5fbbfe4d0cb45 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 24 Jan 2019 14:54:11 -0800 Subject: SL-10276 SL-9851 Fix cloud shaders to ignore clouds when cloud_scale is 0. Fix creation of heavenly body geo to avoid degenerate vector math and not randomly flip orientation when crossing zenith. Add sun_up_factor to eliminate sun glow around moon when sun is down. --- indra/llrender/llshadermgr.cpp | 2 + indra/llrender/llshadermgr.h | 1 + .../shaders/class1/deferred/cloudShadowF.glsl | 91 ++++---- .../shaders/class1/deferred/cloudsF.glsl | 73 +++--- .../shaders/class1/deferred/cloudsV.glsl | 5 +- .../shaders/class1/deferred/moonF.glsl | 10 +- .../shaders/class1/deferred/moonV.glsl | 12 +- .../shaders/class1/windlight/cloudShadowF.glsl | 93 ++++---- .../app_settings/shaders/class2/deferred/skyF.glsl | 196 +++++++++-------- .../shaders/class2/deferred/softenLightF.glsl | 12 - .../shaders/class2/windlight/atmosphericsF.glsl | 3 + .../shaders/class2/windlight/atmosphericsV.glsl | 202 ++++++++--------- .../shaders/class2/windlight/cloudsF.glsl | 73 +++--- .../shaders/class2/windlight/cloudsV.glsl | 245 +++++++++++---------- .../shaders/class2/windlight/skyV.glsl | 4 +- .../shaders/class3/deferred/cloudShadowF.glsl | 91 ++++---- .../shaders/class3/deferred/cloudsF.glsl | 63 +++--- .../shaders/class3/deferred/cloudsV.glsl | 22 +- indra/newview/lldrawpoolwlsky.cpp | 7 +- indra/newview/llvosky.cpp | 21 +- indra/newview/llvosky.h | 7 +- 21 files changed, 650 insertions(+), 583 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 29d120a135..9db8fd1f05 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1358,6 +1358,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("sh_input_g"); mReservedUniforms.push_back("sh_input_b"); + mReservedUniforms.push_back("sun_up_factor"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index c22fe44750..0b1a97d880 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -248,6 +248,7 @@ public: SH_INPUT_L1G, SH_INPUT_L1B, + SUN_UP_FACTOR, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl index d93baa03c6..035e979827 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl @@ -69,53 +69,60 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.0001) { - discard; + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + } + else + { + frag_color = vec4(1); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = vec4(alpha1, alpha1, alpha1, 1); #if !defined(DEPTH_CLAMP) - gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index fe69233e68..60ccfa64db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -65,60 +65,65 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + if (cloud_scale < 0.001) + { + discard; + } vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity + // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; - // Combine - vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0,0,1,0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 17f425475c..fe336fc3a8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -58,6 +58,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -131,6 +132,8 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function + temp2.x *= sun_up_factor; + // Add "minimum anti-solar illumination" temp2.x += .25; @@ -170,7 +173,7 @@ void main() // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; + vary_texcoord0.xy /= max(0.001, cloud_scale); vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 8bf4551abc..7265275e36 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -45,8 +45,8 @@ VARYING vec2 vary_texcoord0; void main() { - vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 moonA = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 moonB = texture2D(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(moonA, moonB, blend_factor); // mix factor which blends when sunlight is brighter @@ -58,8 +58,8 @@ void main() vec3 exp = vec3(1.0 - mix * moon_brightness) * 2.0 - 1.0; c.rgb = pow(c.rgb, exp); - frag_data[0] = vec4(c.rgb, c.a); - frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0f); + frag_data[0] = vec4(c.rgb, c.a); + frag_data[1] = vec4(0.0); + frag_data[2] = vec4(0.0f); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index 0325ecead9..0a68fc82f7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -36,13 +36,13 @@ void calcAtmospherics(vec3 eye_pos); void main() { - //transform vertex - vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + //transform vertex + vec4 vert = vec4(position.xyz, 1.0); + vec4 pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); calcAtmospherics(pos.xyz); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl index d93baa03c6..69a3c59cb3 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl @@ -69,53 +69,60 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); - - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.0001) { - discard; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = vec4(alpha1, alpha1, alpha1, 1); + } + else + { + frag_color = vec4(1); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = vec4(alpha1, alpha1, alpha1, 1); #if !defined(DEPTH_CLAMP) - gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); + gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); #endif } diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl index 09ad6e70d6..6ddd7e7c86 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl @@ -45,6 +45,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -88,98 +89,99 @@ vec3 scaleSoftClip(vec3 light); void main() { - // World / view / projection - // Get relative position - vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - - // Haze color above cloud - vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) - ); - - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // Final atmosphere additive - color *= (1. - temp1); - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - - // At horizon, blend high altitude sky color towards the darker color below the clouds - color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); - + // World / view / projection + // Get relative position + vec3 P = pos.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + temp2.x *= sun_up_factor; + + // Haze color above cloud + vec4 color = ( blue_horizon * blue_weight * (sunlight + ambient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) + ); + + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // Final atmosphere additive + color *= (1. - temp1); + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + + // At horizon, blend high altitude sky color towards the darker color below the clouds + color += (additiveColorBelowCloud - color) * (1. - sqrt(temp1)); + float optic_d = dot(Pn, lightnorm.xyz); vec3 halo_22 = halo22(optic_d); @@ -188,11 +190,11 @@ void main() color.rgb += halo_22; - color *= 2.; + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index c5d317ad37..c80e7fce18 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -48,21 +48,9 @@ uniform float blur_fidelity; uniform vec4 morphFactor; uniform vec3 camPosLocal; //uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; uniform float max_y; -uniform vec4 glow; uniform float global_gamma; -uniform float scene_light_strength; uniform mat3 env_mat; uniform vec4 shadow_clip; uniform mat3 ssao_effect_mat; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 2a629f4f42..5cf3cd1dd2 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -42,6 +42,7 @@ uniform vec4 glow; uniform float scene_light_strength; uniform mat3 ssao_effect_mat; uniform int no_atmo; +uniform float sun_up_factor; vec3 scaleSoftClipFrag(vec3 light); @@ -117,6 +118,8 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, //add "minimum anti-solar illumination" temp2.x += .25; + + temp2.x *= sun_up_factor; //increase ambient when there are more clouds vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 7a6bcd53a1..8c1a7c6281 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -54,110 +54,112 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; void calcAtmospherics(vec3 inPositionEye) { - vec3 P = inPositionEye; - setPositionEye(P); - - //(TERRAIN) limit altitude - if (P.y > max_y) P *= (max_y / P.y); - if (P.y < -max_y) P *= (-max_y / P.y); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - //vary_AtmosAttenuation = distance_multiplier / 10000.; - //vary_AtmosAttenuation = density_multiplier * 100.; - //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - vec3 additive = - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient)); + vec3 P = inPositionEye; + setPositionEye(P); + + //(TERRAIN) limit altitude + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + //vary_AtmosAttenuation = distance_multiplier / 10000.; + //vary_AtmosAttenuation = density_multiplier * 100.; + //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + temp2.x *= sun_up_factor; + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + vec3 additive = + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient)); additive = normalize(additive); - //haze color - //setAdditiveColor( - // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - // + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); - - // vary_SunlitColor = vec3(0); - // vary_AmblitColor = vec3(0); - // vary_AdditiveColor = vec4(Pn, 1.0); - - /* - const float cloudShadowScale = 100.; - // Get cloud uvs for shadowing - vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; - vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; - - // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) -// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); - vary_CloudUVs *= (10000./40000.); - - // Offset by sun vector * (CloudAltitude / CloudSpan) - vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); - vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); - */ + //haze color + //setAdditiveColor( + // vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + // + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + // + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(additive * vec3(1.0 - exp(-temp2.z * distance_multiplier)) * 0.5); + + // vary_SunlitColor = vec3(0); + // vary_AmblitColor = vec3(0); + // vary_AdditiveColor = vec4(Pn, 1.0); + + /* + const float cloudShadowScale = 100.; + // Get cloud uvs for shadowing + vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; + vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; + + // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) +// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); + vary_CloudUVs *= (10000./40000.); + + // Offset by sun vector * (CloudAltitude / CloudSpan) + vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); + vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); + */ } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index e3fa431ddf..93024bf4e7 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -66,60 +66,65 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; - float cloudDensity = vary_CloudDensity; - vec2 uv3 = vary_texcoord2.xy; - vec2 uv4 = vary_texcoord3.xy; + vec4 cloudColorSun = vary_CloudColorSun; + vec4 cloudColorAmbient = vary_CloudColorAmbient; + float cloudDensity = vary_CloudDensity; + vec2 uv3 = vary_texcoord2.xy; + vec2 uv4 = vary_texcoord3.xy; + + if (cloud_scale < 0.001) + { + discard; + } vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity + // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; - // Combine - vec4 color; - color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color *= 2.; + // Combine + vec4 color; + color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); + color *= 2.; - /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + /// Gamma correct for WL (soft clip effect). + frag_data[0] = vec4(scaleSoftClip(color.rgb), alpha1); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); + frag_data[2] = vec4(0,0,1,0); } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index c1dd45cd67..644cd5a35b 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -57,6 +57,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; +uniform float sun_up_factor; uniform vec4 cloud_color; @@ -65,126 +66,128 @@ uniform float cloud_scale; void main() { - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - vary_texcoord0 = texcoord0; - - // Get relative position - vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); - - // Set altitude - if (P.y > 0.) - { - P *= (max_y / P.y); - } - else - { - P *= (-32000. / P.y); - } - - // Can normalize then - vec3 Pn = normalize(P); - float Plen = length(P); - - // Initialize temp variables - vec4 temp1 = vec4(0.); - vec4 temp2 = vec4(0.); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - - // Calculate relative weights - temp1 = blue_density + haze_density; - blue_weight = blue_density / temp1; - haze_weight = haze_density / temp1; - - // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Distance - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z); - - - // Compute haze glow - temp2.x = dot(Pn, lightnorm.xyz); - temp2.x = 1. - temp2.x; - // temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .001); - // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // Add "minimum anti-solar illumination" - temp2.x += .25; - - // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; - - // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow); - - // Haze color below cloud - vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) - ); - - // CLOUDS - - sunlight = sunlight_color; - temp2.y = max(0., lightnorm.y * 2.); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // Cloud color out - vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; - vary_CloudColorAmbient = tmpAmbient * cloud_color; - - // Attenuate cloud color by atmosphere - temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds - vary_CloudColorSun *= temp1; - vary_CloudColorAmbient *= temp1; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); - - // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow - 0.25); - - - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - - // Combine these to minimize register use - vary_CloudColorAmbient += oHazeColorBelowCloud; - - // needs this to compile on mac - //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); - - // END CLOUDS + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + vary_texcoord0 = texcoord0; + + // Get relative position + vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0); + + // Set altitude + if (P.y > 0.) + { + P *= (max_y / P.y); + } + else + { + P *= (-32000. / P.y); + } + + // Can normalize then + vec3 Pn = normalize(P); + float Plen = length(P); + + // Initialize temp variables + vec4 temp1 = vec4(0.); + vec4 temp2 = vec4(0.); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + + // Sunlight attenuation effect (hue and brightness) due to atmosphere + // this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + + // Calculate relative weights + temp1 = blue_density + haze_density; + blue_weight = blue_density / temp1; + haze_weight = haze_density / temp1; + + // Compute sunlight from P & lightnorm (for long rays like sky) + temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Distance + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z); + + + // Compute haze glow + temp2.x = dot(Pn, lightnorm.xyz); + temp2.x = 1. - temp2.x; + // temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .001); + // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + // glow.z should be negative, so we're doing a sort of (1 / "angle") function + + temp2.x *= sun_up_factor; + + // Add "minimum anti-solar illumination" + temp2.x += .25; + + // Increase ambient when there are more clouds + vec4 tmpAmbient = ambient; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; + + // Dim sunlight by cloud shadow percentage + sunlight *= (1. - cloud_shadow); + + // Haze color below cloud + vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) + ); + + // CLOUDS + + sunlight = sunlight_color; + temp2.y = max(0., lightnorm.y * 2.); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // Cloud color out + vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; + vary_CloudColorAmbient = tmpAmbient * cloud_color; + + // Attenuate cloud color by atmosphere + temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds + vary_CloudColorSun *= temp1; + vary_CloudColorAmbient *= temp1; + vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); + + // Make a nice cloud density based on the cloud_shadow value that was passed in. + vary_CloudDensity = 2. * (cloud_shadow - 0.25); + + + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= max(0.001, cloud_scale); + vary_texcoord0.xy += 0.5; + + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1.y += lightnorm.z * 0.0125; + + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; + + // Combine these to minimize register use + vary_CloudColorAmbient += oHazeColorBelowCloud; + + // needs this to compile on mac + //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); + + // END CLOUDS } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 3788ddaf2d..04cf4052b8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -50,7 +50,7 @@ uniform float density_multiplier; uniform float max_y; uniform vec4 glow; - +uniform float sun_up_factor; uniform vec4 cloud_color; void main() @@ -119,6 +119,8 @@ void main() temp2.x = pow(temp2.x, glow.z); // glow.z should be negative, so we're doing a sort of (1 / "angle") function + temp2.x *= sun_up_factor; + // Add "minimum anti-solar illumination" temp2.x += .25; diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl index 65af2821be..95d5b52b45 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl @@ -67,48 +67,55 @@ vec4 computeMoments(float depth, float alpha); void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); - - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) + if (cloud_scale >= 0.001) { - discard; + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); + + vec2 uv4 = vary_texcoord3.xy; + + vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); + + // Offset texture coords + uv1 += cloud_pos_density1.xy + (disturbance * 0.02); //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow + + float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y)); + + cloudDensity *= 1.0 - (density_variance * density_variance); + + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; + + if (alpha1 < 0.001f) + { + discard; + } + + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; + + frag_color = computeMoments(length(pos), alpha1); + } + else + { + frag_color = vec4(0); } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = computeMoments(length(pos), alpha1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl index 015caad749..c111456782 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl @@ -81,47 +81,52 @@ vec4 cloudNoise(vec2 uv) void main() { - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); + // Set variables + vec2 uv1 = vary_texcoord0.xy; + vec2 uv2 = vary_texcoord1.xy; + vec2 uv3 = vary_texcoord2.xy; + float cloudDensity = 2.0 * (cloud_shadow - 0.25); - vec2 uv4 = vary_texcoord3.xy; + if (cloud_scale < 0.001) + { + discard; + } + + vec2 uv4 = vary_texcoord3.xy; vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - // Offset texture coords - uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow + // Offset texture coords + uv1 += cloud_pos_density1.xy + disturbance; //large texture, visible density + uv2 += cloud_pos_density1.xy; //large texture, self shadow + uv3 += cloud_pos_density2.xy + disturbance; //small texture, visible density + uv4 += cloud_pos_density2.xy; //small texture, self shadow float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0)); cloudDensity *= 1.0 - (density_variance * density_variance); - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); + // Compute alpha1, the main cloud opacity + float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; + alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; + // And smooth + alpha1 = 1. - alpha1 * alpha1; + alpha1 = 1. - alpha1 * alpha1; if (alpha1 < 0.001f) { discard; } - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); + // Compute alpha2, for self shadowing effect + // (1 - alpha2) will later be used as percentage of incoming sunlight + float alpha2 = (cloudNoise(uv2).x - 0.5); + alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; + // And smooth + alpha2 = 1. - alpha2; + alpha2 = 1. - alpha2 * alpha2; vec3 view_ray = vary_pos.xyz + camPosLocal; @@ -135,8 +140,8 @@ void main() vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); - // Combine - vec4 color; + // Combine + vec4 color; vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); @@ -156,8 +161,8 @@ void main() color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); color.rgb += amb; - frag_data[0] = vec4(color.rgb, alpha1); - frag_data[1] = vec4(0); - frag_data[2] = vec4(0,1,0,1); + frag_data[0] = vec4(color.rgb, alpha1); + frag_data[1] = vec4(0); + frag_data[2] = vec4(0,1,0,1); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl index 53b6d88ef5..71e422ddf0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl @@ -49,22 +49,22 @@ void main() { vary_pos = position; - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + // World / view / projection + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale; + // Texture coords + vary_texcoord0 = texcoord0; + vary_texcoord0.xy -= 0.5; + vary_texcoord0.xy /= max(0.001, cloud_scale); vary_texcoord0.xy += 0.5; - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; + vary_texcoord1 = vary_texcoord0; + vary_texcoord1.x += lightnorm.x * 0.0125; vary_texcoord1.y += lightnorm.z * 0.0125; - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; + vary_texcoord2 = vary_texcoord0 * 16.; + vary_texcoord3 = vary_texcoord1 * 16.; - // END CLOUDS + // END CLOUDS } diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index e6306b391a..f9ab241988 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -232,6 +232,8 @@ void LLDrawPoolWLSky::renderSkyHazeAdvanced(const LLVector3& camPosLocal, F32 ca sky_shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); + sky_shader->uniform1f(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1.0f : 0.0f); + sky_shader->uniform3f(sCamPosLocal, camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]); renderFsSky(camPosLocal, camHeightLocal, sky_shader); @@ -266,6 +268,8 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca sky_shader->uniform1f(LLShaderMgr::DROPLET_RADIUS, droplet_radius); sky_shader->uniform1f(LLShaderMgr::ICE_LEVEL, ice_level); + sky_shader->uniform1f(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1.0f : 0.0f); + /// Render the skydome renderDome(origin, camHeightLocal, sky_shader); @@ -475,7 +479,7 @@ void LLDrawPoolWLSky::renderSkyCloudsAdvanced(const LLVector3& camPosLocal, F32 cloudshader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); cloudshader->uniform1f(LLShaderMgr::CLOUD_VARIANCE, cloud_variance); - + cloudshader->uniform1f(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1.0f : 0.0f); cloudshader->uniform3f(sCamPosLocal, camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]); /// Render the skydome @@ -530,6 +534,7 @@ void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32 cloudshader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); cloudshader->uniform1f(LLShaderMgr::CLOUD_VARIANCE, cloud_variance); + cloudshader->uniform1f(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1.0f : 0.0f); /// Render the skydome renderDome(camPosLocal, camHeightLocal, cloudshader); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index af078251b3..7b5a922bbd 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -243,6 +243,16 @@ LLHeavenBody::LLHeavenBody(const F32 rad) mColorCached.setToBlack(); } +const LLQuaternion& LLHeavenBody::getRotation() const +{ + return mRotation; +} + +void LLHeavenBody::setRotation(const LLQuaternion& rot) +{ + mRotation = rot; +} + const LLVector3& LLHeavenBody::getDirection() const { return mDirection; @@ -738,6 +748,9 @@ void LLVOSky::updateDirections(void) mSun.setDirection(psky->getSunDirection()); mMoon.setDirection(psky->getMoonDirection()); + mSun.setRotation(psky->getSunRotation()); + mMoon.setRotation(psky->getMoonRotation()); + mSun.setColor(psky->getSunlightColor()); mMoon.setColor(psky->getMoonDiffuse()); @@ -1199,11 +1212,13 @@ bool LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, F32 scale, const S32 index_offset; LLFace *facep; - LLVector3 to_dir = hb.getDirection(); + LLQuaternion rot = hb.getRotation(); + LLVector3 to_dir = LLVector3::x_axis * rot; + LLVector3 hb_right = LLVector3::y_axis * rot; + LLVector3 hb_up = LLVector3::z_axis * rot; + LLVector3 draw_pos = to_dir * HEAVENLY_BODY_DIST; - LLVector3 hb_right = to_dir % LLVector3::z_axis; - LLVector3 hb_up = hb_right % to_dir; hb_right.normalize(); hb_up.normalize(); diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 0713661295..a9ef5474b6 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -30,6 +30,7 @@ #include "stdtypes.h" #include "v3color.h" #include "v4coloru.h" +#include "llquaternion.h" #include "llviewertexture.h" #include "llviewerobject.h" #include "llframetimer.h" @@ -38,7 +39,7 @@ #include "lllegacyatmospherics.h" const F32 SKY_BOX_MULT = 16.0f; -const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 10.f; +const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 20.f; const F32 HEAVENLY_BODY_FACTOR = 0.1f; const F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR; @@ -132,6 +133,7 @@ protected: LLColor3 mColorCached; F32 mIntensity; LLVector3 mDirection; // direction of the local heavenly body + LLQuaternion mRotation; LLVector3 mAngularVelocity; // velocity of the local heavenly body F32 mDiskRadius; @@ -147,6 +149,9 @@ public: LLHeavenBody(const F32 rad); ~LLHeavenBody() {} + const LLQuaternion& getRotation() const; + void setRotation(const LLQuaternion& rot); + const LLVector3& getDirection() const; void setDirection(const LLVector3 &direction); void setAngularVelocity(const LLVector3 &ang_vel); -- cgit v1.3 From f1ee481b82275cfadbce156514920750ebdd3065 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 31 Jan 2019 14:48:35 -0800 Subject: SL-10443 Fix sun/moon disc geo generation reversing the UVs of the images for same. Remove comment about voidwater when depth clamp is unavailable as it no longer applies. --- indra/newview/llviewerwindow.cpp | 5 ----- indra/newview/llvosky.cpp | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 9be2e905a2..09b681ce74 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -1836,11 +1836,6 @@ LLViewerWindow::LLViewerWindow(const Params& p) LLFeatureManager::getInstance()->applyRecommendedSettings(); gSavedSettings.setBOOL("ProbeHardwareOnStartup", FALSE); } - - if (!gGLManager.mHasDepthClamp) - { - LL_INFOS("RenderInit") << "Missing feature GL_ARB_depth_clamp. Void water might disappear in rare cases." << LL_ENDL; - } // If we crashed while initializng GL stuff last time, disable certain features if (gSavedSettings.getBOOL("RenderInitError")) diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 7b5a922bbd..678f1fe748 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -1213,9 +1213,9 @@ bool LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, F32 scale, const LLFace *facep; LLQuaternion rot = hb.getRotation(); - LLVector3 to_dir = LLVector3::x_axis * rot; - LLVector3 hb_right = LLVector3::y_axis * rot; - LLVector3 hb_up = LLVector3::z_axis * rot; + LLVector3 to_dir = LLVector3::x_axis * rot; + LLVector3 hb_right = LLVector3::y_axis_neg * rot; + LLVector3 hb_up = LLVector3::z_axis * rot; LLVector3 draw_pos = to_dir * HEAVENLY_BODY_DIST; -- cgit v1.3 From e17756e700a47bdb1857551268ee385533c9feca Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 5 Feb 2019 11:13:09 -0800 Subject: SL-10443 Make fix which gets 10276 and 10443, but leaves the bizarre flip at the zenith so that the sun/moon textures are always upright w.r.t the viewer. --- indra/newview/llvosky.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 678f1fe748..96363045d3 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -1212,10 +1212,19 @@ bool LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, F32 scale, const S32 index_offset; LLFace *facep; + LLQuaternion rot = hb.getRotation(); - LLVector3 to_dir = LLVector3::x_axis * rot; - LLVector3 hb_right = LLVector3::y_axis_neg * rot; - LLVector3 hb_up = LLVector3::z_axis * rot; + LLVector3 to_dir = LLVector3::x_axis * rot; + + LLVector3 hb_right = to_dir % LLVector3::z_axis; + LLVector3 hb_up = hb_right % to_dir; + + // at zenith so math below fails spectacularly + if ((to_dir * LLVector3::z_axis) > 0.99f) + { + hb_right = LLVector3::y_axis_neg * rot; + hb_up = LLVector3::z_axis * rot; + } LLVector3 draw_pos = to_dir * HEAVENLY_BODY_DIST; -- cgit v1.3 From 3fa8b844c39311a2e4e319a8d4f7ab2c848ae140 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 02:51:41 -0700 Subject: Fixing gamma correction in EEP Step 1: Thou shall always read the sky cubemap as sRGB using hardware sampling. --- indra/llmath/llmath.h | 20 +++++++++++++++++++ indra/llrender/llcubemap.cpp | 18 ++++++++++------- indra/llrender/llcubemap.h | 3 ++- indra/llrender/llimagegl.cpp | 47 ++++++++++++++++++++++++++++++++++++++++---- indra/newview/llvosky.cpp | 7 ++++++- 5 files changed, 82 insertions(+), 13 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index e508c9a199..bb19248f1f 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -537,6 +537,26 @@ inline void ll_remove_outliers(std::vector& data, F32 k) } } +// This converts from a non-linear sRGB floating point value (0..1) to a linear value. +// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this. +inline float sRGBtoLinear(const float val) { + if (val < 0.0031308f) { + return val * 12.92f; + } + else { + return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; + } +} + +inline float linearTosRGB(const float val) { + if (val < 0.04045f) { + return val / 12.92f; + } + else { + return pow((val + 0.055f) / 1.055f, 2.4f); + } +} + // Include simd math header #include "llsimdmath.h" diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index af4e3fdda0..fcac016ed7 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -53,10 +53,11 @@ const BOOL use_cube_mipmaps = FALSE; //current build works best without cube mi bool LLCubeMap::sUseCubeMaps = true; -LLCubeMap::LLCubeMap() +LLCubeMap::LLCubeMap(bool init_as_srgb) : mTextureStage(0), mTextureCoordStage(0), - mMatrixStage(0) + mMatrixStage(0), + mIssRGB(init_as_srgb) { mTargets[0] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB; mTargets[1] = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB; @@ -82,12 +83,15 @@ void LLCubeMap::initGL() U32 texname = 0; LLImageGL::generateTextures(1, &texname); - + for (int i = 0; i < 6; i++) { - mImages[i] = new LLImageGL(64, 64, 4, (use_cube_mipmaps? TRUE : FALSE)); + mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE); + if (mIssRGB) { + mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); - mRawImages[i] = new LLImageRaw(64, 64, 4); + mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); @@ -154,7 +158,7 @@ void LLCubeMap::initGLData() { for (int i = 0; i < 6; i++) { - mImages[i]->setSubImage(mRawImages[i], 0, 0, 64, 64); + mImages[i]->setSubImage(mRawImages[i], 0, 0, RESOLUTION, RESOLUTION); } } @@ -484,7 +488,7 @@ void LLCubeMap::paintIn(LLVector3 dir[4], const LLColor4U& col) td[offset + cc] = U8((td[offset + cc] + col.mV[cc]) * 0.5); } } - mImages[side]->setSubImage(mRawImages[side], 0, 0, 64, 64); + mImages[side]->setSubImage(mRawImages[side], 0, 0, RESOLUTION, RESOLUTION); } } diff --git a/indra/llrender/llcubemap.h b/indra/llrender/llcubemap.h index ee2c41e026..95b6d12099 100644 --- a/indra/llrender/llcubemap.h +++ b/indra/llrender/llcubemap.h @@ -36,8 +36,9 @@ class LLVector3; // Environment map hack! class LLCubeMap : public LLRefCount { + bool mIssRGB; public: - LLCubeMap(); + LLCubeMap(bool init_as_srgb); void init(const std::vector >& rawimages); void initGL(); void initRawData(const std::vector >& rawimages); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 7d8f512c93..d3f8431654 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -187,15 +187,20 @@ S32 LLImageGL::dataFormatBits(S32 dataformat) switch (dataformat) { case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; case GL_LUMINANCE: return 8; case GL_ALPHA: return 8; case GL_COLOR_INDEX: return 8; case GL_LUMINANCE_ALPHA: return 16; case GL_RGB: return 24; + case GL_SRGB: return 24; case GL_RGB8: return 24; case GL_RGBA: return 32; + case GL_SRGB_ALPHA: return 32; case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac default: LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; @@ -206,11 +211,19 @@ S32 LLImageGL::dataFormatBits(S32 dataformat) //static S32 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height) { - if (dataformat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT && - dataformat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) + switch (dataformat) { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: if (width < 4) width = 4; if (height < 4) height = 4; + break; + default: + break; } S32 bytes ((width*height*dataFormatBits(dataformat)+7)>>3); S32 aligned = (bytes+3)&~3; @@ -223,14 +236,19 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat) switch (dataformat) { case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 3; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 3; case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 4; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 4; case GL_LUMINANCE: return 1; case GL_ALPHA: return 1; case GL_COLOR_INDEX: return 1; case GL_LUMINANCE_ALPHA: return 2; case GL_RGB: return 3; + case GL_SRGB: return 3; case GL_RGBA: return 4; + case GL_SRGB_ALPHA: return 4; case GL_BGRA: return 4; // Used for QuickTime media textures on the Mac default: LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; @@ -650,9 +668,19 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) { LL_RECORD_BLOCK_TIME(FTM_SET_IMAGE); bool is_compressed = false; - if (mFormatPrimary >= GL_COMPRESSED_RGBA_S3TC_DXT1_EXT && mFormatPrimary <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) + + switch (mFormatPrimary) { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: is_compressed = true; + break; + default: + break; } @@ -1227,10 +1255,18 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt case GL_RGB8: intformat = GL_COMPRESSED_RGB; break; + case GL_SRGB: + case GL_SRGB8: + intformat = GL_COMPRESSED_SRGB; + break; case GL_RGBA: case GL_RGBA8: intformat = GL_COMPRESSED_RGBA; break; + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + intformat = GL_COMPRESSED_SRGB_ALPHA; + break; case GL_LUMINANCE: case GL_LUMINANCE8: intformat = GL_COMPRESSED_LUMINANCE; @@ -1798,10 +1834,12 @@ void LLImageGL::calcAlphaChannelOffsetAndStride() mAlphaStride = 2; break; case GL_RGB: + case GL_SRGB: mNeedsAlphaAndPickMask = FALSE ; mIsMask = FALSE; return ; //no alpha channel. case GL_RGBA: + case GL_SRGB_ALPHA: mAlphaStride = 4; break; case GL_BGRA_EXT: @@ -1993,7 +2031,8 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) freePickMask(); if (mFormatType != GL_UNSIGNED_BYTE || - mFormatPrimary != GL_RGBA) + mFormatPrimary != GL_RGBA || + mFormatPrimary != GL_SRGB_ALPHA) { //cannot generate a pick mask for this texture return; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 96363045d3..8bcd875d90 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -207,6 +207,9 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { + if (LLPipeline::RenderDeferred) { + mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } @@ -613,7 +616,9 @@ void LLVOSky::initCubeMap() } else if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) { - mCubeMap = new LLCubeMap(); + bool wantsRGB = LLPipeline::RenderDeferred; + + mCubeMap = new LLCubeMap(wantsRGB); mCubeMap->init(images); } gGL.getTexUnit(0)->disable(); -- cgit v1.3 From 57d88a8a98ef8663b9064b12143beb4068e58f86 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 08:11:56 -0700 Subject: Gamma correction pass 2: Make sure lights are in the correct color space. Bonus: cache the sRGB color in setLightColor on point and spot lights. Frees up a pow and some multiplies on the CPU every frame. --- indra/llmath/v3color.h | 8 ++++++++ indra/llmath/v4color.h | 11 +++++++++++ indra/llmath/v4math.h | 12 ++++++++++++ indra/llprimitive/llprimitive.h | 4 +++- indra/llrender/llrender.cpp | 2 +- indra/newview/lldrawpoolwlsky.cpp | 17 ++++++++++++++--- indra/newview/llvosky.cpp | 3 +++ indra/newview/llvovolume.cpp | 13 +++++++++++++ indra/newview/llvovolume.h | 1 + indra/newview/pipeline.cpp | 21 ++++----------------- 10 files changed, 70 insertions(+), 22 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 43910a1bbe..ac78197510 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -475,5 +475,13 @@ inline LLColor3 lerp(const LLColor3 &a, const LLColor3 &b, F32 u) a.mV[VZ] + (b.mV[VZ] - a.mV[VZ]) * u); } +inline const LLColor3 srgbColor3(const LLColor3 &a) { + LLColor3 srgbColor; + srgbColor.mV[0] = linearTosRGB(a.mV[0]); + srgbColor.mV[1] = linearTosRGB(a.mV[1]); + srgbColor.mV[2] = linearTosRGB(a.mV[2]); + + return srgbColor; +} #endif diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index 614cdc9f3e..d9dd28ec54 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -656,5 +656,16 @@ void LLColor4::clamp() } } +inline const LLColor4 srgbColor4(const LLColor4 &a) { + LLColor4 srgbColor; + + srgbColor.mV[0] = linearTosRGB(a.mV[0]); + srgbColor.mV[1] = linearTosRGB(a.mV[1]); + srgbColor.mV[2] = linearTosRGB(a.mV[2]); + srgbColor.mV[3] = a.mV[3]; + + return srgbColor; +} + #endif diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index 3f6d480ed9..00baeefa5c 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -534,6 +534,18 @@ inline F32 LLVector4::normVec(void) return (mag); } +// Because apparently some parts of the viewer use this for color info. +inline const LLVector4 srgbVector4(const LLVector4 &a) { + LLVector4 srgbColor; + + srgbColor.mV[0] = linearTosRGB(a.mV[0]); + srgbColor.mV[1] = linearTosRGB(a.mV[1]); + srgbColor.mV[2] = linearTosRGB(a.mV[2]); + srgbColor.mV[3] = a.mV[3]; + + return srgbColor; +} + #endif diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h index c138c2ac2b..677606abd1 100644 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -133,6 +133,7 @@ class LLLightParams : public LLNetworkData { protected: LLColor4 mColor; // alpha = intensity + LLColor4 msRGBColor; // Only used in deferred (for now?) F32 mRadius; F32 mFalloff; F32 mCutoff; @@ -150,12 +151,13 @@ public: bool fromLLSD(LLSD& sd); - void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); } + void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); msRGBColor = srgbColor4(mColor); } void setRadius(F32 radius) { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); } void setFalloff(F32 falloff) { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); } void setCutoff(F32 cutoff) { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); } LLColor4 getColor() const { return mColor; } + LLColor4 getsRGBColor() const { return msRGBColor; } F32 getRadius() const { return mRadius; } F32 getFalloff() const { return mFalloff; } F32 getCutoff() const { return mCutoff; } diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 2bf7ad9902..fe6010fabd 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1193,7 +1193,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); - shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); + shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, srgbColor4(mAmbientLightColor).mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index e608f6eaf2..7f59852b62 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -503,7 +503,12 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() LLColor4 color(gSky.mVOSkyp->getSun().getInterpColor()); - sun_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + if (LLPipeline::RenderDeferred) { + sun_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, srgbColor4(color).mV); + } + else { + sun_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + } sun_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); LLFacePool::LLOverrideFaceColor color_override(this, color); @@ -554,9 +559,15 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() F32 moon_brightness = (float)psky->getMoonBrightness(); moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness); - moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV); - moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + if (LLPipeline::RenderDeferred) { + moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, srgbColor4(gSky.mVOSkyp->getMoon().getColor()).mV); + moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, srgbColor4(color).mV); + } + else { + moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV); + moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + } moon_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); LLFacePool::LLOverrideFaceColor color_override(this, color); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 8bcd875d90..954a590682 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -210,6 +210,9 @@ void LLSkyTex::createGLImage(S32 which) if (LLPipeline::RenderDeferred) { mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); } + else { + mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); + } mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 4ddd9c4568..85bc1ba845 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -3239,6 +3239,19 @@ LLColor3 LLVOVolume::getLightColor() const } } +LLColor3 LLVOVolume::getLightsRGBColor() const +{ + const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT); + if (param_block) + { + return LLColor3(param_block->getsRGBColor()) * param_block->getsRGBColor().mV[3]; + } + else + { + return LLColor3(1, 1, 1); + } +} + LLUUID LLVOVolume::getLightTextureID() const { if (getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE)) diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h index 0882fc095d..aeabcda911 100644 --- a/indra/newview/llvovolume.h +++ b/indra/newview/llvovolume.h @@ -251,6 +251,7 @@ public: BOOL getIsLight() const; LLColor3 getLightBaseColor() const; // not scaled by intensity LLColor3 getLightColor() const; // scaled by intensity + LLColor3 getLightsRGBColor() const; // Used to get the (cached) light color in sRGB color space. Also scaled by intensity. LLUUID getLightTextureID() const; bool isLightSpotlight() const; LLVector3 getSpotLightParams() const; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 658410fd3d..2a7cac3eda 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8368,7 +8368,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff); shader.uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, mSunDiffuse.mV); - shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonDiffuse.mV); + shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, srgbColor4(mMoonDiffuse).mV); LLEnvironment& environment = LLEnvironment::instance(); shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0); @@ -8705,7 +8705,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) const F32* c = center.getF32ptr(); F32 s = volume->getLightRadius(); - LLColor3 col = volume->getLightColor(); + LLColor3 col = volume->getLightsRGBColor(); if (col.magVecSquared() < 0.001f) { @@ -8742,10 +8742,6 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) continue; } - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ - LL_RECORD_BLOCK_TIME(FTM_LOCAL_LIGHTS); gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); @@ -8801,7 +8797,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) setupSpotLight(gDeferredSpotLightProgram, drawablep); - LLColor3 col = volume->getLightColor(); + LLColor3 col = volume->getLightsRGBColor(); /*col.mV[0] = powf(col.mV[0], 2.2f); col.mV[1] = powf(col.mV[1], 2.2f); col.mV[2] = powf(col.mV[2], 2.2f);*/ @@ -8850,12 +8846,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) col[count] = light_colors.front(); light_colors.pop_front(); - /*col[count].mV[0] = powf(col[count].mV[0], 2.2f); - col[count].mV[1] = powf(col[count].mV[1], 2.2f); - col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/ - far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z); - //col[count] = pow4fsrgb(col[count], 2.2f); count++; if (count == max_count || fullscreen_lights.empty()) { @@ -8897,11 +8888,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) setupSpotLight(gDeferredMultiSpotLightProgram, drawablep); - LLColor3 col = volume->getLightColor(); - - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ + LLColor3 col = volume->getLightsRGBColor(); gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); -- cgit v1.3 From 0272c47e5a31cf972e02fbf14cb2642f86f75d78 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 29 Mar 2019 11:57:45 -0700 Subject: Tweaked naming a bit, also white space. Will wait for a response from @graham_linden regarding moving the sRGB conversion functions in llmath.h to llrender. --- indra/llmath/llmath.h | 24 +++--- indra/llmath/v4color.h | 12 +-- indra/llmath/v4math.h | 12 +-- indra/llprimitive/llprimitive.h | 10 +-- indra/llrender/llcubemap.cpp | 6 +- indra/llrender/llimagegl.cpp | 176 +++++++++++++++++++------------------- indra/llrender/llrender.cpp | 2 +- indra/newview/lldrawpoolwlsky.cpp | 8 +- indra/newview/llvosky.cpp | 18 ++-- indra/newview/llvovolume.cpp | 20 ++--- indra/newview/llvovolume.h | 2 +- indra/newview/pipeline.cpp | 11 +-- 12 files changed, 149 insertions(+), 152 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index bb19248f1f..57f2489a2d 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -540,21 +540,21 @@ inline void ll_remove_outliers(std::vector& data, F32 k) // This converts from a non-linear sRGB floating point value (0..1) to a linear value. // Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this. inline float sRGBtoLinear(const float val) { - if (val < 0.0031308f) { - return val * 12.92f; - } - else { - return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; - } + if (val < 0.0031308f) { + return val * 12.92f; + } + else { + return 1.055f * pow(val, 1.0f / 2.4f) - 0.055f; + } } inline float linearTosRGB(const float val) { - if (val < 0.04045f) { - return val / 12.92f; - } - else { - return pow((val + 0.055f) / 1.055f, 2.4f); - } + if (val < 0.04045f) { + return val / 12.92f; + } + else { + return pow((val + 0.055f) / 1.055f, 2.4f); + } } // Include simd math header diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index d9dd28ec54..6b91b4f191 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -657,14 +657,14 @@ void LLColor4::clamp() } inline const LLColor4 srgbColor4(const LLColor4 &a) { - LLColor4 srgbColor; + LLColor4 srgbColor; - srgbColor.mV[0] = linearTosRGB(a.mV[0]); - srgbColor.mV[1] = linearTosRGB(a.mV[1]); - srgbColor.mV[2] = linearTosRGB(a.mV[2]); - srgbColor.mV[3] = a.mV[3]; + srgbColor.mV[0] = linearTosRGB(a.mV[0]); + srgbColor.mV[1] = linearTosRGB(a.mV[1]); + srgbColor.mV[2] = linearTosRGB(a.mV[2]); + srgbColor.mV[3] = a.mV[3]; - return srgbColor; + return srgbColor; } #endif diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index 00baeefa5c..b8835ba2e4 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -536,14 +536,14 @@ inline F32 LLVector4::normVec(void) // Because apparently some parts of the viewer use this for color info. inline const LLVector4 srgbVector4(const LLVector4 &a) { - LLVector4 srgbColor; + LLVector4 srgbColor; - srgbColor.mV[0] = linearTosRGB(a.mV[0]); - srgbColor.mV[1] = linearTosRGB(a.mV[1]); - srgbColor.mV[2] = linearTosRGB(a.mV[2]); - srgbColor.mV[3] = a.mV[3]; + srgbColor.mV[0] = linearTosRGB(a.mV[0]); + srgbColor.mV[1] = linearTosRGB(a.mV[1]); + srgbColor.mV[2] = linearTosRGB(a.mV[2]); + srgbColor.mV[3] = a.mV[3]; - return srgbColor; + return srgbColor; } diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h index 677606abd1..619a9f8ca5 100644 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -133,7 +133,7 @@ class LLLightParams : public LLNetworkData { protected: LLColor4 mColor; // alpha = intensity - LLColor4 msRGBColor; // Only used in deferred (for now?) + LLColor4 mSRGBColor; // Only used in deferred (for now?) F32 mRadius; F32 mFalloff; F32 mCutoff; @@ -150,14 +150,14 @@ public: operator LLSD() const { return asLLSD(); } bool fromLLSD(LLSD& sd); - - void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); msRGBColor = srgbColor4(mColor); } + + void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); mSRGBColor = srgbColor4(mColor); } void setRadius(F32 radius) { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); } void setFalloff(F32 falloff) { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); } void setCutoff(F32 cutoff) { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); } - LLColor4 getColor() const { return mColor; } - LLColor4 getsRGBColor() const { return msRGBColor; } + LLColor4 getColor() const { return mColor; } + LLColor4 getSRGBColor() const { return mSRGBColor; } F32 getRadius() const { return mRadius; } F32 getFalloff() const { return mFalloff; } F32 getCutoff() const { return mCutoff; } diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index fcac016ed7..14d0a744bb 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -87,9 +87,9 @@ void LLCubeMap::initGL() for (int i = 0; i < 6; i++) { mImages[i] = new LLImageGL(RESOLUTION, RESOLUTION, 4, FALSE); - if (mIssRGB) { - mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); - } + if (mIssRGB) { + mImages[i]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP); mRawImages[i] = new LLImageRaw(RESOLUTION, RESOLUTION, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index d3f8431654..2d526a2113 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -184,47 +184,47 @@ void LLImageGL::cleanupClass() //static S32 LLImageGL::dataFormatBits(S32 dataformat) { - switch (dataformat) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; - case GL_LUMINANCE: return 8; - case GL_ALPHA: return 8; - case GL_COLOR_INDEX: return 8; - case GL_LUMINANCE_ALPHA: return 16; - case GL_RGB: return 24; - case GL_SRGB: return 24; - case GL_RGB8: return 24; - case GL_RGBA: return 32; - case GL_SRGB_ALPHA: return 32; - case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac - default: - LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; - return 0; - } + switch (dataformat) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: return 4; + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: return 8; + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return 8; + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: return 8; + case GL_LUMINANCE: return 8; + case GL_ALPHA: return 8; + case GL_COLOR_INDEX: return 8; + case GL_LUMINANCE_ALPHA: return 16; + case GL_RGB: return 24; + case GL_SRGB: return 24; + case GL_RGB8: return 24; + case GL_RGBA: return 32; + case GL_SRGB_ALPHA: return 32; + case GL_BGRA: return 32; // Used for QuickTime media textures on the Mac + default: + LL_ERRS() << "LLImageGL::Unknown format: " << dataformat << LL_ENDL; + return 0; + } } //static S32 LLImageGL::dataFormatBytes(S32 dataformat, S32 width, S32 height) { - switch (dataformat) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - if (width < 4) width = 4; - if (height < 4) height = 4; - break; - default: - break; - } + switch (dataformat) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + if (width < 4) width = 4; + if (height < 4) height = 4; + break; + default: + break; + } S32 bytes ((width*height*dataFormatBits(dataformat)+7)>>3); S32 aligned = (bytes+3)&~3; return aligned; @@ -669,19 +669,19 @@ BOOL LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) LL_RECORD_BLOCK_TIME(FTM_SET_IMAGE); bool is_compressed = false; - switch (mFormatPrimary) - { - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: - is_compressed = true; - break; - default: - break; - } + switch (mFormatPrimary) + { + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + is_compressed = true; + break; + default: + break; + } @@ -1255,18 +1255,18 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt case GL_RGB8: intformat = GL_COMPRESSED_RGB; break; - case GL_SRGB: - case GL_SRGB8: - intformat = GL_COMPRESSED_SRGB; - break; + case GL_SRGB: + case GL_SRGB8: + intformat = GL_COMPRESSED_SRGB; + break; case GL_RGBA: case GL_RGBA8: intformat = GL_COMPRESSED_RGBA; break; - case GL_SRGB_ALPHA: - case GL_SRGB8_ALPHA8: - intformat = GL_COMPRESSED_SRGB_ALPHA; - break; + case GL_SRGB_ALPHA: + case GL_SRGB8_ALPHA8: + intformat = GL_COMPRESSED_SRGB_ALPHA; + break; case GL_LUMINANCE: case GL_LUMINANCE8: intformat = GL_COMPRESSED_LUMINANCE; @@ -1824,30 +1824,30 @@ void LLImageGL::calcAlphaChannelOffsetAndStride() } mAlphaStride = -1 ; - switch (mFormatPrimary) - { - case GL_LUMINANCE: - case GL_ALPHA: - mAlphaStride = 1; - break; - case GL_LUMINANCE_ALPHA: - mAlphaStride = 2; - break; - case GL_RGB: - case GL_SRGB: - mNeedsAlphaAndPickMask = FALSE ; - mIsMask = FALSE; - return ; //no alpha channel. - case GL_RGBA: - case GL_SRGB_ALPHA: - mAlphaStride = 4; - break; - case GL_BGRA_EXT: - mAlphaStride = 4; - break; - default: - break; - } + switch (mFormatPrimary) + { + case GL_LUMINANCE: + case GL_ALPHA: + mAlphaStride = 1; + break; + case GL_LUMINANCE_ALPHA: + mAlphaStride = 2; + break; + case GL_RGB: + case GL_SRGB: + mNeedsAlphaAndPickMask = FALSE; + mIsMask = FALSE; + return; //no alpha channel. + case GL_RGBA: + case GL_SRGB_ALPHA: + mAlphaStride = 4; + break; + case GL_BGRA_EXT: + mAlphaStride = 4; + break; + default: + break; + } mAlphaOffset = -1 ; if (mFormatType == GL_UNSIGNED_BYTE) @@ -2030,13 +2030,13 @@ void LLImageGL::updatePickMask(S32 width, S32 height, const U8* data_in) freePickMask(); - if (mFormatType != GL_UNSIGNED_BYTE || - mFormatPrimary != GL_RGBA || - mFormatPrimary != GL_SRGB_ALPHA) - { - //cannot generate a pick mask for this texture - return; - } + if (mFormatType != GL_UNSIGNED_BYTE || + mFormatPrimary != GL_RGBA || + mFormatPrimary != GL_SRGB_ALPHA) + { + //cannot generate a pick mask for this texture + return; + } #ifdef SHOW_ASSERT const U32 pickSize = createPickMask(width, height); diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index fe6010fabd..2bf7ad9902 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1193,7 +1193,7 @@ void LLRender::syncLightState() shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); - shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, srgbColor4(mAmbientLightColor).mV); + shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index f674766935..a3aa0e289f 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -503,7 +503,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() LLColor4 color(gSky.mVOSkyp->getSun().getInterpColor()); - sun_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + sun_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); sun_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); LLFacePool::LLOverrideFaceColor color_override(this, color); @@ -553,9 +553,9 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() F32 moon_brightness = (float)psky->getMoonBrightness(); - moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness); - moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV); - moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); + moon_shader->uniform1f(LLShaderMgr::MOON_BRIGHTNESS, moon_brightness); + moon_shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, gSky.mVOSkyp->getMoon().getColor().mV); + moon_shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV); moon_shader->uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor); LLFacePool::LLOverrideFaceColor color_override(this, color); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 954a590682..a181fdaf50 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -207,12 +207,12 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { - if (LLPipeline::RenderDeferred) { - mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); - } - else { - mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); - } + if (LLPipeline::RenderDeferred) { + mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } + else { + mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); + } mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } @@ -619,10 +619,10 @@ void LLVOSky::initCubeMap() } else if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) { - bool wantsRGB = LLPipeline::RenderDeferred; + bool wantsRGB = LLPipeline::RenderDeferred; - mCubeMap = new LLCubeMap(wantsRGB); - mCubeMap->init(images); + mCubeMap = new LLCubeMap(wantsRGB); + mCubeMap->init(images); } gGL.getTexUnit(0)->disable(); } diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 16fca58f8c..1fd7c7d3ce 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -3239,17 +3239,17 @@ LLColor3 LLVOVolume::getLightColor() const } } -LLColor3 LLVOVolume::getLightsRGBColor() const +LLColor3 LLVOVolume::getLightSRGBColor() const { - const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT); - if (param_block) - { - return LLColor3(param_block->getsRGBColor()) * param_block->getsRGBColor().mV[3]; - } - else - { - return LLColor3(1, 1, 1); - } + const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT); + if (param_block) + { + return LLColor3(param_block->getSRGBColor()) * param_block->getSRGBColor().mV[3]; + } + else + { + return LLColor3(1, 1, 1); + } } LLUUID LLVOVolume::getLightTextureID() const diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h index aeabcda911..da2b086f4a 100644 --- a/indra/newview/llvovolume.h +++ b/indra/newview/llvovolume.h @@ -251,7 +251,7 @@ public: BOOL getIsLight() const; LLColor3 getLightBaseColor() const; // not scaled by intensity LLColor3 getLightColor() const; // scaled by intensity - LLColor3 getLightsRGBColor() const; // Used to get the (cached) light color in sRGB color space. Also scaled by intensity. + LLColor3 getLightSRGBColor() const; // Used to get the (cached) light color in sRGB color space. Also scaled by intensity. LLUUID getLightTextureID() const; bool isLightSpotlight() const; LLVector3 getSpotLightParams() const; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index b8c8a42125..f84cd594c9 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8368,7 +8368,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff); shader.uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, mSunDiffuse.mV); - shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, srgbColor4(mMoonDiffuse).mV); + shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonDiffuse.mV); LLEnvironment& environment = LLEnvironment::instance(); shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0); @@ -8705,7 +8705,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) const F32* c = center.getF32ptr(); F32 s = volume->getLightRadius()*1.5f; - LLColor3 col = volume->getLightsRGBColor(); + LLColor3 col = volume->getLightSRGBColor(); if (col.magVecSquared() < 0.001f) { @@ -8797,10 +8797,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) setupSpotLight(gDeferredSpotLightProgram, drawablep); - LLColor3 col = volume->getLightsRGBColor(); - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ + LLColor3 col = volume->getLightSRGBColor(); gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); @@ -8888,7 +8885,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) setupSpotLight(gDeferredMultiSpotLightProgram, drawablep); - LLColor3 col = volume->getLightsRGBColor(); + LLColor3 col = volume->getLightSRGBColor(); gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); -- cgit v1.3 From 27c96405a489327302ebeb7d192788447932d7f1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 13 May 2019 09:49:53 -0700 Subject: SL-10996 Restore old sun matrix gen code. Make sky use correct colorspace. Make sunlight color the CPU-generated WL color when not using atmo shaders or deferred (helps 11107). --- .../shaders/class1/deferred/shadowUtil.glsl | 2 +- .../shaders/class2/deferred/softenLightF.glsl | 8 +- indra/newview/llvosky.cpp | 8 +- indra/newview/pipeline.cpp | 1376 +++++++++----------- 4 files changed, 662 insertions(+), 732 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index bea016300d..4134220306 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -50,7 +50,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, { float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; - stc.z += offset * 3.0; + stc.z += offset * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 03e5143fca..e41b4b99a3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -190,11 +190,10 @@ vec3 post_atmo = color.rgb; bloom = fogged.a; #endif +// srgb colorspace debuggables //color.rgb = amblit; -//color.rgb = vec3(ambient); //color.rgb = sunlit; //color.rgb = post_ambient; -//color.rgb = vec3(final_da); //color.rgb = sun_contrib; //color.rgb = post_sunlight; //color.rgb = diffuse_srgb.rgb; @@ -208,6 +207,11 @@ vec3 post_atmo = color.rgb; color.rgb = srgb_to_linear(color.rgb); } +// linear debuggables +//color.rgb = vec3(final_da); +//color.rgb = vec3(ambient); +//color.rgb = vec3(scol); + frag_color.rgb = color.rgb; frag_color.a = bloom; } diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index a181fdaf50..7e0f377953 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -207,10 +207,14 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { - if (LLPipeline::RenderDeferred) { +#if USE_SRGB_DECODE + if (LLPipeline::RenderDeferred) + { mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); } - else { + else +#endif + { mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); } mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 211993fb46..7578d6a647 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -6215,7 +6215,16 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) mMoonDir.setVec(moon_dir); // calculates diffuse sunlight per-pixel downstream, just provide setting sunlight_color - mSunDiffuse.setVec(psky->getSunlightColor()); + if (canUseWindLightShaders()) + { + mSunDiffuse.setVec(psky->getSunlightColor()); + } + else + { + // not using atmo shaders, use CPU-generated attenuated sunlight diffuse... + mSunDiffuse.setVec(psky->getSunDiffuse()); + } + mMoonDiffuse.setVec(psky->getMoonDiffuse()); F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]); @@ -7551,7 +7560,7 @@ void LLPipeline::renderBloom(bool for_snapshot, F32 zoom_factor, int subfield) gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA); - mScreen.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR); + mScreen.bindTexture(0, 0, LLTexUnit::TFO_POINT); gGL.color4f(1,1,1,1); gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); @@ -7784,7 +7793,7 @@ void LLPipeline::renderBloom(bool for_snapshot, F32 zoom_factor, int subfield) S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mScreen.getUsage()); if (channel > -1) { - mScreen.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR); + mScreen.bindTexture(0, channel); } shader->uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_distance/1000.f); @@ -7823,7 +7832,7 @@ void LLPipeline::renderBloom(bool for_snapshot, F32 zoom_factor, int subfield) S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredLight.getUsage()); if (channel > -1) { - mDeferredLight.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR); + mDeferredLight.bindTexture(0, channel); } shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF); @@ -7915,7 +7924,7 @@ void LLPipeline::renderBloom(bool for_snapshot, F32 zoom_factor, int subfield) S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mScreen.getUsage()); if (channel > -1) { - mScreen.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR); + mScreen.bindTexture(0, channel); } if (!LLViewerCamera::getInstance()->cameraUnderWater()) @@ -7962,7 +7971,7 @@ void LLPipeline::renderBloom(bool for_snapshot, F32 zoom_factor, int subfield) S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mDeferredLight.getUsage()); if (channel > -1) { - mDeferredLight.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR); + mDeferredLight.bindTexture(0, channel); } gGL.begin(LLRender::TRIANGLE_STRIP); @@ -8217,7 +8226,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ channel = shader.enableTexture(LLShaderMgr::DEFERRED_BLOOM); if (channel > -1) { - mGlow[1].bindTexture(0, channel, LLTexUnit::TFO_BILINEAR); + mGlow[1].bindTexture(0, channel); } stop_glerror(); @@ -10019,862 +10028,775 @@ static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW_SPOT_RENDER("Spot Shadow void LLPipeline::generateSunShadow(LLCamera& camera) { - if (!sRenderDeferred || RenderShadowDetail <= 0) - { - if (mNeedsShadowTargetClear) - { - LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); - - for (S32 j = 0; j < 6; j++) - { - LLRenderTarget* shadow_target = getShadowTarget(j); - if (shadow_target) - { - shadow_target->bindTarget(); - shadow_target->clear(); - shadow_target->flush(); - } - } - mNeedsShadowTargetClear = false; - } - - return; - } - - mNeedsShadowTargetClear = true; - - LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW); - - LLEnvironment& environment = LLEnvironment::instance(); - LLSettingsSky::ptr_t psky = environment.getCurrentSky(); - - bool skip_avatar_update = false; - if (!isAgentAvatarValid() || gAgentCamera.getCameraAnimating() || gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK || !LLVOAvatar::sVisibleInFirstPerson) - { - skip_avatar_update = true; - } - - F64 last_modelview[16]; - F64 last_projection[16]; - for (U32 i = 0; i < 16; i++) - { //store last_modelview of world camera - last_modelview[i] = gGLLastModelView[i]; - last_projection[i] = gGLLastProjection[i]; - } - - pushRenderTypeMask(); - andRenderTypeMask(LLPipeline::RENDER_TYPE_SIMPLE, - LLPipeline::RENDER_TYPE_ALPHA, - LLPipeline::RENDER_TYPE_GRASS, - LLPipeline::RENDER_TYPE_FULLBRIGHT, - LLPipeline::RENDER_TYPE_BUMP, - LLPipeline::RENDER_TYPE_VOLUME, - LLPipeline::RENDER_TYPE_AVATAR, - LLPipeline::RENDER_TYPE_TREE, - LLPipeline::RENDER_TYPE_TERRAIN, - LLPipeline::RENDER_TYPE_WATER, - LLPipeline::RENDER_TYPE_VOIDWATER, - LLPipeline::RENDER_TYPE_PASS_ALPHA, - LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_GRASS, - LLPipeline::RENDER_TYPE_PASS_SIMPLE, - LLPipeline::RENDER_TYPE_PASS_BUMP, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, - LLPipeline::RENDER_TYPE_PASS_SHINY, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, - LLPipeline::RENDER_TYPE_PASS_MATERIAL, - LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA, - LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE, - LLPipeline::RENDER_TYPE_PASS_SPECMAP, - LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND, - LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK, - LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE, - LLPipeline::RENDER_TYPE_PASS_NORMMAP, - LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND, - LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK, - LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE, - LLPipeline::RENDER_TYPE_PASS_NORMSPEC, - LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND, - LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK, - LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE, - END_RENDER_TYPES); - - S32 shadow_detail = gSavedSettings.getS32("RenderShadowDetail"); - - // if not using VSM, disable color writes - if (shadow_detail <= 2) - { - gGL.setColorMask(false, false); - } + if (!sRenderDeferred || RenderShadowDetail <= 0) + { + return; + } - bool sun_up = environment.getIsSunUp(); - bool moon_up = environment.getIsMoonUp(); + LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW); - bool ignore_shadows = (shadow_detail == 0); // explicitly disabled shadows + bool skip_avatar_update = false; + if (!isAgentAvatarValid() || gAgentCamera.getCameraAnimating() || gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK || !LLVOAvatar::sVisibleInFirstPerson) + { - // no sun or moon, no shadows - if (!sun_up && !moon_up) - { - ignore_shadows |= true; - } - // only moon and moon is black - else if (!sun_up && moon_up & (mMoonDiffuse == LLColor4::black)) - { - ignore_shadows |= true; - } - // only sun and sun is black - else if (!moon_up && sun_up && (mSunDiffuse == LLColor4::black)) - { - ignore_shadows |= true; - } - // both up, but both black - else if ((mSunDiffuse == LLColor4::black) && (mMoonDiffuse == LLColor4::black)) - { - ignore_shadows |= true; - } + skip_avatar_update = true; + } - if (ignore_shadows) - { //sun diffuse is totally black, shadows don't matter - LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); + if (!skip_avatar_update) + { + gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON); + } - for (S32 j = 0; j < 4; j++) - { - LLRenderTarget* shadow_target = getShadowTarget(j); - if (shadow_target) - { - shadow_target->bindTarget(); - shadow_target->clear(); - shadow_target->flush(); - } - } + F64 last_modelview[16]; + F64 last_projection[16]; + for (U32 i = 0; i < 16; i++) + { //store last_modelview of world camera + last_modelview[i] = gGLLastModelView[i]; + last_projection[i] = gGLLastProjection[i]; + } - if (shadow_detail == 0) - { - for (S32 j = 4; j < 6; j++) - { - LLRenderTarget* shadow_target = getShadowTarget(j); - if (shadow_target) - { - shadow_target->bindTarget(); - shadow_target->clear(); - shadow_target->flush(); - } - } - } - } + pushRenderTypeMask(); + andRenderTypeMask(LLPipeline::RENDER_TYPE_SIMPLE, + LLPipeline::RENDER_TYPE_ALPHA, + LLPipeline::RENDER_TYPE_GRASS, + LLPipeline::RENDER_TYPE_FULLBRIGHT, + LLPipeline::RENDER_TYPE_BUMP, + LLPipeline::RENDER_TYPE_VOLUME, + LLPipeline::RENDER_TYPE_AVATAR, + LLPipeline::RENDER_TYPE_TREE, + LLPipeline::RENDER_TYPE_TERRAIN, + LLPipeline::RENDER_TYPE_WATER, + LLPipeline::RENDER_TYPE_VOIDWATER, + LLPipeline::RENDER_TYPE_PASS_ALPHA, + LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_GRASS, + LLPipeline::RENDER_TYPE_PASS_SIMPLE, + LLPipeline::RENDER_TYPE_PASS_BUMP, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, + LLPipeline::RENDER_TYPE_PASS_SHINY, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, + LLPipeline::RENDER_TYPE_PASS_MATERIAL, + LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA, + LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE, + LLPipeline::RENDER_TYPE_PASS_SPECMAP, + LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND, + LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK, + LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE, + LLPipeline::RENDER_TYPE_PASS_NORMMAP, + LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND, + LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK, + LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE, + LLPipeline::RENDER_TYPE_PASS_NORMSPEC, + LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND, + LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK, + LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE, + END_RENDER_TYPES); + + gGL.setColorMask(false, false); - //get sun view matrix - - //store current projection/modelview matrix - glh::matrix4f saved_proj = get_current_projection(); - glh::matrix4f saved_view = get_current_modelview(); - glh::matrix4f inv_view = saved_view.inverse(); + LLEnvironment& environment = LLEnvironment::instance(); - glh::matrix4f view[6]; - glh::matrix4f proj[6]; - - //clip contains parallel split distances for 3 splits - LLVector3 clip = RenderShadowClipPlanes; + //get sun view matrix + + //store current projection/modelview matrix + glh::matrix4f saved_proj = get_current_projection(); + glh::matrix4f saved_view = get_current_modelview(); + glh::matrix4f inv_view = saved_view.inverse(); - //F32 slope_threshold = gSavedSettings.getF32("RenderShadowSlopeThreshold"); + glh::matrix4f view[6]; + glh::matrix4f proj[6]; + + //clip contains parallel split distances for 3 splits + LLVector3 clip = RenderShadowClipPlanes; - //far clip on last split is minimum of camera view distance and 128 - mSunClipPlanes = LLVector4(clip, clip.mV[2] * clip.mV[2]/clip.mV[1]); + LLVector3 caster_dir(environment.getIsSunUp() ? mSunDir : mMoonDir); - clip = RenderShadowOrthoClipPlanes; - mSunOrthoClipPlanes = LLVector4(clip, clip.mV[2]*clip.mV[2]/clip.mV[1]); + //F32 slope_threshold = gSavedSettings.getF32("RenderShadowSlopeThreshold"); - //currently used for amount to extrude frusta corners for constructing shadow frusta - //LLVector3 n = RenderShadowNearDist; - //F32 nearDist[] = { n.mV[0], n.mV[1], n.mV[2], n.mV[2] }; + //far clip on last split is minimum of camera view distance and 128 + mSunClipPlanes = LLVector4(clip, clip.mV[2] * clip.mV[2]/clip.mV[1]); - LLVector3 caster_dir(environment.getIsSunUp() ? mSunDir : mMoonDir); + clip = RenderShadowOrthoClipPlanes; + mSunOrthoClipPlanes = LLVector4(clip, clip.mV[2]*clip.mV[2]/clip.mV[1]); - //put together a universal "near clip" plane for shadow frusta - LLPlane shadow_near_clip; - { - LLVector3 p = gAgent.getPositionAgent(); - p += caster_dir * RenderFarClip*2.f; - shadow_near_clip.setVec(p, caster_dir); - } + //currently used for amount to extrude frusta corners for constructing shadow frusta + //LLVector3 n = RenderShadowNearDist; + //F32 nearDist[] = { n.mV[0], n.mV[1], n.mV[2], n.mV[2] }; - LLVector3 lightDir = -caster_dir; - lightDir.normVec(); + //put together a universal "near clip" plane for shadow frusta + LLPlane shadow_near_clip; + { + LLVector3 p = gAgent.getPositionAgent(); + p += caster_dir * RenderFarClip*2.f; + shadow_near_clip.setVec(p, caster_dir); + } - glh::vec3f light_dir(lightDir.mV); + LLVector3 lightDir = -caster_dir; + lightDir.normVec(); - //create light space camera matrix - - LLVector3 at = lightDir; + glh::vec3f light_dir(lightDir.mV); - LLVector3 up = camera.getAtAxis(); + //create light space camera matrix + + LLVector3 at = lightDir; - if (fabsf(up*lightDir) > 0.75f) - { - up = camera.getUpAxis(); - } + LLVector3 up = camera.getAtAxis(); - /*LLVector3 left = up%at; - up = at%left;*/ + if (fabsf(up*lightDir) > 0.75f) + { + up = camera.getUpAxis(); + } - up.normVec(); - at.normVec(); - - LLCamera main_camera = camera; - - F32 near_clip = 0.f; - { - //get visible point cloud - std::vector fp; + /*LLVector3 left = up%at; + up = at%left;*/ - main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum); - - LLVector3 min,max; - getVisiblePointCloud(main_camera,min,max,fp); + up.normVec(); + at.normVec(); + + + LLCamera main_camera = camera; + + F32 near_clip = 0.f; + { + //get visible point cloud + std::vector fp; - if (fp.empty()) - { - if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowCamera[0] = main_camera; - mShadowExtents[0][0] = min; - mShadowExtents[0][1] = max; - - mShadowFrustPoints[0].clear(); - mShadowFrustPoints[1].clear(); - mShadowFrustPoints[2].clear(); - mShadowFrustPoints[3].clear(); - } - popRenderTypeMask(); + main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum); + + LLVector3 min,max; + getVisiblePointCloud(main_camera,min,max,fp); - if (!skip_avatar_update) - { - gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode()); - } + if (fp.empty()) + { + if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowCamera[0] = main_camera; + mShadowExtents[0][0] = min; + mShadowExtents[0][1] = max; - return; - } + mShadowFrustPoints[0].clear(); + mShadowFrustPoints[1].clear(); + mShadowFrustPoints[2].clear(); + mShadowFrustPoints[3].clear(); + } + popRenderTypeMask(); - //get good split distances for frustum - for (U32 i = 0; i < fp.size(); ++i) - { - glh::vec3f v(fp[i].mV); - saved_view.mult_matrix_vec(v); - fp[i].setVec(v.v); - } + if (!skip_avatar_update) + { + gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode()); + } - min = fp[0]; - max = fp[0]; + return; + } - //get camera space bounding box - for (U32 i = 1; i < fp.size(); ++i) - { - update_min_max(min, max, fp[i]); - } + //get good split distances for frustum + for (U32 i = 0; i < fp.size(); ++i) + { + glh::vec3f v(fp[i].mV); + saved_view.mult_matrix_vec(v); + fp[i].setVec(v.v); + } - near_clip = -max.mV[2]; - F32 far_clip = -min.mV[2]*2.f; + min = fp[0]; + max = fp[0]; - //far_clip = llmin(far_clip, 128.f); - far_clip = llmin(far_clip, camera.getFar()); + //get camera space bounding box + for (U32 i = 1; i < fp.size(); ++i) + { + update_min_max(min, max, fp[i]); + } - F32 range = far_clip-near_clip; + near_clip = llclamp(-max.mV[2], 0.01f, 4.0f); + F32 far_clip = llclamp(-min.mV[2]*2.f, 16.0f, 512.0f); - LLVector3 split_exp = RenderShadowSplitExponent; + //far_clip = llmin(far_clip, 128.f); + far_clip = llmin(far_clip, camera.getFar()); - F32 da = 1.f-llmax( fabsf(lightDir*up), fabsf(lightDir*camera.getLeftAxis()) ); - - da = powf(da, split_exp.mV[2]); + F32 range = far_clip-near_clip; - F32 sxp = split_exp.mV[1] + (split_exp.mV[0]-split_exp.mV[1])*da; - - for (U32 i = 0; i < 4; ++i) - { - F32 x = (F32)(i+1)/4.f; - x = powf(x, sxp); - mSunClipPlanes.mV[i] = near_clip+range*x; - } + LLVector3 split_exp = RenderShadowSplitExponent; - mSunClipPlanes.mV[0] *= 1.25f; //bump back first split for transition padding - } + F32 da = 1.f-llmax( fabsf(lightDir*up), fabsf(lightDir*camera.getLeftAxis()) ); + + da = powf(da, split_exp.mV[2]); - // convenience array of 4 near clip plane distances - F32 dist[] = { near_clip, mSunClipPlanes.mV[0], mSunClipPlanes.mV[1], mSunClipPlanes.mV[2], mSunClipPlanes.mV[3] }; + F32 sxp = split_exp.mV[1] + (split_exp.mV[0]-split_exp.mV[1])*da; + + for (U32 i = 0; i < 4; ++i) + { + F32 x = (F32)(i+1)/4.f; + x = powf(x, sxp); + mSunClipPlanes.mV[i] = near_clip+range*x; + } - if (!ignore_shadows) - { - for (S32 j = 0; j < 4; j++) - { - LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW_SETUP); + mSunClipPlanes.mV[0] *= 1.25f; //bump back first split for transition padding + } - if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowFrustPoints[j].clear(); - } + // convenience array of 4 near clip plane distances + F32 dist[] = { near_clip, mSunClipPlanes.mV[0], mSunClipPlanes.mV[1], mSunClipPlanes.mV[2], mSunClipPlanes.mV[3] }; + - LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0+j); + if (mSunDiffuse == LLColor4::black) + { //sun diffuse is totally black, shadows don't matter + LLGLDepthTest depth(GL_TRUE); - //restore render matrices - set_current_modelview(saved_view); - set_current_projection(saved_proj); + for (S32 j = 0; j < 4; j++) + { + mShadow[j].bindTarget(); + mShadow[j].clear(); + mShadow[j].flush(); + } + } + else + { + for (S32 j = 0; j < 4; j++) + { + if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowFrustPoints[j].clear(); + } - LLVector3 eye = camera.getOrigin(); + LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0+j); - //camera used for shadow cull/render - LLCamera shadow_cam; - - //create world space camera frustum for this split - shadow_cam = camera; - shadow_cam.setFar(16.f); - - LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); + //restore render matrices + set_current_modelview(saved_view); + set_current_projection(saved_proj); - LLVector3* frust = shadow_cam.mAgentFrustum; + LLVector3 eye = camera.getOrigin(); - LLVector3 pn = shadow_cam.getAtAxis(); - - LLVector3 min, max; + //camera used for shadow cull/render + LLCamera shadow_cam; + + //create world space camera frustum for this split + shadow_cam = camera; + shadow_cam.setFar(16.f); + + LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); - //construct 8 corners of split frustum section - for (U32 i = 0; i < 4; i++) - { - LLVector3 delta = frust[i+4]-eye; - delta += (frust[i+4]-frust[(i+2)%4+4])*0.05f; - delta.normVec(); - F32 dp = delta*pn; - frust[i] = eye + (delta*dist[j]*0.75f)/dp; - frust[i+4] = eye + (delta*dist[j+1]*1.25f)/dp; - } - - shadow_cam.calcAgentFrustumPlanes(frust); - shadow_cam.mFrustumCornerDist = 0.f; - - if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowCamera[j] = shadow_cam; - } + LLVector3* frust = shadow_cam.mAgentFrustum; - std::vector fp; + LLVector3 pn = shadow_cam.getAtAxis(); + + LLVector3 min, max; - if (!gPipeline.getVisiblePointCloud(shadow_cam, min, max, fp, lightDir)) - { - //no possible shadow receivers - if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowExtents[j][0] = LLVector3(); - mShadowExtents[j][1] = LLVector3(); - mShadowCamera[j+4] = shadow_cam; - } + //construct 8 corners of split frustum section + for (U32 i = 0; i < 4; i++) + { + LLVector3 delta = frust[i+4]-eye; + delta += (frust[i+4]-frust[(i+2)%4+4])*0.05f; + delta.normVec(); + F32 dp = delta*pn; + frust[i] = eye + (delta*dist[j]*0.75f)/dp; + frust[i+4] = eye + (delta*dist[j+1]*1.25f)/dp; + } + + shadow_cam.calcAgentFrustumPlanes(frust); + shadow_cam.mFrustumCornerDist = 0.f; + + if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowCamera[j] = shadow_cam; + } - LLRenderTarget* shadow_target = getShadowTarget(j); - if (shadow_target) - { - shadow_target->bindTarget(); - { - LLGLDepthTest depth(GL_TRUE); - shadow_target->clear(); - } - shadow_target->flush(); - } + std::vector fp; - mShadowError.mV[j] = 0.f; - mShadowFOV.mV[j] = 0.f; + if (!gPipeline.getVisiblePointCloud(shadow_cam, min, max, fp, lightDir)) + { + //no possible shadow receivers + if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowExtents[j][0] = LLVector3(); + mShadowExtents[j][1] = LLVector3(); + mShadowCamera[j+4] = shadow_cam; + } - continue; - } + mShadow[j].bindTarget(); + { + LLGLDepthTest depth(GL_TRUE); + mShadow[j].clear(); + } + mShadow[j].flush(); - if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowExtents[j][0] = min; - mShadowExtents[j][1] = max; - mShadowFrustPoints[j] = fp; - } - + mShadowError.mV[j] = 0.f; + mShadowFOV.mV[j] = 0.f; - //find a good origin for shadow projection - LLVector3 origin; + continue; + } - //get a temporary view projection - view[j] = look(camera.getOrigin(), lightDir, -up); + if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowExtents[j][0] = min; + mShadowExtents[j][1] = max; + mShadowFrustPoints[j] = fp; + } + - std::vector wpf; + //find a good origin for shadow projection + LLVector3 origin; - for (U32 i = 0; i < fp.size(); i++) - { - glh::vec3f p = glh::vec3f(fp[i].mV); - view[j].mult_matrix_vec(p); - wpf.push_back(LLVector3(p.v)); - } + //get a temporary view projection + view[j] = look(camera.getOrigin(), lightDir, -up); - min = wpf[0]; - max = wpf[0]; + std::vector wpf; - for (U32 i = 0; i < fp.size(); ++i) - { //get AABB in camera space - update_min_max(min, max, wpf[i]); - } + for (U32 i = 0; i < fp.size(); i++) + { + glh::vec3f p = glh::vec3f(fp[i].mV); + view[j].mult_matrix_vec(p); + wpf.push_back(LLVector3(p.v)); + } - // Construct a perspective transform with perspective along y-axis that contains - // points in wpf - //Known: - // - far clip plane - // - near clip plane - // - points in frustum - //Find: - // - origin - - //get some "interesting" points of reference - LLVector3 center = (min+max)*0.5f; - LLVector3 size = (max-min)*0.5f; - LLVector3 near_center = center; - near_center.mV[1] += size.mV[1]*2.f; - - - //put all points in wpf in quadrant 0, reletive to center of min/max - //get the best fit line using least squares - F32 bfm = 0.f; - F32 bfb = 0.f; + min = wpf[0]; + max = wpf[0]; - for (U32 i = 0; i < wpf.size(); ++i) - { - wpf[i] -= center; - wpf[i].mV[0] = fabsf(wpf[i].mV[0]); - wpf[i].mV[2] = fabsf(wpf[i].mV[2]); - } + for (U32 i = 0; i < fp.size(); ++i) + { //get AABB in camera space + update_min_max(min, max, wpf[i]); + } - if (!wpf.empty()) - { - F32 sx = 0.f; - F32 sx2 = 0.f; - F32 sy = 0.f; - F32 sxy = 0.f; - - for (U32 i = 0; i < wpf.size(); ++i) - { - sx += wpf[i].mV[0]; - sx2 += wpf[i].mV[0]*wpf[i].mV[0]; - sy += wpf[i].mV[1]; - sxy += wpf[i].mV[0]*wpf[i].mV[1]; - } + // Construct a perspective transform with perspective along y-axis that contains + // points in wpf + //Known: + // - far clip plane + // - near clip plane + // - points in frustum + //Find: + // - origin - bfm = (sy*sx-wpf.size()*sxy)/(sx*sx-wpf.size()*sx2); - bfb = (sx*sxy-sy*sx2)/(sx*sx-bfm*sx2); - } - - { - // best fit line is y=bfm*x+bfb - - //find point that is furthest to the right of line - F32 off_x = -1.f; - LLVector3 lp; + //get some "interesting" points of reference + LLVector3 center = (min+max)*0.5f; + LLVector3 size = (max-min)*0.5f; + LLVector3 near_center = center; + near_center.mV[1] += size.mV[1]*2.f; + + + //put all points in wpf in quadrant 0, reletive to center of min/max + //get the best fit line using least squares + F32 bfm = 0.f; + F32 bfb = 0.f; - for (U32 i = 0; i < wpf.size(); ++i) - { - //y = bfm*x+bfb - //x = (y-bfb)/bfm - F32 lx = (wpf[i].mV[1]-bfb)/bfm; + for (U32 i = 0; i < wpf.size(); ++i) + { + wpf[i] -= center; + wpf[i].mV[0] = fabsf(wpf[i].mV[0]); + wpf[i].mV[2] = fabsf(wpf[i].mV[2]); + } - lx = wpf[i].mV[0]-lx; - - if (off_x < lx) - { - off_x = lx; - lp = wpf[i]; - } - } + if (!wpf.empty()) + { + F32 sx = 0.f; + F32 sx2 = 0.f; + F32 sy = 0.f; + F32 sxy = 0.f; + + for (U32 i = 0; i < wpf.size(); ++i) + { + sx += wpf[i].mV[0]; + sx2 += wpf[i].mV[0]*wpf[i].mV[0]; + sy += wpf[i].mV[1]; + sxy += wpf[i].mV[0]*wpf[i].mV[1]; + } - //get line with slope bfm through lp - // bfb = y-bfm*x - bfb = lp.mV[1]-bfm*lp.mV[0]; + bfm = (sy*sx-wpf.size()*sxy)/(sx*sx-wpf.size()*sx2); + bfb = (sx*sxy-sy*sx2)/(sx*sx-bfm*sx2); + } + + { + // best fit line is y=bfm*x+bfb + + //find point that is furthest to the right of line + F32 off_x = -1.f; + LLVector3 lp; - //calculate error - mShadowError.mV[j] = 0.f; + for (U32 i = 0; i < wpf.size(); ++i) + { + //y = bfm*x+bfb + //x = (y-bfb)/bfm + F32 lx = (wpf[i].mV[1]-bfb)/bfm; - for (U32 i = 0; i < wpf.size(); ++i) - { - F32 lx = (wpf[i].mV[1]-bfb)/bfm; - mShadowError.mV[j] += fabsf(wpf[i].mV[0]-lx); - } + lx = wpf[i].mV[0]-lx; + + if (off_x < lx) + { + off_x = lx; + lp = wpf[i]; + } + } - mShadowError.mV[j] /= wpf.size(); - mShadowError.mV[j] /= size.mV[0]; + //get line with slope bfm through lp + // bfb = y-bfm*x + bfb = lp.mV[1]-bfm*lp.mV[0]; - if (mShadowError.mV[j] > RenderShadowErrorCutoff) - { //just use ortho projection - mShadowFOV.mV[j] = -1.f; - origin.clearVec(); - proj[j] = gl_ortho(min.mV[0], max.mV[0], - min.mV[1], max.mV[1], - -max.mV[2], -min.mV[2]); - } - else - { - //origin is where line x = 0; - origin.setVec(0,bfb,0); + //calculate error + mShadowError.mV[j] = 0.f; - F32 fovz = 1.f; - F32 fovx = 1.f; - - LLVector3 zp; - LLVector3 xp; + for (U32 i = 0; i < wpf.size(); ++i) + { + F32 lx = (wpf[i].mV[1]-bfb)/bfm; + mShadowError.mV[j] += fabsf(wpf[i].mV[0]-lx); + } - for (U32 i = 0; i < wpf.size(); ++i) - { - LLVector3 atz = wpf[i]-origin; - atz.mV[0] = 0.f; - atz.normVec(); - if (fovz > -atz.mV[1]) - { - zp = wpf[i]; - fovz = -atz.mV[1]; - } - - LLVector3 atx = wpf[i]-origin; - atx.mV[2] = 0.f; - atx.normVec(); - if (fovx > -atx.mV[1]) - { - fovx = -atx.mV[1]; - xp = wpf[i]; - } - } + mShadowError.mV[j] /= wpf.size(); + mShadowError.mV[j] /= size.mV[0]; - fovx = acos(fovx); - fovz = acos(fovz); + if (mShadowError.mV[j] > RenderShadowErrorCutoff) + { //just use ortho projection + mShadowFOV.mV[j] = -1.f; + origin.clearVec(); + proj[j] = gl_ortho(min.mV[0], max.mV[0], + min.mV[1], max.mV[1], + -max.mV[2], -min.mV[2]); + } + else + { + //origin is where line x = 0; + origin.setVec(0,bfb,0); - F32 cutoff = llmin((F32) RenderShadowFOVCutoff, 1.4f); - - mShadowFOV.mV[j] = fovx; - - if (fovx < cutoff && fovz > cutoff) - { - //x is a good fit, but z is too big, move away from zp enough so that fovz matches cutoff - F32 d = zp.mV[2]/tan(cutoff); - F32 ny = zp.mV[1] + fabsf(d); + F32 fovz = 1.f; + F32 fovx = 1.f; + + LLVector3 zp; + LLVector3 xp; - origin.mV[1] = ny; + for (U32 i = 0; i < wpf.size(); ++i) + { + LLVector3 atz = wpf[i]-origin; + atz.mV[0] = 0.f; + atz.normVec(); + if (fovz > -atz.mV[1]) + { + zp = wpf[i]; + fovz = -atz.mV[1]; + } + + LLVector3 atx = wpf[i]-origin; + atx.mV[2] = 0.f; + atx.normVec(); + if (fovx > -atx.mV[1]) + { + fovx = -atx.mV[1]; + xp = wpf[i]; + } + } - fovz = 1.f; - fovx = 1.f; + fovx = acos(fovx); + fovz = acos(fovz); - for (U32 i = 0; i < wpf.size(); ++i) - { - LLVector3 atz = wpf[i]-origin; - atz.mV[0] = 0.f; - atz.normVec(); - fovz = llmin(fovz, -atz.mV[1]); - - LLVector3 atx = wpf[i]-origin; - atx.mV[2] = 0.f; - atx.normVec(); - fovx = llmin(fovx, -atx.mV[1]); - } + F32 cutoff = llmin((F32) RenderShadowFOVCutoff, 1.4f); + + mShadowFOV.mV[j] = fovx; + + if (fovx < cutoff && fovz > cutoff) + { + //x is a good fit, but z is too big, move away from zp enough so that fovz matches cutoff + F32 d = zp.mV[2]/tan(cutoff); + F32 ny = zp.mV[1] + fabsf(d); - fovx = acos(fovx); - fovz = acos(fovz); + origin.mV[1] = ny; - mShadowFOV.mV[j] = cutoff; - } + fovz = 1.f; + fovx = 1.f; - - origin += center; - - F32 ynear = -(max.mV[1]-origin.mV[1]); - F32 yfar = -(min.mV[1]-origin.mV[1]); - - if (ynear < 0.1f) //keep a sensible near clip plane - { - F32 diff = 0.1f-ynear; - origin.mV[1] += diff; - ynear += diff; - yfar += diff; - } - - if (fovx > cutoff) - { //just use ortho projection - origin.clearVec(); - mShadowError.mV[j] = -1.f; - proj[j] = gl_ortho(min.mV[0], max.mV[0], - min.mV[1], max.mV[1], - -max.mV[2], -min.mV[2]); - } - else - { - //get perspective projection - view[j] = view[j].inverse(); + for (U32 i = 0; i < wpf.size(); ++i) + { + LLVector3 atz = wpf[i]-origin; + atz.mV[0] = 0.f; + atz.normVec(); + fovz = llmin(fovz, -atz.mV[1]); + + LLVector3 atx = wpf[i]-origin; + atx.mV[2] = 0.f; + atx.normVec(); + fovx = llmin(fovx, -atx.mV[1]); + } - glh::vec3f origin_agent(origin.mV); - - //translate view to origin - view[j].mult_matrix_vec(origin_agent); + fovx = acos(fovx); + fovz = acos(fovz); - eye = LLVector3(origin_agent.v); + mShadowFOV.mV[j] = cutoff; + } - if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) - { - mShadowFrustOrigin[j] = eye; - } - - view[j] = look(LLVector3(origin_agent.v), lightDir, -up); + + origin += center; + + F32 ynear = -(max.mV[1]-origin.mV[1]); + F32 yfar = -(min.mV[1]-origin.mV[1]); + + if (ynear < 0.1f) //keep a sensible near clip plane + { + F32 diff = 0.1f-ynear; + origin.mV[1] += diff; + ynear += diff; + yfar += diff; + } + + if (fovx > cutoff) + { //just use ortho projection + origin.clearVec(); + mShadowError.mV[j] = -1.f; + proj[j] = gl_ortho(min.mV[0], max.mV[0], + min.mV[1], max.mV[1], + -max.mV[2], -min.mV[2]); + } + else + { + //get perspective projection + view[j] = view[j].inverse(); - F32 fx = 1.f/tanf(fovx); - F32 fz = 1.f/tanf(fovz); + glh::vec3f origin_agent(origin.mV); + + //translate view to origin + view[j].mult_matrix_vec(origin_agent); - proj[j] = glh::matrix4f(-fx, 0, 0, 0, - 0, (yfar+ynear)/(ynear-yfar), 0, (2.f*yfar*ynear)/(ynear-yfar), - 0, 0, -fz, 0, - 0, -1.f, 0, 0); - } - } - } + eye = LLVector3(origin_agent.v); - //shadow_cam.setFar(128.f); - shadow_cam.setOriginAndLookAt(eye, up, center); + if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowFrustOrigin[j] = eye; + } + + view[j] = look(LLVector3(origin_agent.v), lightDir, -up); - shadow_cam.setOrigin(0,0,0); + F32 fx = 1.f/tanf(fovx); + F32 fz = 1.f/tanf(fovz); - set_current_modelview(view[j]); - set_current_projection(proj[j]); + proj[j] = glh::matrix4f(-fx, 0, 0, 0, + 0, (yfar+ynear)/(ynear-yfar), 0, (2.f*yfar*ynear)/(ynear-yfar), + 0, 0, -fz, 0, + 0, -1.f, 0, 0); + } + } + } - shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR); - shadow_cam.getAgentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip); + //shadow_cam.setFar(128.f); + shadow_cam.setOriginAndLookAt(eye, up, center); - LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); + shadow_cam.setOrigin(0,0,0); - //translate and scale to from [-1, 1] to [0, 1] - glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f, - 0.f, 0.5f, 0.f, 0.5f, - 0.f, 0.f, 0.5f, 0.5f, - 0.f, 0.f, 0.f, 1.f); + set_current_modelview(view[j]); + set_current_projection(proj[j]); - set_current_modelview(view[j]); - set_current_projection(proj[j]); + LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); - for (U32 i = 0; i < 16; i++) - { - gGLLastModelView[i] = mShadowModelview[j].m[i]; - gGLLastProjection[i] = mShadowProjection[j].m[i]; - } + //shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR); + shadow_cam.getAgentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip); - mShadowModelview[j] = view[j]; - mShadowProjection[j] = proj[j]; + //translate and scale to from [-1, 1] to [0, 1] + glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f, + 0.f, 0.5f, 0.f, 0.5f, + 0.f, 0.f, 0.5f, 0.5f, + 0.f, 0.f, 0.f, 1.f); - - mSunShadowMatrix[j] = trans*proj[j]*view[j]*inv_view; - - stop_glerror(); + set_current_modelview(view[j]); + set_current_projection(proj[j]); - LLRenderTarget* shadow_target = getShadowTarget(j); + for (U32 i = 0; i < 16; i++) + { + gGLLastModelView[i] = mShadowModelview[j].m[i]; + gGLLastProjection[i] = mShadowProjection[j].m[i]; + } - if (shadow_target) - { - shadow_target->bindTarget(); - shadow_target->getViewport(gGLViewport); - shadow_target->clear(); + mShadowModelview[j] = view[j]; + mShadowProjection[j] = proj[j]; + mSunShadowMatrix[j] = trans*proj[j]*view[j]*inv_view; + + stop_glerror(); - U32 target_width = shadow_target->getWidth(); + mShadow[j].bindTarget(); + mShadow[j].getViewport(gGLViewport); + mShadow[j].clear(); + + U32 target_width = mShadow[j].getWidth(); - { - LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW_RENDER_DIRECTIONAL); + { + static LLCullResult result[4]; + renderShadow(view[j], proj[j], shadow_cam, result[j], TRUE, FALSE, target_width); + } - static LLCullResult result[4]; - renderShadow(view[j], proj[j], shadow_cam, result[j], TRUE, TRUE, target_width); - } + mShadow[j].flush(); + + if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) + { + mShadowCamera[j+4] = shadow_cam; + } + } + } - shadow_target->flush(); - } + + //hack to disable projector shadows + bool gen_shadow = RenderShadowDetail > 1; - if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA)) - { - LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); - mShadowCamera[j+4] = shadow_cam; - } - } - } + if (gen_shadow) + { + LLTrace::CountStatHandle<>* velocity_stat = LLViewerCamera::getVelocityStat(); + F32 fade_amt = gFrameIntervalSeconds.value() + * llmax(LLTrace::get_frame_recording().getLastRecording().getSum(*velocity_stat) / LLTrace::get_frame_recording().getLastRecording().getDuration().value(), 1.0); - - //hack to disable projector shadows - bool gen_shadow = RenderShadowDetail > 1; + //update shadow targets + for (U32 i = 0; i < 2; i++) + { //for each current shadow + LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW4+i); - if (gen_shadow) - { - LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW_SPOT_SETUP); - - LLTrace::CountStatHandle<>* velocity_stat = LLViewerCamera::getVelocityStat(); - F32 fade_amt = gFrameIntervalSeconds.value() - * llmax(LLTrace::get_frame_recording().getLastRecording().getSum(*velocity_stat) / LLTrace::get_frame_recording().getLastRecording().getDuration().value(), 1.0); - - //update shadow targets - for (U32 i = 0; i < 2; i++) - { //for each current shadow - LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW4+i); - - if (mShadowSpotLight[i].notNull() && - (mShadowSpotLight[i] == mTargetShadowSpotLight[0] || - mShadowSpotLight[i] == mTargetShadowSpotLight[1])) - { //keep this spotlight - mSpotLightFade[i] = llmin(mSpotLightFade[i]+fade_amt, 1.f); - } - else - { //fade out this light - mSpotLightFade[i] = llmax(mSpotLightFade[i]-fade_amt, 0.f); - - if (mSpotLightFade[i] == 0.f || mShadowSpotLight[i].isNull()) - { //faded out, grab one of the pending spots (whichever one isn't already taken) - if (mTargetShadowSpotLight[0] != mShadowSpotLight[(i+1)%2]) - { - mShadowSpotLight[i] = mTargetShadowSpotLight[0]; - } - else - { - mShadowSpotLight[i] = mTargetShadowSpotLight[1]; - } - } - } - } + if (mShadowSpotLight[i].notNull() && + (mShadowSpotLight[i] == mTargetShadowSpotLight[0] || + mShadowSpotLight[i] == mTargetShadowSpotLight[1])) + { //keep this spotlight + mSpotLightFade[i] = llmin(mSpotLightFade[i]+fade_amt, 1.f); + } + else + { //fade out this light + mSpotLightFade[i] = llmax(mSpotLightFade[i]-fade_amt, 0.f); + + if (mSpotLightFade[i] == 0.f || mShadowSpotLight[i].isNull()) + { //faded out, grab one of the pending spots (whichever one isn't already taken) + if (mTargetShadowSpotLight[0] != mShadowSpotLight[(i+1)%2]) + { + mShadowSpotLight[i] = mTargetShadowSpotLight[0]; + } + else + { + mShadowSpotLight[i] = mTargetShadowSpotLight[1]; + } + } + } + } - for (S32 i = 0; i < 2; i++) - { - set_current_modelview(saved_view); - set_current_projection(saved_proj); + for (S32 i = 0; i < 2; i++) + { + set_current_modelview(saved_view); + set_current_projection(saved_proj); - if (mShadowSpotLight[i].isNull()) - { - continue; - } + if (mShadowSpotLight[i].isNull()) + { + continue; + } - LLVOVolume* volume = mShadowSpotLight[i]->getVOVolume(); + LLVOVolume* volume = mShadowSpotLight[i]->getVOVolume(); - if (!volume) - { - mShadowSpotLight[i] = NULL; - continue; - } + if (!volume) + { + mShadowSpotLight[i] = NULL; + continue; + } - LLDrawable* drawable = mShadowSpotLight[i]; + LLDrawable* drawable = mShadowSpotLight[i]; - LLVector3 params = volume->getSpotLightParams(); - F32 fov = params.mV[0]; + LLVector3 params = volume->getSpotLightParams(); + F32 fov = params.mV[0]; - //get agent->light space matrix (modelview) - LLVector3 center = drawable->getPositionAgent(); - LLQuaternion quat = volume->getRenderRotation(); + //get agent->light space matrix (modelview) + LLVector3 center = drawable->getPositionAgent(); + LLQuaternion quat = volume->getRenderRotation(); - //get near clip plane - LLVector3 scale = volume->getScale(); - LLVector3 at_axis(0,0,-scale.mV[2]*0.5f); - at_axis *= quat; + //get near clip plane + LLVector3 scale = volume->getScale(); + LLVector3 at_axis(0,0,-scale.mV[2]*0.5f); + at_axis *= quat; - LLVector3 np = center+at_axis; - at_axis.normVec(); + LLVector3 np = center+at_axis; + at_axis.normVec(); - //get origin that has given fov for plane np, at_axis, and given scale - F32 dist = (scale.mV[1]*0.5f)/tanf(fov*0.5f); + //get origin that has given fov for plane np, at_axis, and given scale + F32 dist = (scale.mV[1]*0.5f)/tanf(fov*0.5f); - LLVector3 origin = np - at_axis*dist; + LLVector3 origin = np - at_axis*dist; - LLMatrix4 mat(quat, LLVector4(origin, 1.f)); + LLMatrix4 mat(quat, LLVector4(origin, 1.f)); - view[i+4] = glh::matrix4f((F32*) mat.mMatrix); + view[i+4] = glh::matrix4f((F32*) mat.mMatrix); - view[i+4] = view[i+4].inverse(); + view[i+4] = view[i+4].inverse(); - //get perspective matrix - F32 near_clip = dist+0.01f; - F32 width = scale.mV[VX]; - F32 height = scale.mV[VY]; - F32 far_clip = dist+volume->getLightRadius()*1.5f; + //get perspective matrix + F32 near_clip = dist+0.01f; + F32 width = scale.mV[VX]; + F32 height = scale.mV[VY]; + F32 far_clip = dist+volume->getLightRadius()*1.5f; - F32 fovy = fov * RAD_TO_DEG; - F32 aspect = width/height; - - proj[i+4] = gl_perspective(fovy, aspect, near_clip, far_clip); + F32 fovy = fov * RAD_TO_DEG; + F32 aspect = width/height; + + proj[i+4] = gl_perspective(fovy, aspect, near_clip, far_clip); - //translate and scale to from [-1, 1] to [0, 1] - glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f, - 0.f, 0.5f, 0.f, 0.5f, - 0.f, 0.f, 0.5f, 0.5f, - 0.f, 0.f, 0.f, 1.f); + //translate and scale to from [-1, 1] to [0, 1] + glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f, + 0.f, 0.5f, 0.f, 0.5f, + 0.f, 0.f, 0.5f, 0.5f, + 0.f, 0.f, 0.f, 1.f); - set_current_modelview(view[i+4]); - set_current_projection(proj[i+4]); + set_current_modelview(view[i+4]); + set_current_projection(proj[i+4]); - mSunShadowMatrix[i+4] = trans*proj[i+4]*view[i+4]*inv_view; - - for (U32 j = 0; j < 16; j++) - { - gGLLastModelView[j] = mShadowModelview[i+4].m[j]; - gGLLastProjection[j] = mShadowProjection[i+4].m[j]; - } + mSunShadowMatrix[i+4] = trans*proj[i+4]*view[i+4]*inv_view; + + for (U32 j = 0; j < 16; j++) + { + gGLLastModelView[j] = mShadowModelview[i+4].m[j]; + gGLLastProjection[j] = mShadowProjection[i+4].m[j]; + } - mShadowModelview[i+4] = view[i+4]; - mShadowProjection[i+4] = proj[i+4]; + mShadowModelview[i+4] = view[i+4]; + mShadowProjection[i+4] = proj[i+4]; - LLCamera shadow_cam = camera; - shadow_cam.setFar(far_clip); - shadow_cam.setOrigin(origin); + LLCamera shadow_cam = camera; + shadow_cam.setFar(far_clip); + shadow_cam.setOrigin(origin); - LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); + LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); - stop_glerror(); + stop_glerror(); - LLRenderTarget* shadow_target = getShadowTarget(i + 4); + mShadow[i+4].bindTarget(); + mShadow[i+4].getViewport(gGLViewport); + mShadow[i+4].clear(); - if (shadow_target) - { - LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW_SPOT_RENDER); + U32 target_width = mShadow[i+4].getWidth(); - shadow_target->bindTarget(); - shadow_target->getViewport(gGLViewport); - shadow_target->clear(); - - U32 target_width = shadow_target->getWidth(); + static LLCullResult result[2]; - static LLCullResult result[2]; - LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0 + i + 4); + LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0 + i + 4); - renderShadow(view[i+4], proj[i+4], shadow_cam, result[i], FALSE, FALSE, target_width); + renderShadow(view[i+4], proj[i+4], shadow_cam, result[i], FALSE, FALSE, target_width); - shadow_target->flush(); - } - } - } - else - { //no spotlight shadows - mShadowSpotLight[0] = mShadowSpotLight[1] = NULL; - } + mShadow[i+4].flush(); + } + } + else + { //no spotlight shadows + mShadowSpotLight[0] = mShadowSpotLight[1] = NULL; + } - if (!CameraOffset) - { - set_current_modelview(saved_view); - set_current_projection(saved_proj); - } - else - { - set_current_modelview(view[1]); - set_current_projection(proj[1]); - gGL.loadMatrix(view[1].m); - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.loadMatrix(proj[1].m); - gGL.matrixMode(LLRender::MM_MODELVIEW); - } - gGL.setColorMask(true, false); + if (!CameraOffset) + { + set_current_modelview(saved_view); + set_current_projection(saved_proj); + } + else + { + set_current_modelview(view[1]); + set_current_projection(proj[1]); + gGL.loadMatrix(view[1].m); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.loadMatrix(proj[1].m); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } + gGL.setColorMask(true, false); - for (U32 i = 0; i < 16; i++) - { - gGLLastModelView[i] = last_modelview[i]; - gGLLastProjection[i] = last_projection[i]; - } + for (U32 i = 0; i < 16; i++) + { + gGLLastModelView[i] = last_modelview[i]; + gGLLastProjection[i] = last_projection[i]; + } - popRenderTypeMask(); + popRenderTypeMask(); - if (!skip_avatar_update) - { - gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode()); - } + if (!skip_avatar_update) + { + gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode()); + } } void LLPipeline::renderGroups(LLRenderPass* pass, U32 type, U32 mask, bool texture) -- cgit v1.3 From 8ba159fed90fc221003e85c5d2d3b82ec30d81bf Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 27 Jun 2019 09:10:38 -0700 Subject: SL-11151, SL-11504 Remove update threshold logic causing hiccups and rework sky updates. Make deferred water do double transport again to match non-ALM rendering more closely. --- indra/llinventory/llsettingsbase.cpp | 8 - indra/llinventory/llsettingsbase.h | 21 -- .../shaders/class1/deferred/waterF.glsl | 2 +- indra/newview/llenvironment.cpp | 2 - indra/newview/lllegacyatmospherics.cpp | 1 - indra/newview/lllegacyatmospherics.h | 1 - indra/newview/llvosky.cpp | 212 +++++++++------------ indra/newview/llvosky.h | 4 +- 8 files changed, 90 insertions(+), 161 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llinventory/llsettingsbase.cpp b/indra/llinventory/llsettingsbase.cpp index c051563714..e8fdd017e3 100644 --- a/indra/llinventory/llsettingsbase.cpp +++ b/indra/llinventory/llsettingsbase.cpp @@ -727,22 +727,14 @@ LLSettingsBase::BlendFactor LLSettingsBlenderTimeDelta::calculateBlend(const LLS bool LLSettingsBlenderTimeDelta::applyTimeDelta(const LLSettingsBase::Seconds& timedelta) { mTimeSpent += timedelta; - mTimeDeltaPassed += timedelta; if (mTimeSpent > mBlendSpan) { - mIgnoreTimeDelta = false; triggerComplete(); return false; } - if ((mTimeDeltaPassed < mTimeDeltaThreshold) && (!mIgnoreTimeDelta)) - { - return false; - } - LLSettingsBase::BlendFactor blendf = calculateBlend(mTimeSpent, mBlendSpan); - mTimeDeltaPassed = LLSettingsBase::Seconds(0.0); if (fabs(mLastBlendF - blendf) < mBlendFMinDelta) { diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index 592ae3478a..afb5014409 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -477,9 +477,6 @@ public: mBlendSpan(blend_span), mLastUpdate(0.0f), mTimeSpent(0.0f), - mTimeDeltaThreshold(0.0f), - mTimeDeltaPassed(0.0f), - mIgnoreTimeDelta(false), mBlendFMinDelta(MIN_BLEND_DELTA), mLastBlendF(-1.0f) { @@ -499,26 +496,11 @@ public: mTimeStart = LLSettingsBase::Seconds(LLDate::now().secondsSinceEpoch()); mLastUpdate = mTimeStart; mTimeSpent = LLSettingsBase::Seconds(0.0f); - mTimeDeltaPassed = LLSettingsBase::Seconds(0.0f); mLastBlendF = LLSettingsBase::BlendFactor(-1.0f); } virtual bool applyTimeDelta(const LLSettingsBase::Seconds& timedelta) SETTINGS_OVERRIDE; - inline void setTimeDeltaThreshold(const LLSettingsBase::Seconds time) - { - mTimeDeltaThreshold = time; - mTimeDeltaPassed = time + LLSettingsBase::Seconds(1.0); // take the next update call. - } - - inline LLSettingsBase::Seconds getTimeDeltaThreshold() const - { - return mTimeDeltaThreshold; - } - - inline void setIgnoreTimeDeltaThreshold(bool val) { mIgnoreTimeDelta = val; } - inline bool getIgnoreTimeDeltaThreshold() const { return mIgnoreTimeDelta; } - inline void setTimeSpent(LLSettingsBase::Seconds time) { mTimeSpent = time; } protected: LLSettingsBase::BlendFactor calculateBlend(const LLSettingsBase::TrackPosition& spanpos, const LLSettingsBase::TrackPosition& spanlen) const; @@ -527,9 +509,6 @@ protected: LLSettingsBase::Seconds mLastUpdate; LLSettingsBase::Seconds mTimeSpent; LLSettingsBase::Seconds mTimeStart; - LLSettingsBase::Seconds mTimeDeltaThreshold; - LLSettingsBase::Seconds mTimeDeltaPassed; - bool mIgnoreTimeDelta; LLSettingsBase::BlendFactor mBlendFMinDelta; LLSettingsBase::BlendFactor mLastBlendF; }; diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index fd5b6989eb..8554ebef0b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -164,7 +164,7 @@ void main() color.rgb += spec * specular; - //color.rgb = atmosTransport(color.rgb); + color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); color.a = spec * sunAngle2; diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp index 3373c8c3a4..d20c05fe67 100644 --- a/indra/newview/llenvironment.cpp +++ b/indra/newview/llenvironment.cpp @@ -196,7 +196,6 @@ namespace mCycleLength(cyclelength), mCycleOffset(cycleoffset) { - setTimeDeltaThreshold(updateThreshold); // must happen prior to getBoundingEntries call... mTrackNo = selectTrackNumber(trackno); @@ -233,7 +232,6 @@ namespace LLSettingsBase::BlendFactor blendf = calculateBlend(targetpos, targetspan); pendsetting->blend((*bounds.second).second, blendf); - setIgnoreTimeDeltaThreshold(true); // for the next span ignore the time delta threshold. reset(pstartsetting, pendsetting, LLEnvironment::TRANSITION_ALTITUDE); } diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index a09f54c303..b6c46b9ff9 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -181,7 +181,6 @@ LLAtmospherics::LLAtmospherics() { /// WL PARAMS mInitialized = FALSE; - mUpdateTimer.reset(); mAmbientScale = gSavedSettings.getF32("SkyAmbientScale"); mNightColorShift = gSavedSettings.getColor3("SkyNightColorShift"); mFogColor.mV[VRED] = mFogColor.mV[VGREEN] = mFogColor.mV[VBLUE] = 0.5f; diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index f2900b4323..22ed37f830 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -277,7 +277,6 @@ protected: LLColor4 mGLFogCol; F32 mFogRatio; F32 mWorldScale; - LLFrameTimer mUpdateTimer; }; #endif diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 7e0f377953..745278bf0c 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -424,7 +424,6 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mInitialized = FALSE; mbCanSelect = FALSE; - mUpdateTimer.reset(); mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); mForceUpdateThrottle.reset(); @@ -496,7 +495,8 @@ void LLVOSky::init() for (S32 tile = 0; tile < NUM_TILES; ++tile) { initSkyTextureDirs(side, tile); - createSkyTexture(m_atmosphericsVars, side, tile, false); + createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); + createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex); } } @@ -663,21 +663,9 @@ void LLVOSky::restoreGL() updateDirections(); - if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap - && LLCubeMap::sUseCubeMaps) + if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) { - LLCubeMap* cube_map = getCubeMap(); - - std::vector > images; - for (S32 side = 0; side < 6; side++) - { - images.push_back(mShinyTex[side].getImageRaw()); - } - - if(cube_map) - { - cube_map->init(images); - } + initCubeMap(); } mForceUpdate = TRUE; @@ -721,7 +709,7 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) } } -void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, bool skip_sky_tex) +void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex) { S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; @@ -730,22 +718,11 @@ void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 S32 tile_y_pos = tile_y * sTileResY; S32 x, y; - if (!skip_sky_tex) - { - for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) - { - for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) - { - mSkyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, mSkyTex[side].getDir(x, y)), x, y); - } - } - } - for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) { for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) { - mShinyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, mSkyTex[side].getDir(x, y), true), x, y); + tex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, tex[side].getDir(x, y), true), x, y); } } } @@ -801,124 +778,109 @@ bool LLVOSky::updateSky() const S32 total_no_tiles = 6 * NUM_TILES; const S32 cycle_frame_no = total_no_tiles + 1; - if (mUpdateTimer.getElapsedTimeF32() > 0.025f) - { - mUpdateTimer.reset(); - const S32 frame = next_frame; - - mForceUpdate = mForceUpdate || (total_no_tiles == frame); + const S32 frame = next_frame; - ++next_frame; - next_frame = next_frame % cycle_frame_no; + mForceUpdate = mForceUpdate || (total_no_tiles == frame); - mInterpVal = (!mInitialized) ? 1 : (F32)next_frame / cycle_frame_no; - // sInterpVal = (F32)next_frame / cycle_frame_no; - LLSkyTex::setInterpVal( mInterpVal ); - LLHeavenBody::setInterpVal( mInterpVal ); - updateDirections(); + ++next_frame; + next_frame = next_frame % cycle_frame_no; - LLVector3 direction = mSun.getDirection(); - direction.normalize(); - const F32 dot_sun = direction * mLastSunLightingDirection; - const F32 dot_moon = direction * mLastMoonLightingDirection; + mInterpVal = (!mInitialized) ? 1 : (F32)next_frame / cycle_frame_no; + // sInterpVal = (F32)next_frame / cycle_frame_no; + LLSkyTex::setInterpVal( mInterpVal ); + LLHeavenBody::setInterpVal( mInterpVal ); + updateDirections(); - 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]); + LLVector3 direction = mSun.getDirection(); + direction.normalize(); + const F32 dot_sun = direction * mLastSunLightingDirection; + const F32 dot_moon = direction * mLastMoonLightingDirection; - 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); + 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]); - mForceUpdate = mForceUpdate || sun_direction_changed; - mForceUpdate = mForceUpdate || moon_direction_changed; - mForceUpdate = mForceUpdate || color_changed; - mForceUpdate = mForceUpdate || !mInitialized; + 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); - bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + mForceUpdate = mForceUpdate || sun_direction_changed; + mForceUpdate = mForceUpdate || moon_direction_changed; + mForceUpdate = mForceUpdate || color_changed; + mForceUpdate = mForceUpdate || !mInitialized; + mForceUpdate = mForceUpdate || mForceUpdateThrottle.hasExpired(); - calc(); + calc(); - if (mForceUpdate && mForceUpdateThrottle.hasExpired()) - { - LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); + if (mForceUpdate) + { + LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); - mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); + mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); - LLSkyTex::stepCurrent(); + LLSkyTex::stepCurrent(); - if (!direction.isExactlyZero()) - { - mLastTotalAmbient = total_ambient; - mInitialized = TRUE; + if (!direction.isExactlyZero()) + { + mInitialized = TRUE; - if (mCubeMap) - { - updateFog(LLViewerCamera::getInstance()->getFar()); + updateFog(LLViewerCamera::getInstance()->getFar()); + mLastTotalAmbient = total_ambient; - for (int side = 0; side < 6; side++) + if (mCubeMap) + { + for (int side = 0; side < 6; side++) + { + for (int tile = 0; tile < NUM_TILES; tile++) { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(m_atmosphericsVars, side, tile, is_alm_wl_sky); - } + createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex); } + } - int tex = mSkyTex[0].getWhich(TRUE); + int tex = mShinyTex[0].getWhich(TRUE); + + for (int side = 0; side < 6; side++) + { + LLImageRaw* raw1 = nullptr; + LLImageRaw* raw2 = nullptr; + raw1 = mShinyTex[side].getImageRaw(TRUE); + raw2 = mShinyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mShinyTex[side].createGLImage(tex); + mShinyTex[side].create(1.0f); + } + initCubeMap(); + } - for (int side = 0; side < 6; side++) + // if we're using a generated sky cubemap instead of rendered sky... + if (!gPipeline.canUseWindLightShaders()) + { + for (int side = 0; side < 6; side++) + { + for (int tile = 0; tile < NUM_TILES; tile++) { - 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); - } - - raw1 = mShinyTex[side].getImageRaw(TRUE); - raw2 = mShinyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mShinyTex[side].createGLImage(tex); + createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); } - next_frame = 0; - - // update the sky texture - if (!is_alm_wl_sky) - { - for (S32 i = 0; i < 6; ++i) - { - mSkyTex[i].create(1.0f); - } - } - - for (S32 i = 0; i < 6; ++i) - { - mShinyTex[i].create(1.0f); - } - - // update the environment map - if (mCubeMap) - { - std::vector > 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(); - } } - } - gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - mForceUpdate = FALSE; - } + int tex = mSkyTex[0].getWhich(TRUE); + + for (int side = 0; side < 6; side++) + { + LLImageRaw* raw1 = nullptr; + LLImageRaw* raw2 = nullptr; + raw1 = mSkyTex[side].getImageRaw(TRUE); + raw2 = mSkyTex[side].getImageRaw(FALSE); + raw2->copy(raw1); + mSkyTex[side].createGLImage(tex); + mSkyTex[side].create(1.0f); + } + } + } + + gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); + mForceUpdate = FALSE; } if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index a9ef5474b6..e118cc7200 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -303,7 +303,7 @@ protected: void updateDirections(void); void initSkyTextureDirs(const S32 side, const S32 tile); - void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, bool skip_sky_tex); + void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex); LLPointer mSunTexturep[2]; LLPointer mMoonTexturep[2]; @@ -350,11 +350,11 @@ protected: LLPointer mCubeMap; // Cube map for the environment S32 mDrawRefl; - LLFrameTimer mUpdateTimer; LLTimer mForceUpdateThrottle; bool mHeavenlyBodyUpdated ; AtmosphericsVars m_atmosphericsVars; + AtmosphericsVars m_lastAtmosphericsVars; LLAtmospherics m_legacyAtmospherics; }; -- cgit v1.3 From d23bf2c16e2d36b18c920bbd42f49c47f3c58bd9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Jul 2019 13:02:09 -0700 Subject: SL-11541 WIP Make LLSettingsSky::gammaCorrect work like the soft scale clip and gamma correct from release. Add transmittance effects to the low-end sky tex gen. --- indra/llinventory/llsettingssky.cpp | 77 +++++++++++---- indra/llinventory/llsettingssky.h | 6 +- indra/newview/lldrawpoolsky.cpp | 4 +- indra/newview/lllegacyatmospherics.cpp | 166 +++++++++------------------------ indra/newview/lllegacyatmospherics.h | 5 +- indra/newview/llvosky.cpp | 110 ++++------------------ indra/newview/llvosky.h | 2 +- 7 files changed, 129 insertions(+), 241 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp index 5047f312f0..75b4415086 100644 --- a/indra/llinventory/llsettingssky.cpp +++ b/indra/llinventory/llsettingssky.cpp @@ -1184,24 +1184,34 @@ LLColor3 LLSettingsSky::getLightAttenuation(F32 distance) const return light_atten; } -LLColor3 LLSettingsSky::getLightTransmittance() const +LLColor3 LLSettingsSky::getLightTransmittance(F32 distance) const { LLColor3 total_density = getTotalDensity(); F32 density_multiplier = getDensityMultiplier(); // Transparency (-> density) from Beer's law - LLColor3 transmittance = componentExp(total_density * -density_multiplier); + LLColor3 transmittance = componentExp(total_density * -(density_multiplier * distance)); return transmittance; } +// performs soft scale clip and gamma correction ala the shader implementation +// scales colors down to 0 - 1 range preserving relative ratios LLColor3 LLSettingsSky::gammaCorrect(const LLColor3& in) const { F32 gamma = getGamma(); + LLColor3 v(in); - v.clamp(); - v= smear(1.0f) - v; - v = componentPow(v, gamma); - v = smear(1.0f) - v; - return v; + // scale down to 0 to 1 range preserving relative ratio (aka homegenize) + F32 max_color = llmax(llmax(in.mV[0], in.mV[1]), in.mV[2]); + if (max_color > 1.0f) + { + v *= 1.0f / max_color; + } + + LLColor3 color = in * 2.0f; + color = smear(1.f) - componentSaturate(color); // clamping after mul seems wrong, but prevents negative colors... + componentPow(color, gamma); + color = smear(1.f) - color; + return color; } LLVector3 LLSettingsSky::getSunDirection() const @@ -1240,6 +1250,12 @@ LLColor3 LLSettingsSky::getSunDiffuse() const return mSunDiffuse; } +LLColor4 LLSettingsSky::getHazeColor() const +{ + update(); + return mHazeColor; +} + LLColor4 LLSettingsSky::getTotalAmbient() const { update(); @@ -1255,14 +1271,19 @@ LLColor3 LLSettingsSky::getMoonlightColor() const return moonlight; } -void LLSettingsSky::clampColor(LLColor3& color) const +void LLSettingsSky::clampColor(LLColor3& color, F32 gamma, F32 scale) const { F32 max_color = llmax(color.mV[0], color.mV[1], color.mV[2]); - if (max_color > 1.f) + if (max_color > scale) { - color *= 1.f/max_color; + color *= scale/max_color; } - color.clamp(); + LLColor3 linear(color); + linear *= 1.0 / scale; + linear = smear(1.0f) - linear; + linear = componentPow(linear, gamma); + linear *= scale; + color = linear; } void LLSettingsSky::calculateLightSettings() const @@ -1278,7 +1299,7 @@ void LLSettingsSky::calculateLightSettings() const // this is used later for sunlight modulation at various altitudes F32 max_y = getMaxY(); LLColor3 light_atten = getLightAttenuation(max_y); - LLColor3 light_transmittance = getLightTransmittance(); + LLColor3 light_transmittance = getLightTransmittance(max_y); // and vary_sunlight will work properly with moon light const F32 LIMIT = FLT_EPSILON * 8.0f; @@ -1291,16 +1312,34 @@ void LLSettingsSky::calculateLightSettings() const lighty = llmax(LIMIT, lighty); componentMultBy(sunlight, componentExp((light_atten * -1.f) * lighty)); componentMultBy(sunlight, light_transmittance); - clampColor(sunlight); + + F32 max_color = llmax(sunlight.mV[0], sunlight.mV[1], sunlight.mV[2]); + if (max_color > 1.0f) + { + sunlight *= 1.0f/max_color; + } //increase ambient when there are more clouds LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5; componentMultBy(tmpAmbient, light_transmittance); - clampColor(tmpAmbient); + + //tmpAmbient = LLColor3::clamp(tmpAmbient, getGamma(), 1.0f); + max_color = llmax(tmpAmbient.mV[0], tmpAmbient.mV[1], tmpAmbient.mV[2]); + if (max_color > 1.0f) + { + tmpAmbient *= 1.0f/max_color; + } //brightness of surface both sunlight and ambient - mSunDiffuse = gammaCorrect(sunlight); - mSunAmbient = gammaCorrect(tmpAmbient); + mSunDiffuse = sunlight; + mSunAmbient = tmpAmbient; + F32 haze_horizon = getHazeHorizon(); + + sunlight *= 1.0 - cloud_shadow; + sunlight += tmpAmbient; + + mHazeColor = getBlueHorizon() * getBlueDensity() * sunlight; + mHazeColor += LLColor4(haze_horizon, haze_horizon, haze_horizon, haze_horizon) * getHazeDensity() * sunlight; F32 moon_brightness = getIsMoonUp() ? getMoonBrightness() : 0.001f; @@ -1308,10 +1347,10 @@ void LLSettingsSky::calculateLightSettings() const LLColor3 moonlight_b(0.66, 0.66, 1.2); // scotopic ambient value componentMultBy(moonlight, componentExp((light_atten * -1.f) * lighty)); - clampColor(moonlight); + clampColor(moonlight, getGamma(), 1.0f); - mMoonDiffuse = gammaCorrect(componentMult(moonlight, light_transmittance) * moon_brightness); - mMoonAmbient = gammaCorrect(componentMult(moonlight_b, light_transmittance) * 0.0125f); + mMoonDiffuse = componentMult(moonlight, light_transmittance) * moon_brightness; + mMoonAmbient = componentMult(moonlight_b, light_transmittance) * 0.0125f; mTotalAmbient = mSunAmbient; } diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h index d04209a1a1..e562fe38ff 100644 --- a/indra/llinventory/llsettingssky.h +++ b/indra/llinventory/llsettingssky.h @@ -251,7 +251,7 @@ public: static LLSD translateLegacyHazeSettings(const LLSD& legacy); LLColor3 getLightAttenuation(F32 distance) const; - LLColor3 getLightTransmittance() const; + LLColor3 getLightTransmittance(F32 distance) const; LLColor3 getTotalDensity() const; LLColor3 gammaCorrect(const LLColor3& in) const; @@ -290,6 +290,7 @@ public: LLColor4 getSunAmbient() const; LLColor3 getSunDiffuse() const; LLColor4 getTotalAmbient() const; + LLColor4 getHazeColor() const; virtual LLSettingsBase::ptr_t buildDerivedClone() const SETTINGS_OVERRIDE { return buildClone(); } @@ -346,7 +347,7 @@ private: void calculateHeavenlyBodyPositions() const; void calculateLightSettings() const; - void clampColor(LLColor3& color) const; + void clampColor(LLColor3& color, F32 gamma, const F32 scale = 1.0f) const; mutable LLVector3 mSunDirection; mutable LLVector3 mMoonDirection; @@ -360,6 +361,7 @@ private: mutable LLColor4 mSunAmbient; mutable LLColor3 mSunDiffuse; mutable LLColor4 mTotalAmbient; + mutable LLColor4 mHazeColor; typedef std::map mapNameToUniformId_t; diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index 516302676d..12614b5e2d 100644 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -129,7 +129,9 @@ void LLDrawPoolSky::renderSkyCubeFace(U8 side) llassert(mSkyTex); mSkyTex[side].bindTexture(TRUE); - + + gGL.getTexUnit(0)->setTextureColorSpace(LLTexUnit::TCS_SRGB); + face.renderIndexed(); if (LLSkyTex::doInterpolate()) diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index b6c46b9ff9..d56e6bd5d6 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -204,6 +204,8 @@ void LLAtmospherics::init() LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVector3 &dir, bool isShiny) { + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + F32 saturation = 0.3f; if (isShiny && dir.mV[VZ] < -0.02f) @@ -240,17 +242,8 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto calcSkyColorWLVert(Pn, vars); -#if SL_11371 - if (dir.mV[VZ] < 0.4f) - { - LLColor4 col = LLColor4(llmax(mFogColor[0],0.2f), llmax(mFogColor[1],0.2f), llmax(mFogColor[2],0.22f),0.f); - col *= dir * LLVector3(0,1,0); - col += vars.hazeColor; - return col; - } -#endif - - LLColor3 sky_color = calcSkyColorWLFrag(Pn, vars); + LLColor3 sky_color = psky->gammaCorrect(vars.hazeColor * 2.0f); + if (isShiny) { F32 brightness = sky_color.brightness(); @@ -261,17 +254,19 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto return LLColor4(sky_color, 0.0f); } +const F32 NIGHTTIME_ELEVATION = -8.0f; // degrees +const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION*DEG_TO_RAD); + void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) { -// LEGACY_ATMOSPHERICS - //LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); LLColor3 blue_density = vars.blue_density; LLColor3 blue_horizon = vars.blue_horizon; F32 haze_horizon = vars.haze_horizon; F32 haze_density = vars.haze_density; F32 density_multiplier = vars.density_multiplier; - //F32 distance_multiplier = vars.distance_multiplier; + F32 distance_multiplier = vars.distance_multiplier; F32 max_y = vars.max_y; LLVector4 sun_norm = vars.sun_norm; @@ -287,9 +282,6 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) Pn *= Plen; - vars.horizontalProjection[0] = LLVector2(Pn[0], Pn[2]); - vars.horizontalProjection[0] /= - 2.f * Plen; - // Set altitude if (Pn[1] > 0.f) { @@ -313,26 +305,38 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes LLColor3 light_atten = vars.light_atten; + LLColor3 light_transmittance = psky->getLightTransmittance(Plen); // Calculate relative weights LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = vars.light_transmittance; + LLColor3 temp1 = vars.total_density; LLColor3 blue_weight = componentDiv(blue_density, temp1); LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); + F32 lighty = sun_norm.mV[1]; + if(lighty < NIGHTTIME_ELEVATION_SIN) + { + lighty = -lighty; + } + // Compute sunlight from P & lightnorm (for long rays like sky) - temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, Pn[1]) * 1.0f + sun_norm[1] ); + temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, lighty)); + + if (temp2.mV[1] > 0.0000001f) + { + temp2.mV[1] = 1.f / temp2.mV[1]; + } + temp2.mV[1] = llmax(temp2.mV[1], 0.0000001f); - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + componentMultBy(sunlight, light_transmittance); - // Distance + // Distance temp2.mV[2] = Plen * density_multiplier; - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]);// * distance_multiplier); - + // Transparency (-> temp1) + temp1 = componentExp((temp1 * -1.f) * temp2.mV[2] * distance_multiplier); // Compute haze glow temp2.mV[0] = Pn * LLVector3(sun_norm); @@ -342,15 +346,8 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) temp2.mV[0] = llmax(temp2.mV[0], .001f); // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - if (glow.mV[0] > 0) // don't pow(zero,negative value), glow from 0 to 2 - { - // Higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.mV[0] *= glow.mV[0]; - } - else - { - temp2.mV[0] = F32_MIN; - } + // Higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.mV[0] *= (glow.mV[0] > 0) ? glow.mV[0] : F32_MIN; temp2.mV[0] = pow(temp2.mV[0], glow.mV[2]); // glow.z should be negative, so we're doing a sort of (1 / "angle") function @@ -371,95 +368,16 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) // Haze color below cloud vars.hazeColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + tmpAmbient)); - // Final atmosphere additive - componentMultBy(vars.hazeColor, LLColor3::white - temp1); - - sunlight = vars.sunlight; - temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, sun_norm[1] * 2.f); - temp2.mV[1] = 1.f / temp2.mV[1]; - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); + LLColor3 final_atten = LLColor3::white - temp1; + final_atten.mV[0] = llmax(final_atten.mV[0], 0.0f); + final_atten.mV[1] = llmax(final_atten.mV[1], 0.0f); + final_atten.mV[2] = llmax(final_atten.mV[2], 0.0f); - // Attenuate cloud color by atmosphere - temp1 = componentSqrt(temp1); //less atmos opacity (more transparency) below clouds + // Final atmosphere additive + componentMultBy(vars.hazeColor, final_atten); // At horizon, blend high altitude sky color towards the darker color below the clouds - vars.hazeColor += componentMult(vars.hazeColorBelowCloud - vars.hazeColor, LLColor3::white - componentSqrt(temp1)); - -#if SL_11371 - if (Pn[1] < 0.f) - { - // Eric's original: - // LLColor3 dark_brown(0.143f, 0.129f, 0.114f); - LLColor3 dark_brown(0.082f, 0.076f, 0.066f); - LLColor3 brown(0.430f, 0.386f, 0.322f); - LLColor3 sky_lighting = sunlight + ambient; - F32 haze_brightness = vars.hazeColor.brightness(); - - if (Pn[1] < -0.05f) - { - vars.hazeColor = colorMix(dark_brown, brown, -Pn[1] * 0.9f) * sky_lighting * haze_brightness; - } - - if (Pn[1] > -0.1f) - { - vars.hazeColor = colorMix(LLColor3::white * haze_brightness, vars.hazeColor, fabs((Pn[1] + 0.05f) * -20.f)); - } - } -#endif - -} - -LLColor3 LLAtmospherics::calcSkyColorWLFrag(LLVector3 & Pn, AtmosphericsVars& vars) -{ - LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); - - - LLColor3 res; - LLColor3 color0 = vars.hazeColor; - - if (!gPipeline.canUseWindLightShaders()) - { - res = psky->gammaCorrect(color0 * 2.0f); - } - else - { - res = color0; - } - -#ifndef LL_RELEASE_FOR_DOWNLOAD - F32 gamma = psky->getGamma(); - LLColor3 color2 = 2.f * color0; - LLColor3 color3 = LLColor3(1.f, 1.f, 1.f) - componentSaturate(color2); - componentPow(color3, gamma); - color3 = LLColor3(1.f, 1.f, 1.f) - color3; - - static enum { - OUT_DEFAULT = 0, - OUT_SKY_BLUE = 1, - OUT_RED = 2, - OUT_PN = 3, - OUT_HAZE = 4, - } debugOut = OUT_DEFAULT; - - switch(debugOut) - { - case OUT_DEFAULT: - break; - case OUT_SKY_BLUE: - res = LLColor3(0.4f, 0.4f, 0.9f); - break; - case OUT_RED: - res = LLColor3(1.f, 0.f, 0.f); - break; - case OUT_PN: - res = LLColor3(Pn[0], Pn[1], Pn[2]); - break; - case OUT_HAZE: - res = vars.hazeColor; - break; - } -#endif // LL_RELEASE_FOR_DOWNLOAD - return res; + vars.hazeColor += componentMult(vars.hazeColorBelowCloud - vars.hazeColor, final_atten); } void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in) @@ -520,10 +438,10 @@ void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in) vars.blue_horizon = psky->getBlueHorizon(); vars.haze_density = psky->getHazeDensity(); vars.haze_horizon = psky->getHazeHorizon(); - vars.density_multiplier = psky->getDensityMultiplier(); + vars.density_multiplier = psky->getDensityMultiplier(); vars.distance_multiplier = psky->getDistanceMultiplier(); vars.max_y = psky->getMaxY(); - vars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); + vars.sun_norm = LLEnvironment::instance().getLightDirectionCFR(); vars.sunlight = psky->getSunlightColor(); vars.ambient = psky->getAmbientColor(); vars.glow = psky->getGlow(); @@ -531,7 +449,9 @@ void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in) vars.dome_radius = psky->getDomeRadius(); vars.dome_offset = psky->getDomeOffset(); vars.light_atten = psky->getLightAttenuation(vars.max_y); - vars.light_transmittance = psky->getLightTransmittance(); + vars.light_transmittance = psky->getLightTransmittance(vars.max_y); + vars.total_density = psky->getTotalDensity(); + vars.gamma = psky->getGamma(); res_color[0] = calcSkyColorInDir(vars, tosun); res_color[1] = calcSkyColorInDir(vars, perp_tosun); diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index 22ed37f830..e304ac3043 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -204,8 +204,6 @@ public: , light_atten() , light_transmittance() { - horizontalProjection[0] = LLVector2(0,0); - horizontalProjection[1] = LLVector2(0,0); } LLColor3 hazeColor; @@ -213,7 +211,6 @@ public: LLColor3 cloudColorSun; LLColor3 cloudColorAmbient; F32 cloudDensity; - LLVector2 horizontalProjection[2]; LLColor3 blue_density; LLColor3 blue_horizon; F32 haze_density; @@ -231,6 +228,7 @@ public: F32 dome_offset; LLColor3 light_atten; LLColor3 light_transmittance; + LLColor3 total_density; }; class LLAtmospherics @@ -260,7 +258,6 @@ public: protected: void calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars); - LLColor3 calcSkyColorWLFrag(LLVector3 & Pn, AtmosphericsVars& vars); LLColor3 getHazeColor(LLSettingsSky::ptr_t psky, AtmosphericsVars& vars, F32 costheta, F32 cloud_shadow); LLHaze mHaze; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 745278bf0c..3afc57d9ba 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -207,16 +207,7 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { -#if USE_SRGB_DECODE - if (LLPipeline::RenderDeferred) - { - mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); - } - else -#endif - { - mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); - } + mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } @@ -478,7 +469,7 @@ void LLVOSky::init() m_atmosphericsVars.haze_horizon = psky->getHazeHorizon(); m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); - m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedLightNorm(); m_atmosphericsVars.sunlight = psky->getSunlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); @@ -486,7 +477,8 @@ void LLVOSky::init() m_atmosphericsVars.dome_radius = psky->getDomeRadius(); m_atmosphericsVars.dome_offset = psky->getDomeOffset(); m_atmosphericsVars.light_atten = psky->getLightAttenuation(m_atmosphericsVars.max_y); - m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(); + m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(m_atmosphericsVars.max_y); + m_atmosphericsVars.total_density = psky->getTotalDensity(); m_atmosphericsVars.gamma = psky->getGamma(); // Initialize the cached normalized direction vectors @@ -496,7 +488,7 @@ void LLVOSky::init() { initSkyTextureDirs(side, tile); createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex); + createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); } } @@ -527,8 +519,9 @@ void LLVOSky::calc() m_atmosphericsVars.haze_density = psky->getHazeDensity(); m_atmosphericsVars.haze_horizon = psky->getHazeHorizon(); m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); + m_atmosphericsVars.distance_multiplier = psky->getDistanceMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); - m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedLightNorm(); m_atmosphericsVars.sunlight = psky->getSunlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); @@ -536,72 +529,10 @@ void LLVOSky::calc() m_atmosphericsVars.dome_radius = psky->getDomeRadius(); m_atmosphericsVars.dome_offset = psky->getDomeOffset(); m_atmosphericsVars.light_atten = psky->getLightAttenuation(m_atmosphericsVars.max_y); - m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(); + m_atmosphericsVars.light_transmittance = psky->getLightTransmittance(m_atmosphericsVars.max_y); m_atmosphericsVars.gamma = psky->getGamma(); - LLColor3 vary_HazeColor; - LLColor3 vary_SunlightColor; - LLColor3 vary_AmbientColor; - { - // Initialize temp variables - LLColor3 sunlight = m_atmosphericsVars.sunlight; - - // Sunlight attenuation effect (hue and brightness) due to atmosphere - // this is used later for sunlight modulation at various altitudes - LLColor3 light_atten = - (m_atmosphericsVars.blue_density * 1.0 + smear(m_atmosphericsVars.haze_density * 0.25f)) * (m_atmosphericsVars.density_multiplier * m_atmosphericsVars.max_y); - - // Calculate relative weights - LLColor3 temp2(0.f, 0.f, 0.f); - LLColor3 temp1 = m_atmosphericsVars.blue_density + smear(m_atmosphericsVars.haze_density); - LLColor3 blue_weight = componentDiv(m_atmosphericsVars.blue_density, temp1); - LLColor3 haze_weight = componentDiv(smear(m_atmosphericsVars.haze_density), temp1); - - // Compute sunlight from P & lightnorm (for long rays like sky) - /// USE only lightnorm. - // temp2[1] = llmax(0.f, llmax(0.f, Pn[1]) * 1.0f + lightnorm[1] ); - F32 lighty = getSun().getDirection().mV[2]; - temp2.mV[1] = llmax(0.f, lighty); - if(temp2.mV[1] > 0.f) - { - temp2.mV[1] = 1.f / temp2.mV[1]; - } - componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1])); - - // Distance - temp2.mV[2] = m_atmosphericsVars.density_multiplier; - - // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); - - // vary_AtmosAttenuation = temp1; - - //increase ambient when there are more clouds - LLColor3 tmpAmbient = m_atmosphericsVars.ambient + (smear(1.f) - m_atmosphericsVars.ambient) * m_atmosphericsVars.cloud_shadow * 0.5f; - - //haze color - vary_HazeColor = - (m_atmosphericsVars.blue_horizon * blue_weight * (sunlight * (1.f - m_atmosphericsVars.cloud_shadow) + tmpAmbient) - + componentMult(m_atmosphericsVars.haze_horizon * haze_weight, sunlight * (1.f - m_atmosphericsVars.cloud_shadow) * temp2.mV[0] + tmpAmbient) - ); - - //brightness of surface both sunlight and ambient - vary_SunlightColor = componentMult(sunlight, temp1) * 1.f; - vary_SunlightColor.clamp(); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_SunlightColor = componentPow(vary_SunlightColor, m_atmosphericsVars.gamma); - vary_SunlightColor = smear(1.0f) - vary_SunlightColor; - vary_AmbientColor = componentMult(tmpAmbient, temp1) * 0.5; - vary_AmbientColor.clamp(); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; - vary_AmbientColor = componentPow(vary_AmbientColor, m_atmosphericsVars.gamma); - vary_AmbientColor = smear(1.0f) - vary_AmbientColor; - - componentMultBy(vary_HazeColor, LLColor3(1.f, 1.f, 1.f) - temp1); - - } - - mSun.setColor(vary_SunlightColor); + mSun.setColor(psky->getSunDiffuse()); mMoon.setColor(LLColor3(1.0f, 1.0f, 1.0f)); mSun.renewDirection(); @@ -617,17 +548,17 @@ void LLVOSky::initCubeMap() { images.push_back(mShinyTex[side].getImageRaw()); } - if (mCubeMap) + + if (!mCubeMap && gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) + { + mCubeMap = new LLCubeMap(true); + } + + if (mCubeMap) { mCubeMap->init(images); } - else if (gSavedSettings.getBOOL("RenderWater") && gGLManager.mHasCubeMap && LLCubeMap::sUseCubeMaps) - { - bool wantsRGB = LLPipeline::RenderDeferred; - mCubeMap = new LLCubeMap(wantsRGB); - mCubeMap->init(images); - } gGL.getTexUnit(0)->disable(); } @@ -709,7 +640,7 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) } } -void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex) +void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex, bool is_shiny) { S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; @@ -722,7 +653,7 @@ void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 { for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) { - tex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, tex[side].getDir(x, y), true), x, y); + tex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, tex[side].getDir(x, y), is_shiny), x, y); } } } @@ -740,9 +671,6 @@ void LLVOSky::updateDirections(void) mSun.setRotation(psky->getSunRotation()); mMoon.setRotation(psky->getMoonRotation()); - mSun.setColor(psky->getSunlightColor()); - mMoon.setColor(psky->getMoonDiffuse()); - mSun.renewDirection(); mSun.renewColor(); mMoon.renewDirection(); @@ -834,7 +762,7 @@ bool LLVOSky::updateSky() { for (int tile = 0; tile < NUM_TILES; tile++) { - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex); + createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); } } diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index e118cc7200..3c7ce4004c 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -303,7 +303,7 @@ protected: void updateDirections(void); void initSkyTextureDirs(const S32 side, const S32 tile); - void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex); + void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex, bool is_shiny = false); LLPointer mSunTexturep[2]; LLPointer mMoonTexturep[2]; -- cgit v1.3 From 695ec5229f6c8c80625e7d445232ae5fb0011327 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 11 Jul 2019 08:33:41 -0700 Subject: Fix knock-on from touching the sky tex gen which also generated the shiny env map. --- indra/newview/lllegacyatmospherics.cpp | 2 +- indra/newview/llvosky.cpp | 21 +++++++++++++++------ indra/newview/llvosky.h | 4 +++- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index d56e6bd5d6..68613be19c 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -242,7 +242,7 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto calcSkyColorWLVert(Pn, vars); - LLColor3 sky_color = psky->gammaCorrect(vars.hazeColor * 2.0f); + LLColor3 sky_color = isShiny ? vars.hazeColor : psky->gammaCorrect(vars.hazeColor * 2.0f); if (isShiny) { diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 3afc57d9ba..cf3132447d 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -96,12 +96,14 @@ S32 LLSkyTex::sCurrent = 0; LLSkyTex::LLSkyTex() : mSkyData(NULL), - mSkyDirs(NULL) + mSkyDirs(NULL), + mIsShiny(false) { } -void LLSkyTex::init() +void LLSkyTex::init(bool isShiny) { + mIsShiny = isShiny; mSkyData = new LLColor4[sResolution * sResolution]; mSkyDirs = new LLVector3[sResolution * sResolution]; @@ -207,7 +209,14 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { - mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + if (mIsShiny) + { + mTexture[which]->setExplicitFormat(GL_RGBA8, GL_RGBA); + } + else + { + mTexture[which]->setExplicitFormat(GL_SRGB8_ALPHA8, GL_RGBA); + } mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } @@ -421,8 +430,8 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) for (S32 i = 0; i < 6; i++) { - mSkyTex[i].init(); - mShinyTex[i].init(); + mSkyTex[i].init(false); + mShinyTex[i].init(true); } for (S32 i=0; i Date: Tue, 16 Jul 2019 10:40:01 -0700 Subject: SL-11605 Fix broken throttling of sky/envmap updates. --- indra/llrender/llvertexbuffer.cpp | 2 - indra/newview/llvosky.cpp | 92 ++++++++++++++++++++++----------------- indra/newview/llvosky.h | 1 + 3 files changed, 54 insertions(+), 41 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 2ac17127be..f498526367 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -761,8 +761,6 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; - llassert(idx); - stop_glerror(); LLGLSLShader::startProfile(); glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index cf3132447d..ad452659c6 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -424,6 +424,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mInitialized = FALSE; mbCanSelect = FALSE; + mUpdateTimer.reset(); mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); mForceUpdateThrottle.reset(); @@ -706,6 +707,7 @@ bool LLVOSky::updateSky() // It's dead. Don't update it. return TRUE; } + if (gGLManager.mIsDisabled) { return TRUE; @@ -746,11 +748,12 @@ bool LLVOSky::updateSky() mForceUpdate = mForceUpdate || moon_direction_changed; mForceUpdate = mForceUpdate || color_changed; mForceUpdate = mForceUpdate || !mInitialized; - mForceUpdate = mForceUpdate || mForceUpdateThrottle.hasExpired(); + + bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); calc(); - if (mForceUpdate) + if (mForceUpdate && mForceUpdateThrottle.hasExpired()) { LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); @@ -759,62 +762,73 @@ bool LLVOSky::updateSky() LLSkyTex::stepCurrent(); if (!direction.isExactlyZero()) - { - mInitialized = TRUE; - - updateFog(LLViewerCamera::getInstance()->getFar()); + { mLastTotalAmbient = total_ambient; + mInitialized = TRUE; if (mCubeMap) { - for (int side = 0; side < 6; side++) - { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); - } - } - - int tex = mShinyTex[0].getWhich(TRUE); - - for (int side = 0; side < 6; side++) - { - LLImageRaw* raw1 = nullptr; - LLImageRaw* raw2 = nullptr; - raw1 = mShinyTex[side].getImageRaw(TRUE); - raw2 = mShinyTex[side].getImageRaw(FALSE); - raw2->copy(raw1); - mShinyTex[side].createGLImage(tex); - mShinyTex[side].create(1.0f); - } - initCubeMap(); - } + updateFog(LLViewerCamera::getInstance()->getFar()); - // if we're using a generated sky cubemap instead of rendered sky... - if (!gPipeline.canUseWindLightShaders()) - { 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); + int tex = mSkyTex[0].getWhich(TRUE); - for (int side = 0; side < 6; side++) - { - LLImageRaw* raw1 = nullptr; - LLImageRaw* raw2 = nullptr; + for (int side = 0; side < 6; 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); - mSkyTex[side].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 sky texture + if (!is_alm_wl_sky) + { + for (S32 i = 0; i < 6; ++i) + { + mSkyTex[i].create(1.0f); + } + } + + for (S32 i = 0; i < 6; ++i) + { + mShinyTex[i].create(1.0f); + } + + // update the environment map + if (mCubeMap) + { + std::vector > 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(); + } + } gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); mForceUpdate = FALSE; diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 67a7059b5a..8c2817e1ed 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -352,6 +352,7 @@ protected: LLPointer mCubeMap; // Cube map for the environment S32 mDrawRefl; + LLFrameTimer mUpdateTimer; LLTimer mForceUpdateThrottle; bool mHeavenlyBodyUpdated ; -- cgit v1.3 From 41c7523e08aab7f2bf4a040ac1c1c8a1d24babed Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2019 13:44:59 -0700 Subject: SL-11676 Make sun/moon textures render on Low/Low-Mid again. Fix solar additive being present when moon was only heavenly body in sky. --- indra/newview/lldrawpoolsky.cpp | 55 +++++++++++++++++++++------------- indra/newview/lldrawpoolsky.h | 2 +- indra/newview/lllegacyatmospherics.cpp | 2 +- indra/newview/llvosky.cpp | 22 ++++++++------ indra/newview/llvosky.h | 7 ++--- 5 files changed, 52 insertions(+), 36 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index 12614b5e2d..dbe8724088 100644 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -111,37 +111,52 @@ void LLDrawPoolSky::render(S32 pass) LLVertexBuffer::unbind(); gGL.diffuseColor4f(1,1,1,1); - for (S32 i = 0; i < llmin(6, face_count); ++i) + for (S32 i = 0; i < face_count; ++i) { - renderSkyCubeFace(i); + renderSkyFace(i); } gGL.popMatrix(); } -void LLDrawPoolSky::renderSkyCubeFace(U8 side) +void LLDrawPoolSky::renderSkyFace(U8 index) { - LLFace &face = *mDrawFace[LLVOSky::FACE_SIDE0 + side]; - if (!face.getGeomCount()) + LLFace* face = mDrawFace[index]; + + if (!face || !face->getGeomCount()) { return; } - llassert(mSkyTex); - mSkyTex[side].bindTexture(TRUE); - - gGL.getTexUnit(0)->setTextureColorSpace(LLTexUnit::TCS_SRGB); - - face.renderIndexed(); - - if (LLSkyTex::doInterpolate()) - { - - LLGLEnable blend(GL_BLEND); - mSkyTex[side].bindTexture(FALSE); - gGL.diffuseColor4f(1, 1, 1, LLSkyTex::getInterpVal()); // lighting is disabled - face.renderIndexed(); - } + F32 interp_val = gSky.mVOSkyp ? gSky.mVOSkyp->getInterpVal() : 0.0f; + + if (index < 6) // sky tex...interp + { + llassert(mSkyTex); + mSkyTex[index].bindTexture(true); // bind the current tex + + face->renderIndexed(); + + if (interp_val > 0.01f) // iff, we've got enough info to lerp (a to and a from) + { + LLGLEnable blend(GL_BLEND); + llassert(mSkyTex); + mSkyTex[index].bindTexture(false); // bind the "other" texture + gGL.diffuseColor4f(1, 1, 1, interp_val); // lighting is disabled + face->renderIndexed(); + } + } + else // heavenly body faces, no interp... + { + LLGLEnable blend(GL_BLEND); + + LLViewerTexture* tex = face->getTexture(LLRender::DIFFUSE_MAP); + if (tex) + { + gGL.getTexUnit(0)->bind(tex, true); + face->renderIndexed(); + } + } } void LLDrawPoolSky::endRenderPass( S32 pass ) diff --git a/indra/newview/lldrawpoolsky.h b/indra/newview/lldrawpoolsky.h index 098bd2134a..916d8c1cbe 100644 --- a/indra/newview/lldrawpoolsky.h +++ b/indra/newview/lldrawpoolsky.h @@ -61,7 +61,7 @@ public: /*virtual*/ void endRenderPass(S32 pass); void setSkyTex(LLSkyTex* const st) { mSkyTex = st; } - void renderSkyCubeFace(U8 side); + void renderSkyFace(U8 index); void renderHeavenlyBody(U8 hb, LLFace* face); void renderSunHalo(LLFace* face); diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index 1660a1897e..720c7e2388 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -442,7 +442,7 @@ void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in) vars.density_multiplier = psky->getDensityMultiplier(); vars.distance_multiplier = psky->getDistanceMultiplier(); vars.max_y = psky->getMaxY(); - vars.sun_norm = LLEnvironment::instance().getLightDirectionCFR(); + vars.sun_norm = LLEnvironment::instance().getSunDirectionCFR(); vars.sunlight = psky->getSunlightColor(); vars.ambient = psky->getAmbientColor(); vars.glow = psky->getGlow(); diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index ad452659c6..8d5c0f04cd 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -90,7 +90,6 @@ namespace S32 LLSkyTex::sComponents = 4; S32 LLSkyTex::sResolution = 64; -F32 LLSkyTex::sInterpVal = 0.f; S32 LLSkyTex::sCurrent = 0; @@ -479,7 +478,7 @@ void LLVOSky::init() m_atmosphericsVars.haze_horizon = psky->getHazeHorizon(); m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); - m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedLightNorm(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); m_atmosphericsVars.sunlight = psky->getSunlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); @@ -531,7 +530,7 @@ void LLVOSky::calc() m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); m_atmosphericsVars.distance_multiplier = psky->getDistanceMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); - m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedLightNorm(); + m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); m_atmosphericsVars.sunlight = psky->getSunlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); @@ -725,8 +724,6 @@ bool LLVOSky::updateSky() next_frame = next_frame % cycle_frame_no; mInterpVal = (!mInitialized) ? 1 : (F32)next_frame / cycle_frame_no; - // sInterpVal = (F32)next_frame / cycle_frame_no; - LLSkyTex::setInterpVal( mInterpVal ); LLHeavenBody::setInterpVal( mInterpVal ); updateDirections(); @@ -912,6 +909,8 @@ void LLVOSky::setSunTextures(const LLUUID& sun_texture, const LLUUID& sun_textur mSunTexturep[0] = sun_texture.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(sun_texture, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); mSunTexturep[1] = sun_texture_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(sun_texture_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); + bool can_use_wl = gPipeline.canUseWindLightShaders(); + if (mFace[FACE_SUN]) { if (mSunTexturep[0]) @@ -934,11 +933,14 @@ void LLVOSky::setSunTextures(const LLUUID& sun_texture, const LLUUID& sun_textur mFace[FACE_SUN]->setTexture(LLRender::DIFFUSE_MAP, mSunTexturep[0]); - if (mSunTexturep[1]) + if (can_use_wl) { - mSunTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); + if (mSunTexturep[1]) + { + mSunTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); + } + mFace[FACE_SUN]->setTexture(LLRender::ALTERNATE_DIFFUSE_MAP, mSunTexturep[1]); } - mFace[FACE_SUN]->setTexture(LLRender::ALTERNATE_DIFFUSE_MAP, mSunTexturep[1]); } } @@ -946,6 +948,8 @@ void LLVOSky::setMoonTextures(const LLUUID& moon_texture, const LLUUID& moon_tex { LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + bool can_use_wl = gPipeline.canUseWindLightShaders(); + mMoonTexturep[0] = moon_texture.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(moon_texture, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); mMoonTexturep[1] = moon_texture_next.isNull() ? nullptr : LLViewerTextureManager::getFetchedTexture(moon_texture_next, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_UI); @@ -957,7 +961,7 @@ void LLVOSky::setMoonTextures(const LLUUID& moon_texture, const LLUUID& moon_tex } mFace[FACE_MOON]->setTexture(LLRender::DIFFUSE_MAP, mMoonTexturep[0]); - if (mMoonTexturep[1]) + if (mMoonTexturep[1] && can_use_wl) { mMoonTexturep[1]->setAddressMode(LLTexUnit::TAM_CLAMP); mFace[FACE_MOON]->setTexture(LLRender::ALTERNATE_DIFFUSE_MAP, mMoonTexturep[1]); diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 8c2817e1ed..5f27085599 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -57,13 +57,8 @@ private: LLColor4 *mSkyData; LLVector3 *mSkyDirs; // Cache of sky direction vectors static S32 sCurrent; - static F32 sInterpVal; public: - static F32 getInterpVal() { return sInterpVal; } - static void setInterpVal(const F32 v) { sInterpVal = v; } - static BOOL doInterpolate() { return sInterpVal > 0.001f; } - void bindTexture(BOOL curr = TRUE); protected: @@ -299,6 +294,8 @@ public: LLFace *mFace[FACE_COUNT]; LLVector3 mBumpSunDir; + F32 getInterpVal() const { return mInterpVal; } + protected: ~LLVOSky(); -- cgit v1.3 From 5937a4222473131d0cec4238fc234646e9aba91e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2019 14:25:35 -0700 Subject: SL-10566, SL-10677 Make sky updates only occur if the input atmospherics values have actually changed (perf optimization). Make water rendering use specular color for coloring spec. --- indra/newview/lldrawpoolwater.cpp | 3 + indra/newview/lllegacyatmospherics.h | 111 +++++++++++++++++++++++++++++++++++ indra/newview/llvosky.cpp | 10 +++- 3 files changed, 121 insertions(+), 3 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 1b5c154378..13420fc001 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -500,6 +500,9 @@ void LLDrawPoolWater::shade2(bool edge, LLGLSLShader* shader, const LLColor3& li } } + LLColor4 specular(psky->getIsSunUp() ? psky->getSunlightColor() : psky->getMoonlightColor()); + shader->uniform4fv(LLShaderMgr::SPECULAR_COLOR, 1, specular.mV); + sTime = (F32)LLFrameTimer::getElapsedSeconds() * 0.5f; S32 reftex = shader->enableTexture(LLShaderMgr::WATER_REFTEX); diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index e304ac3043..95700227f9 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -206,6 +206,8 @@ public: { } + LL_FORCE_INLINE friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b); + LLColor3 hazeColor; LLColor3 hazeColorBelowCloud; LLColor3 cloudColorSun; @@ -231,6 +233,115 @@ public: LLColor3 total_density; }; +bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b) +{ + if (a.hazeColor != b.hazeColor) + { + return false; + } + + if (a.hazeColorBelowCloud != b.hazeColorBelowCloud) + { + return false; + } + + if (a.cloudColorSun != b.cloudColorSun) + { + return false; + } + + if (a.cloudColorAmbient != b.cloudColorAmbient) + { + return false; + } + + if (a.cloudDensity != b.cloudDensity) + { + return false; + } + + if (a.density_multiplier != b.density_multiplier) + { + return false; + } + + if (a.haze_horizon != b.haze_horizon) + { + return false; + } + + if (a.haze_density != b.haze_density) + { + return false; + } + + if (a.blue_horizon != b.blue_horizon) + { + return false; + } + + if (a.blue_density != b.blue_density) + { + return false; + } + + if (a.dome_offset != b.dome_offset) + { + return false; + } + + if (a.dome_radius != b.dome_radius) + { + return false; + } + + if (a.cloud_shadow != b.cloud_shadow) + { + return false; + } + + if (a.glow != b.glow) + { + return false; + } + + if (a.ambient != b.ambient) + { + return false; + } + + if (a.sunlight != b.sunlight) + { + return false; + } + + if (a.sun_norm != b.sun_norm) + { + return false; + } + + if (a.gamma != b.gamma) + { + return false; + } + + if (a.max_y != b.max_y) + { + return false; + } + + if (a.distance_multiplier != b.distance_multiplier) + { + return false; + } + + // light_atten, light_transmittance, total_density + // are ignored as they always change when the values above do + // they're just shared calc across the sky map generation to save cycles + + return true; +} + class LLAtmospherics { public: diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 8d5c0f04cd..78c782eb5f 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -479,7 +479,7 @@ void LLVOSky::init() m_atmosphericsVars.density_multiplier = psky->getDensityMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); - m_atmosphericsVars.sunlight = psky->getSunlightColor(); + m_atmosphericsVars.sunlight = psky->getIsSunUp() ? psky->getSunlightColor() : psky->getMoonlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); m_atmosphericsVars.cloud_shadow = psky->getCloudShadow(); @@ -531,7 +531,7 @@ void LLVOSky::calc() m_atmosphericsVars.distance_multiplier = psky->getDistanceMultiplier(); m_atmosphericsVars.max_y = psky->getMaxY(); m_atmosphericsVars.sun_norm = LLEnvironment::instance().getClampedSunNorm(); - m_atmosphericsVars.sunlight = psky->getSunlightColor(); + m_atmosphericsVars.sunlight = psky->getIsSunUp() ? psky->getSunlightColor() : psky->getMoonlightColor(); m_atmosphericsVars.ambient = psky->getAmbientColor(); m_atmosphericsVars.glow = psky->getGlow(); m_atmosphericsVars.cloud_shadow = psky->getCloudShadow(); @@ -750,7 +750,9 @@ bool LLVOSky::updateSky() calc(); - if (mForceUpdate && mForceUpdateThrottle.hasExpired()) + bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; + + if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics) { LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); @@ -758,6 +760,8 @@ bool LLVOSky::updateSky() LLSkyTex::stepCurrent(); + m_lastAtmosphericsVars = m_atmosphericsVars; + if (!direction.isExactlyZero()) { mLastTotalAmbient = total_ambient; -- cgit v1.3 From be74485334267339dee14018aa82f84cc34b0ecb Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Thu, 22 Aug 2019 20:33:34 +0300 Subject: SL-11776 Compensate freeze by spreading calculations --- indra/newview/llvosky.cpp | 218 ++++++++++++++++++++++++++-------------------- indra/newview/llvosky.h | 3 +- 2 files changed, 126 insertions(+), 95 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 78c782eb5f..408da88c3f 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; @@ -80,6 +81,8 @@ namespace 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); @@ -416,6 +419,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mCloudDensity(0.2f), mWind(0.f), mForceUpdate(FALSE), + mCubeMapUpdateStage(-1), mWorldScale(1.f), mBumpSunDir(0.f, 0.f, 1.f) { @@ -428,7 +432,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 +495,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 +553,7 @@ void LLVOSky::calc() void LLVOSky::initCubeMap() { std::vector > 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 +575,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 +588,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 +608,8 @@ void LLVOSky::restoreGL() initCubeMap(); } - mForceUpdate = TRUE; + mForceUpdate = TRUE; + mCubeMapUpdateStage = -1; if (mDrawable) { @@ -713,7 +714,7 @@ bool LLVOSky::updateSky() } 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; @@ -727,112 +728,141 @@ 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; + if (mCubeMapUpdateStage < 0) + { + LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC); + calc(); - 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]); + LLVector3 direction = mSun.getDirection(); + direction.normalize(); + const F32 dot_sun = direction * mLastSunLightingDirection; + const F32 dot_moon = direction * mLastMoonLightingDirection; - 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); + 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]); - mForceUpdate = mForceUpdate || sun_direction_changed; - mForceUpdate = mForceUpdate || moon_direction_changed; - mForceUpdate = mForceUpdate || color_changed; - mForceUpdate = mForceUpdate || !mInitialized; + 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); - bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + mForceUpdate = mForceUpdate || sun_direction_changed; + mForceUpdate = mForceUpdate || moon_direction_changed; + mForceUpdate = mForceUpdate || color_changed; + mForceUpdate = mForceUpdate || !mInitialized; - calc(); + bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; - bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; + if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics) + { + // start updating cube map sides + if (mCubeMap && !direction.isExactlyZero()) + { + updateFog(LLViewerCamera::getInstance()->getFar()); - if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics) - { + mCubeMapUpdateStage = 0; + } + else + { + mCubeMapUpdateStage = NUM_CUBEMAP_FACES; + } + 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; - - 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); - } - } - } - + LLVector3 direction = mSun.getDirection(); + if (!direction.isExactlyZero()) + { + bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); int tex = mSkyTex[0].getWhich(TRUE); - for (int side = 0; side < 6; side++) - { + 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); + 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 + // update the sky texture if (!is_alm_wl_sky) { - for (S32 i = 0; i < 6; ++i) - { + for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) + { 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 > 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 + if (mCubeMap) + { + std::vector > 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(); + } + } + + 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); + + LLVector3 direction = mSun.getDirection(); + if (!direction.isExactlyZero()) + { + mLastTotalAmbient = total_ambient; + mInitialized = TRUE; - gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - mForceUpdate = FALSE; + 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; + } } if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 5f27085599..c3a04e12e5 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -337,7 +337,8 @@ protected: F32 mWind; bool mInitialized; - bool mForceUpdate; //flag to force instantaneous update of cubemap + bool mForceUpdate; // flag to force update of cubemap + S32 mCubeMapUpdateStage; // state of cubemap uodate: -1 idle; 0-5 per-face updates; 6 finalizing LLVector3 mLastSunLightingDirection; LLVector3 mLastMoonLightingDirection; LLColor3 mLastTotalAmbient; -- cgit v1.3 From 8960a56f531745bc2d434bdddb6c65731621f596 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 22 Aug 2019 11:19:04 -0700 Subject: SL-11776 Fix false alarming sky updates and doing expensive CPU work for same sky pixels. --- indra/llinventory/llsettingssky.cpp | 41 ++++++++++ indra/llinventory/llsettingssky.h | 3 + indra/newview/lllegacyatmospherics.cpp | 117 ++++++++++++++++++++++++++- indra/newview/lllegacyatmospherics.h | 111 +------------------------- indra/newview/llviewershadermgr.cpp | 2 +- indra/newview/llvosky.cpp | 140 +++++++++++++++++---------------- indra/newview/llvosky.h | 3 +- 7 files changed, 234 insertions(+), 183 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp index 35bd9a2254..9bbeb00efe 100644 --- a/indra/llinventory/llsettingssky.cpp +++ b/indra/llinventory/llsettingssky.cpp @@ -1051,6 +1051,19 @@ LLColor3 LLSettingsSky::getAmbientColor() const return getColor(SETTING_AMBIENT, LLColor3(0.25f, 0.25f, 0.25f)); } +LLColor3 LLSettingsSky::getAmbientColorClamped() const +{ + LLColor3 ambient = getAmbientColor(); + + F32 max_color = llmax(ambient.mV[0], ambient.mV[1], ambient.mV[2]); + if (max_color > 1.0f) + { + ambient *= 1.0f/max_color; + } + + return ambient; +} + LLColor3 LLSettingsSky::getBlueDensity() const { return getColor(SETTING_BLUE_DENSITY, LLColor3(0.2447f, 0.4487f, 0.7599f)); @@ -1313,10 +1326,23 @@ void LLSettingsSky::calculateLightSettings() const componentMultBy(sunlight, componentExp((light_atten * -1.f) * lighty)); componentMultBy(sunlight, light_transmittance); + //F32 max_color = llmax(sunlight.mV[0], sunlight.mV[1], sunlight.mV[2]); + //if (max_color > 1.0f) + //{ + // sunlight *= 1.0f/max_color; + //} + //increase ambient when there are more clouds LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5; componentMultBy(tmpAmbient, light_transmittance); + //tmpAmbient = LLColor3::clamp(tmpAmbient, getGamma(), 1.0f); + //max_color = llmax(tmpAmbient.mV[0], tmpAmbient.mV[1], tmpAmbient.mV[2]); + //if (max_color > 1.0f) + //{ + // tmpAmbient *= 1.0f/max_color; + //} + //brightness of surface both sunlight and ambient mSunDiffuse = sunlight; mSunAmbient = tmpAmbient; @@ -1334,6 +1360,7 @@ void LLSettingsSky::calculateLightSettings() const LLColor3 moonlight_b(0.66, 0.66, 1.2); // scotopic ambient value componentMultBy(moonlight, componentExp((light_atten * -1.f) * lighty)); + //clampColor(moonlight, getGamma(), 1.0f); mMoonDiffuse = componentMult(moonlight, light_transmittance) * moon_brightness; mMoonAmbient = componentMult(moonlight_b, light_transmittance) * 0.0125f; @@ -1676,6 +1703,20 @@ LLColor3 LLSettingsSky::getSunlightColor() const return LLColor3(mSettings[SETTING_SUNLIGHT_COLOR]); } +LLColor3 LLSettingsSky::getSunlightColorClamped() const +{ + LLColor3 sunlight = getSunlightColor(); + //clampColor(sunlight, getGamma(), 3.0f); + + F32 max_color = llmax(sunlight.mV[0], sunlight.mV[1], sunlight.mV[2]); + if (max_color > 1.0f) + { + sunlight *= 1.0f/max_color; + } + + return sunlight; +} + void LLSettingsSky::setSunlightColor(const LLColor3 &val) { setValue(SETTING_SUNLIGHT_COLOR, val); diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h index e562fe38ff..4127911643 100644 --- a/indra/llinventory/llsettingssky.h +++ b/indra/llinventory/llsettingssky.h @@ -292,6 +292,9 @@ public: LLColor4 getTotalAmbient() const; LLColor4 getHazeColor() const; + LLColor3 getSunlightColorClamped() const; + LLColor3 getAmbientColorClamped() const; + virtual LLSettingsBase::ptr_t buildDerivedClone() const SETTINGS_OVERRIDE { return buildClone(); } static LLUUID GetDefaultAssetId(); diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index 720c7e2388..a1093df7e1 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -242,8 +242,10 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto calcSkyColorWLVert(Pn, vars); + bool low_end = !gPipeline.canUseWindLightShaders(); + LLColor3 sky_color = isShiny ? vars.hazeColor : - !gPipeline.canUseWindLightShaders() ? vars.hazeColor * 2.0f : psky->gammaCorrect(vars.hazeColor * 2.0f); + low_end ? vars.hazeColor * 2.0f : psky->gammaCorrect(vars.hazeColor * 2.0f); if (isShiny) { @@ -443,8 +445,8 @@ void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in) vars.distance_multiplier = psky->getDistanceMultiplier(); vars.max_y = psky->getMaxY(); vars.sun_norm = LLEnvironment::instance().getSunDirectionCFR(); - vars.sunlight = psky->getSunlightColor(); - vars.ambient = psky->getAmbientColor(); + vars.sunlight = psky->getSunlightColorClamped(); + vars.ambient = psky->getAmbientColorClamped(); vars.glow = psky->getGlow(); vars.cloud_shadow = psky->getCloudShadow(); vars.dome_radius = psky->getDomeRadius(); @@ -605,3 +607,112 @@ F32 azimuth(const LLVector3 &v) } return azimuth; } + +bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b) +{ + if (a.hazeColor != b.hazeColor) + { + return false; + } + + if (a.hazeColorBelowCloud != b.hazeColorBelowCloud) + { + return false; + } + + if (a.cloudColorSun != b.cloudColorSun) + { + return false; + } + + if (a.cloudColorAmbient != b.cloudColorAmbient) + { + return false; + } + + if (a.cloudDensity != b.cloudDensity) + { + return false; + } + + if (a.density_multiplier != b.density_multiplier) + { + return false; + } + + if (a.haze_horizon != b.haze_horizon) + { + return false; + } + + if (a.haze_density != b.haze_density) + { + return false; + } + + if (a.blue_horizon != b.blue_horizon) + { + return false; + } + + if (a.blue_density != b.blue_density) + { + return false; + } + + if (a.dome_offset != b.dome_offset) + { + return false; + } + + if (a.dome_radius != b.dome_radius) + { + return false; + } + + if (a.cloud_shadow != b.cloud_shadow) + { + return false; + } + + if (a.glow != b.glow) + { + return false; + } + + if (a.ambient != b.ambient) + { + return false; + } + + if (a.sunlight != b.sunlight) + { + return false; + } + + if (a.sun_norm != b.sun_norm) + { + return false; + } + + if (a.gamma != b.gamma) + { + return false; + } + + if (a.max_y != b.max_y) + { + return false; + } + + if (a.distance_multiplier != b.distance_multiplier) + { + return false; + } + + // light_atten, light_transmittance, total_density + // are ignored as they always change when the values above do + // they're just shared calc across the sky map generation to save cycles + + return true; +} diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index 95700227f9..cdfcead7a4 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -206,7 +206,7 @@ public: { } - LL_FORCE_INLINE friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b); + friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b); LLColor3 hazeColor; LLColor3 hazeColorBelowCloud; @@ -233,115 +233,6 @@ public: LLColor3 total_density; }; -bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b) -{ - if (a.hazeColor != b.hazeColor) - { - return false; - } - - if (a.hazeColorBelowCloud != b.hazeColorBelowCloud) - { - return false; - } - - if (a.cloudColorSun != b.cloudColorSun) - { - return false; - } - - if (a.cloudColorAmbient != b.cloudColorAmbient) - { - return false; - } - - if (a.cloudDensity != b.cloudDensity) - { - return false; - } - - if (a.density_multiplier != b.density_multiplier) - { - return false; - } - - if (a.haze_horizon != b.haze_horizon) - { - return false; - } - - if (a.haze_density != b.haze_density) - { - return false; - } - - if (a.blue_horizon != b.blue_horizon) - { - return false; - } - - if (a.blue_density != b.blue_density) - { - return false; - } - - if (a.dome_offset != b.dome_offset) - { - return false; - } - - if (a.dome_radius != b.dome_radius) - { - return false; - } - - if (a.cloud_shadow != b.cloud_shadow) - { - return false; - } - - if (a.glow != b.glow) - { - return false; - } - - if (a.ambient != b.ambient) - { - return false; - } - - if (a.sunlight != b.sunlight) - { - return false; - } - - if (a.sun_norm != b.sun_norm) - { - return false; - } - - if (a.gamma != b.gamma) - { - return false; - } - - if (a.max_y != b.max_y) - { - return false; - } - - if (a.distance_multiplier != b.distance_multiplier) - { - return false; - } - - // light_atten, light_transmittance, total_density - // are ignored as they always change when the values above do - // they're just shared calc across the sky map generation to save cycles - - return true; -} - class LLAtmospherics { public: diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index c874b3cf59..aca236cdfd 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -528,7 +528,7 @@ void LLViewerShaderMgr::setShaders() } // Trigger a full rebuild of the fallback skybox / cubemap if we've toggled windlight shaders - if (mShaderLevel[SHADER_WINDLIGHT] != wl_class && gSky.mVOSkyp.notNull()) + if (!wl_class || (mShaderLevel[SHADER_WINDLIGHT] != wl_class && gSky.mVOSkyp.notNull())) { gSky.mVOSkyp->forceSkyUpdate(); } diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 78c782eb5f..ae63a9921c 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -416,6 +416,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mCloudDensity(0.2f), mWind(0.f), mForceUpdate(FALSE), + mNeedUpdate(TRUE), mWorldScale(1.f), mBumpSunDir(0.f, 0.f, 1.f) { @@ -608,7 +609,7 @@ void LLVOSky::restoreGL() initCubeMap(); } - mForceUpdate = TRUE; + forceSkyUpdate(); if (mDrawable) { @@ -690,6 +691,13 @@ 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(); @@ -718,7 +726,7 @@ bool LLVOSky::updateSky() 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; @@ -727,10 +735,13 @@ 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; + LLVector3 sun_dir = mSun.getDirection(); + sun_dir.normalize(); + LLVector3 moon_dir = mMoon.getDirection(); + moon_dir.normalize(); + + const F32 dot_sun = sun_dir * mLastSunLightingDirection; + const F32 dot_moon = moon_dir * mLastMoonLightingDirection; LLColor3 delta_color; delta_color.setVec(mLastTotalAmbient.mV[0] - total_ambient.mV[0], @@ -741,10 +752,10 @@ bool LLVOSky::updateSky() 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; + mNeedUpdate = mNeedUpdate || sun_direction_changed; + mNeedUpdate = mNeedUpdate || moon_direction_changed; + mNeedUpdate = mNeedUpdate || color_changed; + mNeedUpdate = mNeedUpdate || !mInitialized; bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); @@ -752,7 +763,7 @@ bool LLVOSky::updateSky() bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; - if (mForceUpdate && mForceUpdateThrottle.hasExpired() && !same_atmospherics) + if (mNeedUpdate && mForceUpdateThrottle.hasExpired() && (mForceUpdate || !same_atmospherics)) { LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); @@ -762,77 +773,76 @@ bool LLVOSky::updateSky() m_lastAtmosphericsVars = m_atmosphericsVars; - if (!direction.isExactlyZero()) + mLastTotalAmbient = total_ambient; + mInitialized = TRUE; + + if (mCubeMap) { - mLastTotalAmbient = total_ambient; - mInitialized = TRUE; + updateFog(LLViewerCamera::getInstance()->getFar()); - if (mCubeMap) + for (int side = 0; side < 6; side++) { - updateFog(LLViewerCamera::getInstance()->getFar()); - - for (int side = 0; side < 6; side++) + for (int tile = 0; tile < NUM_TILES; tile++) { - for (int tile = 0; tile < NUM_TILES; tile++) - { - createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); - } + 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; - - 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 < 6; side++) + { + LLImageRaw* raw1 = nullptr; + LLImageRaw* raw2 = nullptr; - // update the sky texture if (!is_alm_wl_sky) { - for (S32 i = 0; i < 6; ++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 < 6; ++i) + 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) + { + for (S32 i = 0; i < 6; ++i) { - mShinyTex[i].create(1.0f); + mSkyTex[i].create(1.0f); } + } + + for (S32 i = 0; i < 6; ++i) + { + mShinyTex[i].create(1.0f); + } - // update the environment map - if (mCubeMap) + // update the environment map + if (mCubeMap) + { + std::vector > images; + images.reserve(6); + for (S32 side = 0; side < 6; side++) { - std::vector > 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(); - } + images.push_back(mShinyTex[side].getImageRaw(TRUE)); + } + mCubeMap->init(images); + gGL.getTexUnit(0)->disable(); } gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); - mForceUpdate = FALSE; + + mNeedUpdate = FALSE; + mForceUpdate = FALSE; } if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) @@ -1605,8 +1615,6 @@ void LLVOSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir_cfr, const LLV } updateDirections(); - - mForceUpdate = true; } void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr) @@ -1630,8 +1638,6 @@ void LLVOSky::setSunDirectionCFR(const LLVector3 &sun_dir_cfr) } updateDirections(); - - mForceUpdate = true; } void LLVOSky::setMoonDirectionCFR(const LLVector3 &moon_dir_cfr) @@ -1639,6 +1645,4 @@ void LLVOSky::setMoonDirectionCFR(const LLVector3 &moon_dir_cfr) mMoon.setDirection(moon_dir_cfr); updateDirections(); - - mForceUpdate = true; } diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index 5f27085599..6c9d6dc8be 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -288,7 +288,7 @@ public: void setSunScale(F32 sun_scale); void setMoonScale(F32 sun_scale); - void forceSkyUpdate(void) { mForceUpdate = TRUE; } + void forceSkyUpdate(void); public: LLFace *mFace[FACE_COUNT]; @@ -337,6 +337,7 @@ protected: F32 mWind; bool mInitialized; + bool mNeedUpdate; //flag to mark update being necessary (input has changed) bool mForceUpdate; //flag to force instantaneous update of cubemap LLVector3 mLastSunLightingDirection; LLVector3 mLastMoonLightingDirection; -- cgit v1.3 From 413884dfc5b0a0eb38a025685e0e3da5a9f1efce Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Thu, 22 Aug 2019 21:48:20 +0300 Subject: SL-11776 Fixed moon's comparison condition --- indra/newview/llvosky.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 408da88c3f..37b685f731 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -736,7 +736,9 @@ bool LLVOSky::updateSky() LLVector3 direction = mSun.getDirection(); direction.normalize(); const F32 dot_sun = direction * mLastSunLightingDirection; - const F32 dot_moon = direction * mLastMoonLightingDirection; + LLVector3 moon_direction = mMoon.getDirection(); + moon_direction.normalize(); + const F32 dot_moon = moon_direction * mLastMoonLightingDirection; LLColor3 delta_color; delta_color.setVec(mLastTotalAmbient.mV[0] - total_ambient.mV[0], -- cgit v1.3 From 6932fa60d6aff2a413078663cc1100d2f9d87cbf Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 22 Aug 2019 15:25:07 -0700 Subject: Best of both worlds for 11776. --- indra/newview/llvosky.cpp | 144 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 28ad3d0877..41440ca6ed 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -420,6 +420,7 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) mWind(0.f), mForceUpdate(FALSE), mNeedUpdate(TRUE), + mCubeMapUpdateStage(-1), mWorldScale(1.f), mBumpSunDir(0.f, 0.f, 1.f) { @@ -502,13 +503,9 @@ void LLVOSky::init() initSkyTextureDirs(side, tile); createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); - } - } - - for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) - { - mSkyTex[i].create(1.0f); - mShinyTex[i].create(1.0f); + } + mSkyTex[side].create(1.0f); + mShinyTex[side].create(1.0f); } initCubeMap(); @@ -692,6 +689,8 @@ void LLVOSky::forceSkyUpdate() mForceUpdate = TRUE; memset(&m_lastAtmosphericsVars, 0x00, sizeof(AtmosphericsVars)); + + mCubeMapUpdateStage = -1; } bool LLVOSky::updateSky() @@ -720,9 +719,7 @@ bool LLVOSky::updateSky() const S32 total_no_tiles = NUM_CUBEMAP_FACES * NUM_TILES; const S32 cycle_frame_no = total_no_tiles + 1; - const S32 frame = next_frame; - - mNeedUpdate = mForceUpdate || (total_no_tiles == frame); + mNeedUpdate = mForceUpdate; ++next_frame; next_frame = next_frame % cycle_frame_no; @@ -731,95 +728,98 @@ bool LLVOSky::updateSky() LLHeavenBody::setInterpVal( mInterpVal ); updateDirections(); - // Note: must be before comparison of old/current env settings below to be an effective optimization - calc(); - - bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; - - if (mNeedUpdate && mForceUpdateThrottle.hasExpired() && (mForceUpdate || !same_atmospherics)) - { - LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); - - mForceUpdateThrottle.setTimerExpirySec(UPDATE_EXPRY); + if (!mCubeMap) + { + mCubeMapUpdateStage = NUM_CUBEMAP_FACES; + mForceUpdate = FALSE; + return TRUE; + } - LLSkyTex::stepCurrent(); - - m_lastAtmosphericsVars = m_atmosphericsVars; + if (mCubeMapUpdateStage < 0) + { + LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC); + calc(); - mInitialized = TRUE; + bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; - if (mCubeMap) - { - updateFog(LLViewerCamera::getInstance()->getFar()); + mNeedUpdate = mNeedUpdate || !same_atmospherics; - 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 (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(); int tex = mSkyTex[0].getWhich(TRUE); - for (int side = 0; side < NUM_CUBEMAP_FACES; side++) - { + 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); + 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 + // update the sky texture if (!is_alm_wl_sky) { - for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) - { + for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) + { mSkyTex[i].create(1.0f); - } + } } for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) - { - mShinyTex[i].create(1.0f); - } + { + mShinyTex[i].create(1.0f); + } - // update the environment map - if (mCubeMap) - { - std::vector > 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(); - } + // update the environment map + initCubeMap(); - gPipeline.markRebuild(gSky.mVOGroundp->mDrawable, LLDrawable::REBUILD_ALL, TRUE); + m_lastAtmosphericsVars = m_atmosphericsVars; - mNeedUpdate = FALSE; + mNeedUpdate = FALSE; mForceUpdate = FALSE; - } - if (mDrawable.notNull() && mDrawable->getFace(0) && !mDrawable->getFace(0)->getVertexBuffer()) + 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; -- cgit v1.3 From a645648ffc7d7bd665e13c0ed73e70ac06cebe29 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 23 Aug 2019 09:04:28 -0700 Subject: Remove unused vars to appease Clang. --- indra/newview/llvosky.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 41440ca6ed..19299f55a2 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -77,9 +77,6 @@ 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"); -- cgit v1.3 From fd4a90858c9beb147eb312f3c41396435d389c4d Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Wed, 28 Aug 2019 21:51:22 +0300 Subject: SL-11776 [EEP] Reduced frequency of sky updates by comparing data fuzzily --- indra/newview/lllegacyatmospherics.cpp | 183 ++++++++++++++++++++++++++++----- indra/newview/lllegacyatmospherics.h | 5 +- indra/newview/llvosky.cpp | 27 +++-- indra/newview/llvosky.h | 2 +- 4 files changed, 180 insertions(+), 37 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index 13d5eb96c4..fb779bb1a7 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -205,12 +205,16 @@ void LLAtmospherics::init() LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVector3 &dir, bool isShiny) { LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + return calcSkyColorInDir(psky, vars, dir, isShiny); +} +LLColor4 LLAtmospherics::calcSkyColorInDir(const LLSettingsSky::ptr_t &psky, AtmosphericsVars& vars, const LLVector3 &dir, bool isShiny) +{ F32 saturation = 0.3f; if (isShiny && dir.mV[VZ] < -0.02f) { - LLColor4 col = LLColor4(llmax(mFogColor[0],0.2f), llmax(mFogColor[1],0.2f), llmax(mFogColor[2],0.22f),0.f); + LLColor4 col; LLColor3 desat_fog = LLColor3(mFogColor); F32 brightness = desat_fog.brightness(); // So that shiny somewhat shows up at night. @@ -219,8 +223,8 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto brightness = 0.15f; desat_fog = smear(0.15f); } - LLColor3 greyscale = smear(brightness); - desat_fog = desat_fog * saturation + greyscale * (1.0f - saturation); + F32 greyscale_sat = brightness * (1.0f - saturation); + desat_fog = desat_fog * saturation + smear(greyscale_sat); if (!gPipeline.canUseWindLightShaders()) { col = LLColor4(desat_fog, 0.f); @@ -240,36 +244,34 @@ LLColor4 LLAtmospherics::calcSkyColorInDir(AtmosphericsVars& vars, const LLVecto // undo OGL_TO_CFR_ROTATION and negate vertical direction. LLVector3 Pn = LLVector3(-dir[1] , -dir[2], -dir[0]); - calcSkyColorWLVert(Pn, vars); - - bool low_end = !gPipeline.canUseWindLightShaders(); - - LLColor3 sky_color = isShiny ? vars.hazeColor : - low_end ? vars.hazeColor * 2.0f : psky->gammaCorrect(vars.hazeColor * 2.0f); + //calculates hazeColor + calcSkyColorWLVert(psky, Pn, vars); if (isShiny) { - F32 brightness = sky_color.brightness(); - LLColor3 greyscale = smear(brightness); - sky_color = sky_color * saturation + greyscale * (1.0f - saturation); + F32 brightness = vars.hazeColor.brightness(); + F32 greyscale_sat = brightness * (1.0f - saturation); + LLColor3 sky_color = vars.hazeColor * saturation + smear(greyscale_sat); sky_color *= (0.5f + 0.5f * brightness); + return LLColor4(sky_color, 0.0f); } + + bool low_end = !gPipeline.canUseWindLightShaders(); + LLColor3 sky_color = low_end ? vars.hazeColor * 2.0f : psky->gammaCorrect(vars.hazeColor * 2.0f); + return LLColor4(sky_color, 0.0f); } const F32 NIGHTTIME_ELEVATION = -8.0f; // degrees const F32 NIGHTTIME_ELEVATION_SIN = (F32)sinf(NIGHTTIME_ELEVATION*DEG_TO_RAD); -void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) +void LLAtmospherics::calcSkyColorWLVert(const LLSettingsSky::ptr_t &psky, LLVector3 & Pn, AtmosphericsVars& vars) { - LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); - LLColor3 blue_density = vars.blue_density; LLColor3 blue_horizon = vars.blue_horizon; F32 haze_horizon = vars.haze_horizon; F32 haze_density = vars.haze_density; F32 density_multiplier = vars.density_multiplier; - F32 distance_multiplier = vars.distance_multiplier; F32 max_y = vars.max_y; LLVector4 sun_norm = vars.sun_norm; @@ -316,13 +318,10 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) LLColor3 temp1 = vars.total_density; LLColor3 blue_weight = componentDiv(blue_density, temp1); + LLColor3 blue_factor = blue_horizon * blue_weight; LLColor3 haze_weight = componentDiv(smear(haze_density), temp1); + LLColor3 haze_factor = haze_horizon * haze_weight; - F32 lighty = sun_norm.mV[1]; - if(lighty < NIGHTTIME_ELEVATION_SIN) - { - lighty = -lighty; - } // Compute sunlight from P & lightnorm (for long rays like sky) temp2.mV[1] = llmax(F_APPROXIMATELY_ZERO, llmax(0.f, Pn[1]) * 1.0f + sun_norm.mV[1] ); @@ -335,8 +334,7 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) temp2.mV[2] = Plen * density_multiplier; // Transparency (-> temp1) - temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]);// * distance_multiplier); - (void)distance_multiplier; + temp1 = componentExp((temp1 * -1.f) * temp2.mV[2]); // Compute haze glow temp2.mV[0] = Pn * LLVector3(sun_norm); @@ -357,7 +355,7 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) // Haze color above cloud - vars.hazeColor = (blue_horizon * blue_weight * (sunlight + ambient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + ambient)); + vars.hazeColor = (blue_factor * (sunlight + ambient) + componentMult(haze_factor, sunlight * temp2.mV[0] + ambient)); // Increase ambient when there are more clouds LLColor3 tmpAmbient = ambient + (LLColor3::white - ambient) * cloud_shadow * 0.5f; @@ -366,7 +364,7 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars) sunlight *= (1.f - cloud_shadow); // Haze color below cloud - vars.hazeColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + componentMult(haze_horizon * haze_weight, sunlight * temp2.mV[0] + tmpAmbient)); + vars.hazeColorBelowCloud = (blue_factor * (sunlight + tmpAmbient) + componentMult(haze_factor, sunlight * temp2.mV[0] + tmpAmbient)); LLColor3 final_atten = LLColor3::white - temp1; final_atten.mV[0] = llmax(final_atten.mV[0], 0.0f); @@ -716,3 +714,138 @@ bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b) return true; } + +bool aproximately_equal(const F32 &a, const F32 &b, const F32 &fraction_treshold) +{ + F32 diff = fabs(a - b); + if (diff < F_APPROXIMATELY_ZERO || diff < llmax(fabs(a), fabs(b)) * fraction_treshold) + { + return true; + } + return false; +} + +bool aproximately_equal(const LLColor3 &a, const LLColor3 &b, const F32 &fraction_treshold) +{ + return aproximately_equal(a.mV[0], b.mV[0], fraction_treshold) + && aproximately_equal(a.mV[1], b.mV[1], fraction_treshold) + && aproximately_equal(a.mV[2], b.mV[2], fraction_treshold); +} + +bool aproximately_equal(const LLVector4 &a, const LLVector4 &b, const F32 &fraction_treshold) +{ + return aproximately_equal(a.mV[0], b.mV[0], fraction_treshold) + && aproximately_equal(a.mV[1], b.mV[1], fraction_treshold) + && aproximately_equal(a.mV[2], b.mV[2], fraction_treshold) + && aproximately_equal(a.mV[3], b.mV[3], fraction_treshold); +} + +bool aproximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold) +{ + if (!aproximately_equal(a.hazeColor, b.hazeColor, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.hazeColorBelowCloud, b.hazeColorBelowCloud, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.cloudColorSun, b.cloudColorSun, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.cloudColorAmbient, b.cloudColorAmbient, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.cloudDensity, b.cloudDensity, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.density_multiplier, b.density_multiplier, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.haze_horizon, b.haze_horizon, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.haze_density, b.haze_density, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.blue_horizon, b.blue_horizon, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.blue_density, b.blue_density, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.dome_offset, b.dome_offset, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.dome_radius, b.dome_radius, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.cloud_shadow, b.cloud_shadow, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.glow, b.glow, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.ambient, b.ambient, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.sunlight, b.sunlight, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.sun_norm, b.sun_norm, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.gamma, b.gamma, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.max_y, b.max_y, fraction_treshold)) + { + return false; + } + + if (!aproximately_equal(a.distance_multiplier, b.distance_multiplier, fraction_treshold)) + { + return false; + } + + // light_atten, light_transmittance, total_density + // are ignored as they always change when the values above do + // they're just shared calc across the sky map generation to save cycles + + return true; +} + diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index cdfcead7a4..5dd8c41a32 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -207,6 +207,8 @@ public: } friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b); + // returns true if values are within treshold of each other. + friend bool aproximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold = 0.0005); LLColor3 hazeColor; LLColor3 hazeColorBelowCloud; @@ -256,10 +258,11 @@ public: void setWind ( const LLVector3& wind ) { mWind = wind.length(); } LLColor4 calcSkyColorInDir(AtmosphericsVars& vars, const LLVector3& dir, bool isShiny = false); + LLColor4 calcSkyColorInDir(const LLSettingsSky::ptr_t &psky, AtmosphericsVars& vars, const LLVector3& dir, bool isShiny = false); protected: - void calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars); + void calcSkyColorWLVert(const LLSettingsSky::ptr_t &psky, LLVector3 & Pn, AtmosphericsVars& vars); LLColor3 getHazeColor(LLSettingsSky::ptr_t psky, AtmosphericsVars& vars, F32 costheta, F32 cloud_shadow); LLHaze mHaze; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 19299f55a2..3ef148e473 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -498,8 +498,7 @@ void LLVOSky::init() for (S32 tile = 0; tile < NUM_TILES; ++tile) { initSkyTextureDirs(side, tile); - createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); + createSkyTexture(m_atmosphericsVars, side, tile); } mSkyTex[side].create(1.0f); mShinyTex[side].create(1.0f); @@ -647,8 +646,10 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) } } -void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex, bool is_shiny) +void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile) { + LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); + S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; @@ -660,7 +661,8 @@ void LLVOSky::createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 { for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) { - tex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(vars, tex[side].getDir(x, y), is_shiny), x, y); + mSkyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(psky, vars, mSkyTex[side].getDir(x, y), false), x, y); + mShinyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(psky, vars, mShinyTex[side].getDir(x, y), true), x, y); } } } @@ -710,8 +712,6 @@ 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; @@ -737,7 +737,7 @@ bool LLVOSky::updateSky() LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC); calc(); - bool same_atmospherics = m_lastAtmosphericsVars == m_atmosphericsVars; + bool same_atmospherics = aproximatelyEqual(m_lastAtmosphericsVars, m_atmosphericsVars); mNeedUpdate = mNeedUpdate || !same_atmospherics; @@ -754,6 +754,8 @@ bool LLVOSky::updateSky() LL_RECORD_BLOCK_TIME(FTM_VOSKY_UPDATEFORCED); LLSkyTex::stepCurrent(); + bool is_alm_wl_sky = gPipeline.canUseWindLightShaders(); + int tex = mSkyTex[0].getWhich(TRUE); for (int side = 0; side < NUM_CUBEMAP_FACES; side++) @@ -807,14 +809,19 @@ bool LLVOSky::updateSky() } mCubeMapUpdateStage = -1; } + // run 0 to 5 faces, each face in own frame else if (mCubeMapUpdateStage >= 0 && mCubeMapUpdateStage < NUM_CUBEMAP_FACES) { LL_RECORD_BLOCK_TIME(FTM_VOSKY_CREATETEXTURES); S32 side = mCubeMapUpdateStage; - for (int tile = 0; tile < NUM_TILES; tile++) + // CPU hungry part, createSkyTexture() is math heavy + // Prior to EEP it was mostly per tile, but since EPP it is per face. + // This still can be optimized further + // (i.e. potentially can be made per tile again, can be moved to thread + // instead of executing per face, or may be can be moved to shaders) + for (S32 tile = 0; tile < NUM_TILES; tile++) { - createSkyTexture(m_atmosphericsVars, side, tile, mSkyTex); - createSkyTexture(m_atmosphericsVars, side, tile, mShinyTex, true); + createSkyTexture(m_atmosphericsVars, side, tile); } mCubeMapUpdateStage++; } diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index b1a01a9366..fc577ab5f8 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -302,7 +302,7 @@ protected: void updateDirections(void); void initSkyTextureDirs(const S32 side, const S32 tile); - void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile, LLSkyTex* tex, bool is_shiny = false); + void createSkyTexture(AtmosphericsVars& vars, const S32 side, const S32 tile); LLPointer mSunTexturep[2]; LLPointer mMoonTexturep[2]; -- cgit v1.3 From c5724023dd80a6c8a77d15650161e7cf67f8650e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 28 Aug 2019 15:27:23 -0700 Subject: Work around issue with friend ops not accepting default params on Clang. --- indra/newview/lllegacyatmospherics.cpp | 62 +++++++++++++++++----------------- indra/newview/lllegacyatmospherics.h | 2 +- indra/newview/llvosky.cpp | 4 ++- 3 files changed, 35 insertions(+), 33 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp index fb779bb1a7..d9425b702a 100644 --- a/indra/newview/lllegacyatmospherics.cpp +++ b/indra/newview/lllegacyatmospherics.cpp @@ -715,7 +715,7 @@ bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b) return true; } -bool aproximately_equal(const F32 &a, const F32 &b, const F32 &fraction_treshold) +bool approximatelyEqual(const F32 &a, const F32 &b, const F32 &fraction_treshold) { F32 diff = fabs(a - b); if (diff < F_APPROXIMATELY_ZERO || diff < llmax(fabs(a), fabs(b)) * fraction_treshold) @@ -725,119 +725,119 @@ bool aproximately_equal(const F32 &a, const F32 &b, const F32 &fraction_treshol return false; } -bool aproximately_equal(const LLColor3 &a, const LLColor3 &b, const F32 &fraction_treshold) +bool approximatelyEqual(const LLColor3 &a, const LLColor3 &b, const F32 &fraction_treshold) { - return aproximately_equal(a.mV[0], b.mV[0], fraction_treshold) - && aproximately_equal(a.mV[1], b.mV[1], fraction_treshold) - && aproximately_equal(a.mV[2], b.mV[2], fraction_treshold); + return approximatelyEqual(a.mV[0], b.mV[0], fraction_treshold) + && approximatelyEqual(a.mV[1], b.mV[1], fraction_treshold) + && approximatelyEqual(a.mV[2], b.mV[2], fraction_treshold); } -bool aproximately_equal(const LLVector4 &a, const LLVector4 &b, const F32 &fraction_treshold) +bool approximatelyEqual(const LLVector4 &a, const LLVector4 &b, const F32 &fraction_treshold) { - return aproximately_equal(a.mV[0], b.mV[0], fraction_treshold) - && aproximately_equal(a.mV[1], b.mV[1], fraction_treshold) - && aproximately_equal(a.mV[2], b.mV[2], fraction_treshold) - && aproximately_equal(a.mV[3], b.mV[3], fraction_treshold); + return approximatelyEqual(a.mV[0], b.mV[0], fraction_treshold) + && approximatelyEqual(a.mV[1], b.mV[1], fraction_treshold) + && approximatelyEqual(a.mV[2], b.mV[2], fraction_treshold) + && approximatelyEqual(a.mV[3], b.mV[3], fraction_treshold); } -bool aproximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold) +bool approximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold) { - if (!aproximately_equal(a.hazeColor, b.hazeColor, fraction_treshold)) + if (!approximatelyEqual(a.hazeColor, b.hazeColor, fraction_treshold)) { return false; } - if (!aproximately_equal(a.hazeColorBelowCloud, b.hazeColorBelowCloud, fraction_treshold)) + if (!approximatelyEqual(a.hazeColorBelowCloud, b.hazeColorBelowCloud, fraction_treshold)) { return false; } - if (!aproximately_equal(a.cloudColorSun, b.cloudColorSun, fraction_treshold)) + if (!approximatelyEqual(a.cloudColorSun, b.cloudColorSun, fraction_treshold)) { return false; } - if (!aproximately_equal(a.cloudColorAmbient, b.cloudColorAmbient, fraction_treshold)) + if (!approximatelyEqual(a.cloudColorAmbient, b.cloudColorAmbient, fraction_treshold)) { return false; } - if (!aproximately_equal(a.cloudDensity, b.cloudDensity, fraction_treshold)) + if (!approximatelyEqual(a.cloudDensity, b.cloudDensity, fraction_treshold)) { return false; } - if (!aproximately_equal(a.density_multiplier, b.density_multiplier, fraction_treshold)) + if (!approximatelyEqual(a.density_multiplier, b.density_multiplier, fraction_treshold)) { return false; } - if (!aproximately_equal(a.haze_horizon, b.haze_horizon, fraction_treshold)) + if (!approximatelyEqual(a.haze_horizon, b.haze_horizon, fraction_treshold)) { return false; } - if (!aproximately_equal(a.haze_density, b.haze_density, fraction_treshold)) + if (!approximatelyEqual(a.haze_density, b.haze_density, fraction_treshold)) { return false; } - if (!aproximately_equal(a.blue_horizon, b.blue_horizon, fraction_treshold)) + if (!approximatelyEqual(a.blue_horizon, b.blue_horizon, fraction_treshold)) { return false; } - if (!aproximately_equal(a.blue_density, b.blue_density, fraction_treshold)) + if (!approximatelyEqual(a.blue_density, b.blue_density, fraction_treshold)) { return false; } - if (!aproximately_equal(a.dome_offset, b.dome_offset, fraction_treshold)) + if (!approximatelyEqual(a.dome_offset, b.dome_offset, fraction_treshold)) { return false; } - if (!aproximately_equal(a.dome_radius, b.dome_radius, fraction_treshold)) + if (!approximatelyEqual(a.dome_radius, b.dome_radius, fraction_treshold)) { return false; } - if (!aproximately_equal(a.cloud_shadow, b.cloud_shadow, fraction_treshold)) + if (!approximatelyEqual(a.cloud_shadow, b.cloud_shadow, fraction_treshold)) { return false; } - if (!aproximately_equal(a.glow, b.glow, fraction_treshold)) + if (!approximatelyEqual(a.glow, b.glow, fraction_treshold)) { return false; } - if (!aproximately_equal(a.ambient, b.ambient, fraction_treshold)) + if (!approximatelyEqual(a.ambient, b.ambient, fraction_treshold)) { return false; } - if (!aproximately_equal(a.sunlight, b.sunlight, fraction_treshold)) + if (!approximatelyEqual(a.sunlight, b.sunlight, fraction_treshold)) { return false; } - if (!aproximately_equal(a.sun_norm, b.sun_norm, fraction_treshold)) + if (!approximatelyEqual(a.sun_norm, b.sun_norm, fraction_treshold)) { return false; } - if (!aproximately_equal(a.gamma, b.gamma, fraction_treshold)) + if (!approximatelyEqual(a.gamma, b.gamma, fraction_treshold)) { return false; } - if (!aproximately_equal(a.max_y, b.max_y, fraction_treshold)) + if (!approximatelyEqual(a.max_y, b.max_y, fraction_treshold)) { return false; } - if (!aproximately_equal(a.distance_multiplier, b.distance_multiplier, fraction_treshold)) + if (!approximatelyEqual(a.distance_multiplier, b.distance_multiplier, fraction_treshold)) { return false; } diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index 5dd8c41a32..03c8efb91a 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -208,7 +208,7 @@ public: friend bool operator==(const AtmosphericsVars& a, const AtmosphericsVars& b); // returns true if values are within treshold of each other. - friend bool aproximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold = 0.0005); + friend bool approximatelyEqual(const AtmosphericsVars& a, const AtmosphericsVars& b, const F32 fraction_treshold); LLColor3 hazeColor; LLColor3 hazeColorBelowCloud; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 3ef148e473..ba2ba71e46 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -83,6 +83,8 @@ namespace LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATEFORCED("VOSky Update Forced"); F32Seconds UPDATE_EXPRY(0.25f); + + const F32 UPDATE_MIN_DELTA_THRESHOLD = 0.0005f; } /*************************************** SkyTex @@ -737,7 +739,7 @@ bool LLVOSky::updateSky() LL_RECORD_BLOCK_TIME(FTM_VOSKY_CALC); calc(); - bool same_atmospherics = aproximatelyEqual(m_lastAtmosphericsVars, m_atmosphericsVars); + bool same_atmospherics = approximatelyEqual(m_lastAtmosphericsVars, m_atmosphericsVars, UPDATE_MIN_DELTA_THRESHOLD); mNeedUpdate = mNeedUpdate || !same_atmospherics; -- cgit v1.3 From b71e33b48cf321bb76081baeb210511cb9fbc1c8 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 25 Feb 2020 13:08:01 -0800 Subject: SL-12574 Cleanup unused argument --- indra/newview/llvosky.cpp | 27 +++++++++++++-------------- indra/newview/llvosky.h | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 64f34eb619..525251d42c 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -190,9 +190,8 @@ void LLSkyTex::initEmpty(const S32 tex) createGLImage(tex); } -void LLSkyTex::create(const F32 brightness) +void LLSkyTex::create() { - /// Brightness ignored for now. U8* data = mImageRaw[sCurrent]->getData(); for (S32 i = 0; i < sResolution; ++i) { @@ -502,8 +501,8 @@ void LLVOSky::init() initSkyTextureDirs(side, tile); createSkyTexture(m_atmosphericsVars, side, tile); } - mSkyTex[side].create(1.0f); - mShinyTex[side].create(1.0f); + mSkyTex[side].create(); + mShinyTex[side].create(); } initCubeMap(); @@ -764,35 +763,35 @@ bool LLVOSky::updateSky() { 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); - } + } 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) { for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) -{ - mSkyTex[i].create(1.0f); + { + mSkyTex[i].create(); } - } + } for (S32 i = 0; i < NUM_CUBEMAP_FACES; ++i) - { - mShinyTex[i].create(1.0f); - } + { + mShinyTex[i].create(); + } // update the environment map initCubeMap(); diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index fc577ab5f8..39e42bbb24 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -78,7 +78,7 @@ protected: void initEmpty(const S32 tex); - void create(F32 brightness); + void create(); void setDir(const LLVector3 &dir, const S32 i, const S32 j) { -- cgit v1.3 From d87cc68a72393cdc56dcbc2e36fd94ec7a814246 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 25 Feb 2020 13:08:37 -0800 Subject: SL-12574 Cleanup inconsistent indentation --- indra/newview/llvosky.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 525251d42c..943704c8de 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -698,20 +698,20 @@ bool LLVOSky::updateSky() LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky(); if (mDead || !(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))) -{ + { return TRUE; -} + } if (mDead) -{ + { // It's dead. Don't update it. return TRUE; -} + } if (gGLManager.mIsDisabled) -{ + { return TRUE; -} + } static S32 next_frame = 0; const S32 total_no_tiles = NUM_CUBEMAP_FACES * NUM_TILES; @@ -743,15 +743,15 @@ bool LLVOSky::updateSky() mNeedUpdate = mNeedUpdate || !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(); @@ -805,9 +805,9 @@ bool LLVOSky::updateSky() 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); - } + { + gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); + } mCubeMapUpdateStage = -1; } // run 0 to 5 faces, each face in own frame @@ -821,11 +821,11 @@ bool LLVOSky::updateSky() // (i.e. potentially can be made per tile again, can be moved to thread // instead of executing per face, or may be can be moved to shaders) for (S32 tile = 0; tile < NUM_TILES; tile++) - { + { createSkyTexture(m_atmosphericsVars, side, tile); - } + } mCubeMapUpdateStage++; - } + } return TRUE; } -- cgit v1.3 From edb4373f7d2a32beb93a7f69ddcdf5e1bc0eb6a1 Mon Sep 17 00:00:00 2001 From: maxim_productengine Date: Thu, 5 Mar 2020 14:13:39 +0200 Subject: SL-9775 FIXED EEP viewer crash when looking at the sun (which is playing parcel media) --- indra/newview/llface.cpp | 3 ++- indra/newview/llface.h | 4 ++++ indra/newview/llviewertexture.cpp | 5 ++++- indra/newview/llvosky.cpp | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) (limited to 'indra/newview/llvosky.cpp') diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 174d8e34d1..59269c2115 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -168,7 +168,8 @@ void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp) mImportanceToCamera = 0.f ; mBoundingSphereRadius = 0.0f ; - mHasMedia = FALSE ; + mHasMedia = false ; + mIsMediaAllowed = true; } void LLFace::destroy() diff --git a/indra/newview/llface.h b/indra/newview/llface.h index 0c5af5b579..c74d4e3fa8 100644 --- a/indra/newview/llface.h +++ b/indra/newview/llface.h @@ -218,6 +218,9 @@ public: void setHasMedia(bool has_media) { mHasMedia = has_media ;} BOOL hasMedia() const ; + void setMediaAllowed(bool is_media_allowed) { mIsMediaAllowed = is_media_allowed; } + BOOL isMediaAllowed() const { return mIsMediaAllowed; } + BOOL switchTexture() ; //vertex buffer tracking @@ -293,6 +296,7 @@ private: F32 mImportanceToCamera ; F32 mBoundingSphereRadius ; bool mHasMedia ; + bool mIsMediaAllowed; protected: diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index f5f9d0d3cc..a2cec9a613 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -3481,7 +3481,10 @@ BOOL LLViewerMediaTexture::findFaces() U32 end = tex->getNumFaces(ch); for(U32 i = 0; i < end; i++) { - mMediaFaceList.push_back((*face_list)[i]); + if ((*face_list)[i]->isMediaAllowed()) + { + mMediaFaceList.push_back((*face_list)[i]); + } } } } diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 943704c8de..2037aca7e9 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -881,6 +881,10 @@ LLDrawable *LLVOSky::createDrawable(LLPipeline *pipeline) mFace[FACE_MOON] = mDrawable->addFace(poolp, nullptr); mFace[FACE_BLOOM] = mDrawable->addFace(poolp, nullptr); + mFace[FACE_SUN]->setMediaAllowed(false); + mFace[FACE_MOON]->setMediaAllowed(false); + mFace[FACE_BLOOM]->setMediaAllowed(false); + return mDrawable; } -- cgit v1.3