From 446afe2d1a081a0e10a34749bbe1e4475075dae0 Mon Sep 17 00:00:00 2001 From: Graham Linden <graham@lindenlab.com> Date: Tue, 26 Mar 2019 08:21:53 -0700 Subject: [PATCH] Make whether the sun or moon is primary part of llrender light state so we can set uniforms for shaders along with other light params. Fix atten calcs to not use abs val. --- indra/llinventory/llsettingssky.cpp | 2 +- indra/llrender/llrender.cpp | 20 ++++++++++++++++++-- indra/llrender/llrender.h | 2 ++ indra/newview/pipeline.cpp | 3 ++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp index f1bea326c11..0e597aabb0c 100644 --- a/indra/llinventory/llsettingssky.cpp +++ b/indra/llinventory/llsettingssky.cpp @@ -1281,7 +1281,7 @@ void LLSettingsSky::calculateLightSettings() const // and vary_sunlight will work properly with moon light F32 lighty = lightnorm[1]; - if(fabs(lighty) > 0.001f) + if(lighty > 0.001f) { lighty = 1.f / lighty; } diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index dc662bf8982..2bf7ad9902e 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -850,9 +850,12 @@ LLLightState::LLLightState(S32 index) if (mIndex == 0) { mDiffuse.set(1,1,1,1); + mDiffuseB.set(0,0,0,0); mSpecular.set(1,1,1,1); } + mSunIsPrimary = true; + mAmbient.set(0,0,0,1); mPosition.set(0,0,1,0); mSpotDirection.set(0,0,-1); @@ -904,6 +907,15 @@ void LLLightState::setDiffuseB(const LLColor4& diffuse) } } +void LLLightState::setSunPrimary(bool v) +{ + if (mSunIsPrimary != v) + { + ++gGL.mLightHash; + mSunIsPrimary = v; + } +} + void LLLightState::setAmbient(const LLColor4& ambient) { if (mAmbient != ambient) @@ -1162,7 +1174,8 @@ void LLRender::syncLightState() LLVector3 direction[8]; LLVector4 attenuation[8]; LLVector3 diffuse[8]; - LLVector3 diffuseB[8]; + LLVector3 diffuse_b[8]; + bool sun_primary[8]; for (U32 i = 0; i < 8; i++) { @@ -1172,7 +1185,8 @@ void LLRender::syncLightState() direction[i] = light->mSpotDirection; attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[2], light->mSpecular.mV[3]); diffuse[i].set(light->mDiffuse.mV); - diffuseB[i].set(light->mDiffuseB.mV); + diffuse_b[i].set(light->mDiffuseB.mV); + sun_primary[i] = light->mSunIsPrimary; } shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); @@ -1180,6 +1194,8 @@ void LLRender::syncLightState() 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->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_primary[0] ? 1 : 0); + shader->uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, diffuse_b[0].mV); } } diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 3f2d5eb35d0..ad9cd11283d 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -239,6 +239,7 @@ class LLLightState void setSpotExponent(const F32& exponent); void setSpotCutoff(const F32& cutoff); void setSpotDirection(const LLVector3& direction); + void setSunPrimary(bool v); protected: friend class LLRender; @@ -247,6 +248,7 @@ class LLLightState bool mEnabled; LLColor4 mDiffuse; LLColor4 mDiffuseB; + bool mSunIsPrimary; LLColor4 mAmbient; LLColor4 mSpecular; LLVector4 mPosition; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c4a644c7b68..4c93d16fb1e 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -6240,6 +6240,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) LLLightState* light = gGL.getLight(0); light->setPosition(light_dir); + light->setSunPrimary(sun_up); light->setDiffuse(mSunDiffuse); light->setDiffuseB(mMoonDiffuse); light->setAmbient(LLColor4::black); @@ -6361,7 +6362,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) { mHWLightColors[cur_light] = LLColor4::black; LLLightState* light = gGL.getLight(cur_light); - + light->setSunPrimary(true); light->setDiffuse(LLColor4::black); light->setAmbient(LLColor4::black); light->setSpecular(LLColor4::black); -- GitLab