summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2018-06-01 00:18:36 +0100
committerGraham Linden <graham@lindenlab.com>2018-06-01 00:18:36 +0100
commit64302d3000b69b31e72eb6a3bd8a981c80cb88de (patch)
treed942aa56bc50bd44542ff5f7757d46a6189e8036 /indra
parent439273c9c11ec5f3c186fd7d97a28d11419153cd (diff)
Modify use of sky settings, reduce complexity, and name funcs to indicate coord systems in use.
Fix class2 softenLightF shader.
Diffstat (limited to 'indra')
-rw-r--r--indra/llinventory/llsettingsbase.h2
-rw-r--r--indra/llinventory/llsettingssky.cpp177
-rw-r--r--indra/llinventory/llsettingssky.h113
-rw-r--r--indra/llmath/llquaternion.cpp2
-rw-r--r--indra/llmath/m3math.cpp2
-rw-r--r--indra/llrender/llrender.h5
-rw-r--r--indra/llrender/llshadermgr.cpp6
-rw-r--r--indra/newview/app_settings/settings.xml2
-rw-r--r--indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl8
-rw-r--r--indra/newview/lldrawpoolwater.cpp19
-rw-r--r--indra/newview/lldrawpoolwlsky.cpp21
-rw-r--r--indra/newview/llenvironment.cpp80
-rw-r--r--indra/newview/llenvironment.h27
-rw-r--r--indra/newview/llface.cpp6
-rw-r--r--indra/newview/lllegacyatmospherics.cpp6
-rw-r--r--indra/newview/lllegacyatmospherics.h2
-rw-r--r--indra/newview/llsettingsvo.cpp69
-rw-r--r--indra/newview/llsettingsvo.h1
-rw-r--r--indra/newview/llsky.cpp157
-rw-r--r--indra/newview/llsky.h19
-rw-r--r--indra/newview/llstartup.cpp3
-rw-r--r--indra/newview/lltoolgun.cpp2
-rw-r--r--indra/newview/llviewermessage.cpp11
-rw-r--r--indra/newview/llviewershadermgr.cpp2
-rw-r--r--indra/newview/llvosky.cpp417
-rw-r--r--indra/newview/llvosky.h109
-rw-r--r--indra/newview/llvowlsky.cpp5
-rw-r--r--indra/newview/llvowlsky.h3
-rw-r--r--indra/newview/pipeline.cpp61
-rw-r--r--indra/newview/pipeline.h6
30 files changed, 637 insertions, 706 deletions
diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h
index 5b44dc4666..264c6c6c49 100644
--- a/indra/llinventory/llsettingsbase.h
+++ b/indra/llinventory/llsettingsbase.h
@@ -251,7 +251,7 @@ protected:
void markDirty() { mDirty = true; }
private:
- bool mDirty;
+ bool mDirty = true;
LLSD combineSDMaps(const LLSD &first, const LLSD &other) const;
diff --git a/indra/llinventory/llsettingssky.cpp b/indra/llinventory/llsettingssky.cpp
index e06cd7ca72..b8623c3ed3 100644
--- a/indra/llinventory/llsettingssky.cpp
+++ b/indra/llinventory/llsettingssky.cpp
@@ -42,13 +42,14 @@ namespace
{
LLTrace::BlockTimerStatHandle FTM_BLEND_SKYVALUES("Blending Sky Environment");
LLTrace::BlockTimerStatHandle FTM_UPDATE_SKYVALUES("Update Sky Environment");
+ static const LLVector3 DUE_EAST = LLVector3::x_axis;
}
-static LLQuaternion body_position_from_angles(F32 azimuth, F32 altitude)
+static LLQuaternion convert_azimuth_and_altitude_to_quat(F32 azimuth, F32 altitude)
{
- LLQuaternion body_quat;
- body_quat.setEulerAngles(0.0f, -altitude, azimuth);
- return body_quat;
+ LLQuaternion quat;
+ quat.setEulerAngles(0.0f, -altitude, azimuth);
+ return quat;
}
const F32 LLSettingsSky::DOME_OFFSET(0.96f);
@@ -487,8 +488,6 @@ LLSettingsSky::validation_list_t LLSettingsSky::validationList()
LLSD(LLSDArray(0.2f)("*")(-2.5f)("*")),
LLSD(LLSDArray(20.0f)("*")(0.0f)("*")))));
- validation.push_back(Validator(SETTING_LIGHT_NORMAL, false, LLSD::TypeArray,
- boost::bind(&Validator::verifyVectorNormalized, _1, 3)));
validation.push_back(Validator(SETTING_MAX_Y, true, LLSD::TypeReal,
boost::bind(&Validator::verifyFloatRange, _1, LLSD(LLSDArray(0.0f)(4000.0f)))));
validation.push_back(Validator(SETTING_MOON_ROTATION, true, LLSD::TypeArray, &Validator::verifyQuaternionNormal));
@@ -579,8 +578,8 @@ LLSD LLSettingsSky::defaults()
LLQuaternion sunquat;
LLQuaternion moonquat;
- sunquat.setEulerAngles(0.0f, -1.39626, 0.0f); // 80 deg pitch / 0 deg azimuth from East
- moonquat.setEulerAngles(0.0f, -1.39626, F_PI); // 80 deg pitch / 180 deg azimuth from East
+ sunquat = convert_azimuth_and_altitude_to_quat(0.0f, 80.0f * DEG_TO_RAD);
+ moonquat = convert_azimuth_and_altitude_to_quat(F_PI, 80.0f * DEG_TO_RAD);
// Magic constants copied form dfltsetting.xml
dfltsetting[SETTING_CLOUD_COLOR] = LLColor4(0.4099, 0.4099, 0.4099, 0.0).getValue();
@@ -595,7 +594,6 @@ LLSD LLSettingsSky::defaults()
dfltsetting[SETTING_GAMMA] = LLSD::Real(1.0);
dfltsetting[SETTING_GLOW] = LLColor4(5.000, 0.0010, -0.4799, 1.0).getValue();
- dfltsetting[SETTING_LIGHT_NORMAL] = LLVector3(0.0000, 0.9126, -0.4086).getValue();
dfltsetting[SETTING_MAX_Y] = LLSD::Real(1605);
dfltsetting[SETTING_MOON_ROTATION] = moonquat.getValue();
dfltsetting[SETTING_STAR_BRIGHTNESS] = LLSD::Real(0.0000);
@@ -657,7 +655,7 @@ LLSD LLSettingsSky::translateLegacyHazeSettings(const LLSD& legacy)
return legacyhazesettings;
}
-LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy, const std::string* name)
+LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy)
{
LLSD newsettings(defaults());
@@ -719,11 +717,7 @@ LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy, const std::strin
{
newsettings[SETTING_GLOW] = LLColor3(legacy[SETTING_GLOW]).getValue();
}
-
- if (legacy.has(SETTING_LIGHT_NORMAL))
- {
- newsettings[SETTING_LIGHT_NORMAL] = LLVector3(legacy[SETTING_LIGHT_NORMAL]).getValue();
- }
+
if (legacy.has(SETTING_MAX_Y))
{
newsettings[SETTING_MAX_Y] = LLSD::Real(legacy[SETTING_MAX_Y][0].asReal());
@@ -762,16 +756,11 @@ LLSD LLSettingsSky::translateLegacySettings(const LLSD& legacy, const std::strin
F32 azimuth = legacy[SETTING_LEGACY_EAST_ANGLE].asReal();
F32 altitude = legacy[SETTING_LEGACY_SUN_ANGLE].asReal();
- F32 pi_over_2 = F_PI * 0.5f;
- LLQuaternion sunquat = body_position_from_angles(azimuth - pi_over_2, altitude);
- LLQuaternion moonquat = body_position_from_angles(azimuth + pi_over_2, altitude);
+ LLQuaternion sunquat = convert_azimuth_and_altitude_to_quat(azimuth, altitude);
+ LLQuaternion moonquat = convert_azimuth_and_altitude_to_quat(azimuth + F_PI, altitude);
- if (name)
- {
- LLVector3 sundir = LLVector3::x_axis * sunquat;
- LLVector3 moondir = LLVector3::x_axis * moonquat;
- LL_INFOS() << *name << " sun: " << sundir << " moon: " << moondir << LL_ENDL;
- }
+ //LLVector3 sundir = DUE_EAST * sunquat;
+ //LLVector3 moondir = DUE_EAST * moonquat;
newsettings[SETTING_SUN_ROTATION] = sunquat.getValue();
newsettings[SETTING_MOON_ROTATION] = moonquat.getValue();
@@ -785,11 +774,11 @@ void LLSettingsSky::updateSettings()
LL_RECORD_BLOCK_TIME(FTM_UPDATE_SKYVALUES);
//LL_INFOS("WINDLIGHT", "SKY", "EEP") << "WL Parameters are dirty. Reticulating Splines..." << LL_ENDL;
+ mPositionsDirty = isDirty();
+ mLightingDirty = isDirty();
+
// base class clears dirty flag so as to not trigger recursive update
LLSettingsBase::updateSettings();
-
- calculateHeavnlyBodyPositions();
- calculateLightSettings();
}
bool LLSettingsSky::getIsSunUp() const
@@ -804,44 +793,42 @@ bool LLSettingsSky::getIsMoonUp() const
return moonDir.mV[2] > NIGHTTIME_ELEVATION_SIN;
}
-void LLSettingsSky::calculateHeavnlyBodyPositions()
+void LLSettingsSky::calculateHeavnlyBodyPositions() const
{
+ if (!mPositionsDirty)
+ {
+ return;
+ }
+
+ mPositionsDirty = false;
+
LLQuaternion sunq = getSunRotation();
LLQuaternion moonq = getMoonRotation();
- mSunDirection = LLVector3::x_axis * sunq;
- mSunDirection.normalize();
+ mSunDirection = DUE_EAST * sunq;
+ mMoonDirection = DUE_EAST * moonq;
- mMoonDirection = LLVector3::x_axis * moonq;
+ mSunDirection.normalize();
mMoonDirection.normalize();
+}
+
+LLVector3 LLSettingsSky::getLightDirection() const
+{
+ calculateHeavnlyBodyPositions();
// is the normal from the sun or the moon
if (getIsSunUp())
{
- mLightDirection = mSunDirection;
+ llassert(mSunDirection.length() > 0.01f);
+ return mSunDirection;
}
else if (getIsMoonUp())
{
- mLightDirection = mMoonDirection;
+ llassert(mMoonDirection.length() > 0.01f);
+ return mMoonDirection;
}
- else
- {
- mLightDirection = LLVector3::z_axis;
- }
-
- // calculate the clamp lightnorm for sky (to prevent ugly banding in sky
- // when haze goes below the horizon
- mClampedLightDirection = mLightDirection;
- if (mClampedLightDirection.mV[1] < -0.1f)
- {
- mClampedLightDirection.mV[1] = -0.1f;
- mClampedLightDirection.normalize();
- }
-
- //LL_INFOS() << "Sun: " << mSunDirection << LL_ENDL;
- //LL_INFOS() << "Moon: " << mMoonDirection << LL_ENDL;
- //LL_INFOS() << "Light: " << mLightDirection << LL_ENDL;
+ return LLVector3::z_axis;
}
LLColor3 LLSettingsSky::getBlueDensity() const
@@ -969,42 +956,91 @@ LLColor3 LLSettingsSky::gammaCorrect(const LLColor3& in) const
return v;
}
-void LLSettingsSky::calculateLightSettings()
+LLVector3 LLSettingsSky::getSunDirection() const
+{
+ calculateHeavnlyBodyPositions();
+ return mSunDirection;
+}
+
+LLVector3 LLSettingsSky::getMoonDirection() const
+{
+ calculateHeavnlyBodyPositions();
+ return mMoonDirection;
+}
+
+LLColor4U LLSettingsSky::getFadeColor() const
+{
+ calculateLightSettings();
+ return mFadeColor;
+}
+
+LLColor4 LLSettingsSky::getMoonAmbient() const
+{
+ calculateLightSettings();
+ return mMoonAmbient;
+}
+
+LLColor3 LLSettingsSky::getMoonDiffuse() const
+{
+ calculateLightSettings();
+ return mMoonDiffuse;
+}
+
+LLColor4 LLSettingsSky::getSunAmbient() const
+{
+ calculateLightSettings();
+ return mSunAmbient;
+}
+
+LLColor3 LLSettingsSky::getSunDiffuse() const
+{
+ calculateLightSettings();
+ return mSunDiffuse;
+}
+
+LLColor4 LLSettingsSky::getTotalAmbient() const
{
+ calculateLightSettings();
+ return mTotalAmbient;
+}
+
+void LLSettingsSky::calculateLightSettings() const
+{
+ if (!mLightingDirty)
+ {
+ return;
+ }
+
+ calculateHeavnlyBodyPositions();
+
+ mLightingDirty = false;
+
// Initialize temp variables
LLColor3 sunlight = getSunlightColor();
LLColor3 ambient = getAmbientColor();
- F32 cloud_shadow = getCloudShadow();
- LLVector3 lightnorm = getLightDirection();
+ F32 cloud_shadow = getCloudShadow();
+ LLVector3 lightnorm = getLightDirection();
- // Sunlight attenuation effect (hue and brightness) due to atmosphere
- // this is used later for sunlight modulation at various altitudes
+ // Sunlight attenuation effect (hue and brightness) due to atmosphere
+ // this is used later for sunlight modulation at various altitudes
F32 max_y = getMaxY();
LLColor3 light_atten = getLightAttenuation(max_y);
LLColor3 light_transmittance = getLightTransmittance();
-
- // 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 = lightnorm[1];
- if (lighty < NIGHTTIME_ELEVATION_SIN)
- {
- lighty = -lighty;
- }
+ // and vary_sunlight will work properly with moon light
+ F32 lighty = lightnorm[1];
lighty = llmax(0.f, lighty);
if(lighty > 0.f)
- {
+ {
lighty = 1.f / lighty;
- }
+ }
componentMultBy(sunlight, componentExp((light_atten * -1.f) * lighty));
- //increase ambient when there are more clouds
- LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5f;
+ //increase ambient when there are more clouds
+ LLColor3 tmpAmbient = ambient + (smear(1.f) - ambient) * cloud_shadow * 0.5f;
- //brightness of surface both sunlight and ambient
+ //brightness of surface both sunlight and ambient
mSunDiffuse = gammaCorrect(componentMult(sunlight, light_transmittance));
mSunAmbient = gammaCorrect(componentMult(tmpAmbient, light_transmittance) * 0.5);
@@ -1015,4 +1051,3 @@ void LLSettingsSky::calculateLightSettings()
mFadeColor = mTotalAmbient + (mSunDiffuse + mMoonDiffuse) * 0.5f;
mFadeColor.setAlpha(0);
}
-
diff --git a/indra/llinventory/llsettingssky.h b/indra/llinventory/llsettingssky.h
index 4c8a5e4016..3084cadd57 100644
--- a/indra/llinventory/llsettingssky.h
+++ b/indra/llinventory/llsettingssky.h
@@ -281,16 +281,6 @@ public:
setValue(SETTING_GLOW, val);
}
- LLVector3 getLightNormal() const
- {
- return LLVector3(mSettings[SETTING_LIGHT_NORMAL]);
- }
-
- void setLightNormal(const LLVector3 &val)
- {
- setValue(SETTING_LIGHT_NORMAL, val);
- }
-
F32 getMaxY() const
{
return mSettings[SETTING_MAX_Y].asReal();
@@ -361,68 +351,7 @@ public:
setValue(SETTING_SUN_TEXTUREID, id);
}
- // Internal/calculated settings
- LLVector3 getLightDirection() const
- {
- update();
- return mLightDirection;
- };
-
- LLVector3 getClampedLightDirection() const
- {
- update();
- return mClampedLightDirection;
- };
-
- LLVector3 getSunDirection() const
- {
- update();
- return mSunDirection;
- }
-
- LLVector3 getMoonDirection() const
- {
- update();
- return mMoonDirection;
- }
-
- LLColor4U getFadeColor() const
- {
- update();
- return mFadeColor;
- }
-
- LLColor4 getMoonAmbient() const
- {
- update();
- return mMoonAmbient;
- }
-
- LLColor3 getMoonDiffuse() const
- {
- update();
- return mMoonDiffuse;
- }
-
- LLColor4 getSunAmbient() const
- {
- update();
- return mSunAmbient;
- }
-
- LLColor3 getSunDiffuse() const
- {
- update();
- return mSunDiffuse;
- }
-
- LLColor4 getTotalAmbient() const
- {
- update();
- return mTotalAmbient;
- }
-
-//=====================================================================
+ //=====================================================================
// transient properties used in animations.
LLUUID getNextSunTextureId() const
{
@@ -446,7 +375,7 @@ public:
virtual validation_list_t getValidationList() const override;
static validation_list_t validationList();
- static LLSD translateLegacySettings(const LLSD& legacy, const std::string* name = nullptr);
+ static LLSD translateLegacySettings(const LLSD& legacy);
static LLSD translateLegacyHazeSettings(const LLSD& legacy);
LLColor3 getLightAttenuation(F32 distance) const;
@@ -468,9 +397,20 @@ public:
void setHazeDensity(F32 val);
void setHazeHorizon(F32 val);
+// Internal/calculated settings
bool getIsSunUp() const;
bool getIsMoonUp() const;
+ LLVector3 getLightDirection() const;
+ LLVector3 getSunDirection() const;
+ LLVector3 getMoonDirection() const;
+ LLColor4U getFadeColor() const;
+ LLColor4 getMoonAmbient() const;
+ LLColor3 getMoonDiffuse() const;
+ LLColor4 getSunAmbient() const;
+ LLColor3 getSunDiffuse() const;
+ LLColor4 getTotalAmbient() const;
+
protected:
static const std::string SETTING_LEGACY_EAST_ANGLE;
static const std::string SETTING_LEGACY_ENABLE_CLOUD_SCROLL;
@@ -484,28 +424,29 @@ protected:
virtual void updateSettings() override;
private:
+ mutable bool mPositionsDirty = true;
+ mutable bool mLightingDirty = true;
+
static LLSD rayleighConfigDefault();
static LLSD absorptionConfigDefault();
static LLSD mieConfigDefault();
- void calculateHeavnlyBodyPositions();
- void calculateLightSettings();
+ void calculateHeavnlyBodyPositions() const;
+ void calculateLightSettings() const;
- LLVector3 mSunDirection;
- LLVector3 mMoonDirection;
- LLVector3 mLightDirection;
- LLVector3 mClampedLightDirection;
+ mutable LLVector3 mSunDirection;
+ mutable LLVector3 mMoonDirection;
+ mutable LLVector3 mLightDirection;
static const F32 DOME_RADIUS;
static const F32 DOME_OFFSET;
- LLColor4U mFadeColor;
- LLColor4 mMoonAmbient;
- LLColor3 mMoonDiffuse;
- LLColor4 mSunAmbient;
- LLColor3 mSunDiffuse;
-
- LLColor4 mTotalAmbient;
+ mutable LLColor4U mFadeColor;
+ mutable LLColor4 mMoonAmbient;
+ mutable LLColor3 mMoonDiffuse;
+ mutable LLColor4 mSunAmbient;
+ mutable LLColor3 mSunDiffuse;
+ mutable LLColor4 mTotalAmbient;
LLUUID mNextSunTextureId;
LLUUID mNextMoonTextureId;
diff --git a/indra/llmath/llquaternion.cpp b/indra/llmath/llquaternion.cpp
index a7ff707bb8..a8d9eba2a0 100644
--- a/indra/llmath/llquaternion.cpp
+++ b/indra/llmath/llquaternion.cpp
@@ -38,8 +38,6 @@
#include "m3math.h"
#include "llquantize.h"
-#pragma optimize("", off)
-
// WARNING: Don't use this for global const definitions! using this
// at the top of a *.cpp file might not give you what you think.
const LLQuaternion LLQuaternion::DEFAULT;
diff --git a/indra/llmath/m3math.cpp b/indra/llmath/m3math.cpp
index 7e59e10bab..65eb3348de 100644
--- a/indra/llmath/m3math.cpp
+++ b/indra/llmath/m3math.cpp
@@ -34,8 +34,6 @@
#include "m3math.h"
#include "llquaternion.h"
-#pragma optimize("", off)
-
// LLMatrix3
// ji
diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h
index 113909c1c6..ceebc7000b 100644
--- a/indra/llrender/llrender.h
+++ b/indra/llrender/llrender.h
@@ -503,6 +503,11 @@ const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X
0.f, 1.f, 0.f, 0.f, // Y becomes Z
0.f, 0.f, 0.f, 1.f };
+const F32 XYZ_TO_OGL_ROTATION[16] = { 1.f, 0.f, 0.f, 0.f, // X stays X
+ 0.f, 0.f, -1.f, 0.f, // Z becomes -Y
+ 0.f, 1.f, 0.f, 0.f, // Y becomes Z
+ 0.f, 0.f, 0.f, 1.f };
+
glh::matrix4f copy_matrix(F32* src);
glh::matrix4f get_current_modelview();
glh::matrix4f get_current_projection();
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 4d0e0f2249..aa54a5f040 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -35,6 +35,8 @@
#include "OpenGL/OpenGL.h"
#endif
+#pragma optimize("", off)
+
#ifdef LL_RELEASE_FOR_DOWNLOAD
#define UNIFORM_ERRS LL_WARNS_ONCE("Shader")
#else
@@ -552,8 +554,8 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string&
if (log.length() > 0)
{
- LL_INFOS() << "Shader loading from " << fname << ":\n" << LL_ENDL;
- LL_INFOS() << log << LL_ENDL;
+ LL_INFOS("ShaderErrors") << "Shader loading from " << fname << ":\n" << LL_ENDL;
+ LL_INFOS("ShaderErrors") << log << LL_ENDL;
}
}
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index c9e0f7c2f4..0793784878 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -8645,7 +8645,7 @@
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
- <integer>0</integer>
+ <integer>1</integer>
</map>
<key>RenderLocalLights</key>
<map>
diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
index c20092bfe0..371b32406c 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl
@@ -82,6 +82,8 @@ vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten);
vec3 scaleFragSoftClip(vec3 l);
vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit);
void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten);
+vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten);
+vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten);
vec4 getPosition_d(vec2 pos_screen, float depth)
{
@@ -147,7 +149,7 @@ void main()
calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten);
- col = atmosAmbient(vec3(0));
+ col = atmosFragAmbient(vec3(0), amblit);
float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
ambient *= 0.5;
ambient *= ambient;
@@ -167,7 +169,7 @@ void main()
//
float sa = dot(refnormpersp, sun_dir.xyz);
- vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r);
+ vec3 dumbshiny = sunlit*scol_ambocc.r*(texture2D(lightFunc, vec2(sa, spec.a)).r);
// add the two types of shiny together
vec3 spec_contrib = dumbshiny * spec.rgb;
@@ -192,7 +194,7 @@ void main()
if (norm.w < 0.5)
{
col = mix(atmosFragLighting(col, additive, atten), fullbrightFragAtmosTransport(col, atten, additive), diffuse.a);
- col = mix(scaleFragSoftClip(col), fullbrightFragScaleSoftClip(col), diffuse.a);
+ col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a);
}
#ifdef WATER_FOG
diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp
index bcc0023089..9cd59c61ec 100644
--- a/indra/newview/lldrawpoolwater.cpp
+++ b/indra/newview/lldrawpoolwater.cpp
@@ -488,26 +488,29 @@ void LLDrawPoolWater::shade()
LLVector3 light_dir;
LLColor3 light_color;
- LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
+ LLEnvironment& environment = LLEnvironment::instance();
+ LLSettingsWater::ptr_t pwater = environment.getCurrentWater();
+ LLSettingsSky::ptr_t psky = environment.getCurrentSky();
- light_dir = voskyp->getLightDirection();
+ light_dir = environment.getLightDirection();
light_dir.normalize();
- bool sun_up = LLEnvironment::instance().getIsSunUp();
- bool moon_up = LLEnvironment::instance().getIsSunUp();
+ bool sun_up = environment.getIsSunUp();
+ bool moon_up = environment.getIsMoonUp();
if (sun_up)
{
- light_color = light_color + voskyp->getSunAmbientColor();
- light_diffuse += voskyp->getSunDiffuseColor();
+ light_color = light_color + psky->getSunAmbient();
+ light_diffuse += psky->getSunDiffuse();
}
light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0.f);
if (moon_up)
{
- light_color += voskyp->getMoonDiffuseColor();
- light_diffuse += voskyp->getMoonDiffuseColor() * 0.5f;
+ LLColor3 moon_diffuse_color = psky->getMoonDiffuse();
+ light_color += moon_diffuse_color;
+ light_diffuse += moon_diffuse_color * 0.5f;
if (!sun_up)
{
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index 277f1f3d6c..def81e46fc 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -179,22 +179,12 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
sky_shader->bindTexture(LLShaderMgr::SINGLE_MIE_SCATTER_TEX, gAtmosphere->getMieScattering());
sky_shader->bindTexture(LLShaderMgr::ILLUMINANCE_TEX, gAtmosphere->getIlluminance());
- static float sunSize = (float)cos(0.0005);
+ LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+ LLVector4 light_dir = LLEnvironment::instance().getClampedLightNorm();
+ F32 sunSize = (float)cosf(psky->getSunArcRadians());
sky_shader->uniform1f(LLShaderMgr::SUN_SIZE, sunSize);
-
- static LLVector3 solDir(-0.935f, 0.23f, 0.27f);
-
- static bool fooA = false;
- static bool fooB = false;
-
- //neither of these appear to track with the env settings, would the real sun please stand up.
- if (fooA) solDir = gPipeline.mTransformedSunDir;
- if (fooB) solDir = gSky.mVOSkyp->getSun().getDirection();
-
- solDir.normalize();
-
- sky_shader->uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, solDir.mV);
+ sky_shader->uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, light_dir.mV);
// clouds are rendered along with sky in adv atmo
if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && sCloudNoiseTexture.notNull())
@@ -295,7 +285,7 @@ void LLDrawPoolWLSky::renderSkyClouds(const LLVector3& camPosLocal, F32 camHeigh
cloud_shader->bind();
/// Render the skydome
- renderDome(camPosLocal, camHeightLocal, cloud_shader);
+//renderDome(camPosLocal, camHeightLocal, cloud_shader);
cloud_shader->unbind();
}
@@ -339,6 +329,7 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
if (gPipeline.canUseVertexShaders())
{
gHighlightProgram.bind();
+ gHighlightProgram.uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, color.mV);
}
LLFacePool::LLOverrideFaceColor color_override(this, color);
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index a6f0f2cb62..0177f88b6d 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -56,6 +56,8 @@
#include "llatmosphere.h"
+#pragma optimize("", off)
+
//define EXPORT_PRESETS 1
//=========================================================================
namespace
@@ -630,6 +632,52 @@ void LLEnvironment::updateEnvironment(F64Seconds transition, bool forced)
}
}
+LLVector3 LLEnvironment::getLightDirection() const
+{
+ LLSettingsSky::ptr_t psky = mCurrentEnvironment->getSky();
+ if (!psky)
+ {
+ return LLVector3(0, 0, 1);
+ }
+ return psky->getLightDirection();
+}
+
+LLVector4 LLEnvironment::toCFR(const LLVector3 vec) const
+{
+ LLVector4 vec_cfr(vec.mV[1], vec.mV[0], vec.mV[2], 0.0f);
+ return vec_cfr;
+}
+
+LLVector4 LLEnvironment::toLightNorm(const LLVector3 vec) const
+{
+ LLVector4 vec_ogl(vec.mV[1], vec.mV[2], vec.mV[0], 0.0f);
+ return vec_ogl;
+}
+
+LLVector4 LLEnvironment::getLightDirectionCFR() const
+{
+ LLVector3 light_direction = getLightDirection();
+ LLVector4 light_direction_cfr = toCFR(light_direction);
+ return light_direction_cfr;
+}
+
+LLVector4 LLEnvironment::getClampedLightNorm() const
+{
+ LLVector3 light_direction = getLightDirection();
+ if (light_direction.mV[2] < -0.1f)
+ {
+ light_direction.mV[2] = -0.1f;
+ }
+ return toLightNorm(light_direction);
+}
+
+LLVector4 LLEnvironment::getRotatedLightNorm() const
+{
+ LLVector3 light_direction = getLightDirection();
+ light_direction *= LLQuaternion(-mLastCamYaw, LLVector3(0.f, 1.f, 0.f));
+ return toLightNorm(light_direction);
+}
+
//-------------------------------------------------------------------------
void LLEnvironment::update(const LLViewerCamera * cam)
{
@@ -644,18 +692,14 @@ void LLEnvironment::update(const LLViewerCamera * cam)
// update clouds, sun, and general
updateCloudScroll();
- F32 camYaw = cam->getYaw();
+ // cache this for use in rotating the rotated light vec for shader param updates later...
+ mLastCamYaw = cam->getYaw() + SUN_DELTA_YAW;
stop_glerror();
// *TODO: potential optimization - this block may only need to be
// executed some of the time. For example for water shaders only.
{
- LLVector3 lightNorm3( getLightDirection() );
-
- lightNorm3 *= LLQuaternion(-(camYaw + SUN_DELTA_YAW), LLVector3(0.f, 1.f, 0.f));
- mRotatedLight = LLVector4(lightNorm3, 0.f);
-
LLViewerShaderMgr::shader_iter shaders_iter, end_shaders;
end_shaders = LLViewerShaderMgr::instance()->endShaders();
for (shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter)
@@ -767,26 +811,10 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
void LLEnvironment::updateShaderUniforms(LLGLSLShader *shader)
{
if (gPipeline.canUseWindLightShaders())
- {
- updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
+ {
updateGLVariablesForSettings(shader, mCurrentEnvironment->getWater());
- }
-
- if (shader->mShaderGroup == LLGLSLShader::SG_DEFAULT)
- {
- stop_glerror();
- shader->uniform4fv(LLShaderMgr::LIGHTNORM, 1, mRotatedLight.mV);
- shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
- stop_glerror();
- }
- else if (shader->mShaderGroup == LLGLSLShader::SG_SKY)
- {
- stop_glerror();
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, getClampedLightDirection().mV);
- stop_glerror();
- }
-
- shader->uniform1f(LLShaderMgr::SCENE_LIGHT_STRENGTH, getSceneLightStrength());
+ updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
+ }
}
LLEnvironment::list_name_id_t LLEnvironment::getSkyList() const
@@ -1552,6 +1580,7 @@ void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
mInitialized = false;
mSky = psky;
+ mSky->update();
mBlenderSky.reset();
if (gAtmosphere)
@@ -1570,6 +1599,7 @@ void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater)
mInitialized = false;
mWater = pwater;
+ mWater->update();
mBlenderWater.reset();
}
diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h
index 615318a4e6..27bb6e7fc2 100644
--- a/indra/newview/llenvironment.h
+++ b/indra/newview/llenvironment.h
@@ -188,15 +188,23 @@ public:
bool getIsSunUp() const;
bool getIsMoonUp() const;
- inline F32 getSceneLightStrength() const { return mSceneLightStrength; }
- inline void setSceneLightStrength(F32 light_strength) { mSceneLightStrength = light_strength; }
+ // Returns either sun or moon direction (depending on which is up and stronger)
+ // Light direction in +x right, +z up, +y at internal coord sys
+ LLVector3 getLightDirection() const;
- inline LLVector4 getLightDirection() const { return ((mCurrentEnvironment->getSky()) ? LLVector4(mCurrentEnvironment->getSky()->getLightDirection(), 0.0f) : LLVector4(0, 0, 1, 0)); }
- inline LLVector4 getClampedLightDirection() const { return LLVector4(mCurrentEnvironment->getSky()->getClampedLightDirection(), 0.0f); }
- inline LLVector4 getRotatedLight() const { return mRotatedLight; }
+ // Returns light direction converted to CFR coord system
+ LLVector4 getLightDirectionCFR() const;
+
+ // Returns light direction converted to OGL coord system
+ // and clamped above -0.1f in Y to avoid render artifacts in sky shaders
+ LLVector4 getClampedLightNorm() const;
+
+ // Returns light direction converted to OGL coord system
+ // and rotated by last cam yaw needed by water rendering shaders
+ LLVector4 getRotatedLightNorm() const;
static LLSettingsWater::ptr_t createWaterFromLegacyPreset(const std::string filename);
- static LLSettingsSky::ptr_t createSkyFromLegacyPreset(const std::string filename);
+ static LLSettingsSky::ptr_t createSkyFromLegacyPreset(const std::string filename);
//-------------------------------------------
connection_t setSkyListChange(const change_signal_t::slot_type& cb);
@@ -220,6 +228,9 @@ protected:
virtual void initSingleton();
private:
+ LLVector4 toCFR(const LLVector3 vec) const;
+ LLVector4 toLightNorm(const LLVector3 vec) const;
+
class DayInstance
{
public:
@@ -295,6 +306,7 @@ private:
};
static const F32 SUN_DELTA_YAW;
+ F32 mLastCamYaw = 0.0f;
typedef std::map<LLUUID, LLSettingsBase::ptr_t> AssetSettingMap_t;
@@ -325,9 +337,6 @@ private:
namedSettingMap_t mDayCycleByName;
AssetSettingMap_t mDayCycleById;
- F32 mSceneLightStrength;
- LLVector4 mRotatedLight;
-
UserPrefs mUserPrefs;
change_signal_t mSkyListChange;
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 5af4cd89c4..a880cfa2a2 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -42,7 +42,6 @@
#include "llrender.h"
#include "lllightconstants.h"
#include "llsky.h"
-#include "llenvironment.h"
#include "llviewercamera.h"
#include "llviewertexturelist.h"
#include "llvopartgroup.h"
@@ -1626,14 +1625,11 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
{
tep->getScale( &s_scale, &t_scale );
}
-
- LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-
// Use the nudged south when coming from above sun angle, such
// that emboss mapping always shows up on the upward faces of cubes when
// it's noon (since a lot of builders build with the sun forced to noon).
LLVector3 sun_ray = gSky.mVOSkyp->mBumpSunDir;
- LLVector3 moon_ray = psky->getMoonDirection();
+ LLVector3 moon_ray = gSky.mVOSkyp->getMoon().getDirection();
LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray;
bump_s_primary_light_ray.load3((offset_multiple * s_scale * primary_light_ray).mV);
diff --git a/indra/newview/lllegacyatmospherics.cpp b/indra/newview/lllegacyatmospherics.cpp
index ff09e62f76..59cfab61fd 100644
--- a/indra/newview/lllegacyatmospherics.cpp
+++ b/indra/newview/lllegacyatmospherics.cpp
@@ -267,7 +267,7 @@ void LLAtmospherics::calcSkyColorWLVert(LLVector3 & Pn, AtmosphericsVars& vars)
F32 density_multiplier = psky->getDensityMultiplier();
F32 max_y = psky->getMaxY();
- LLVector3 lightnorm = psky->getLightNormal();
+ LLVector3 lightnorm = LLVector3(LLEnvironment::instance().getClampedLightNorm());
// project the direction ray onto the sky dome.
F32 phi = acos(Pn[1]);
@@ -444,8 +444,10 @@ LLColor3 LLAtmospherics::calcSkyColorWLFrag(LLVector3 & Pn, AtmosphericsVars& va
return res;
}
-void LLAtmospherics::updateFog(const F32 distance, LLVector3& tosun)
+void LLAtmospherics::updateFog(const F32 distance, const LLVector3& tosun_in)
{
+ LLVector3 tosun = tosun_in;
+
if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOG))
{
if (!LLGLSLShader::sNoFixedFunction)
diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h
index 83250ee50b..ded7e1f554 100644
--- a/indra/newview/lllegacyatmospherics.h
+++ b/indra/newview/lllegacyatmospherics.h
@@ -207,7 +207,7 @@ public:
~LLAtmospherics();
void init();
- void updateFog(const F32 distance, LLVector3& tosun);
+ void updateFog(const F32 distance, const LLVector3& tosun);
const LLHaze& getHaze() const { return mHaze; }
LLHaze& getHaze() { return mHaze; }
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index bd69659e7a..85cdd1e984 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -365,7 +365,7 @@ LLSettingsSky::ptr_t LLSettingsVOSky::buildSky(LLSD settings)
LLSettingsSky::ptr_t LLSettingsVOSky::buildFromLegacyPreset(const std::string &name, const LLSD &legacy)
{
- LLSD newsettings = LLSettingsSky::translateLegacySettings(legacy, &name);
+ LLSD newsettings = LLSettingsSky::translateLegacySettings(legacy);
newsettings[SETTING_NAME] = name;
@@ -476,7 +476,7 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
sunquat.getEulerAngles(&roll, &pitch, &yaw);
legacy[SETTING_LEGACY_EAST_ANGLE] = yaw;
- legacy[SETTING_LEGACY_SUN_ANGLE] = pitch;
+ legacy[SETTING_LEGACY_SUN_ANGLE] = -pitch;
return legacy;
}
@@ -485,32 +485,51 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
void LLSettingsVOSky::updateSettings()
{
LLSettingsSky::updateSettings();
-
LLVector3 sun_direction = getSunDirection();
LLVector3 moon_direction = getMoonDirection();
- // axis swap converts from +x right, +z up, +y at
- // to CFR (+x at, +z up, +y right)
- // set direction (in CRF) and don't allow overriding
- //LLVector3 crf_sunDirection(sun_direction.mV[1], sun_direction.mV[0], sun_direction.mV[2]);
- //LLVector3 crf_moonDirection(moon_direction.mV[1], moon_direction.mV[0], moon_direction.mV[2]);
-
- gSky.setSunDirection(sun_direction, moon_direction);
+ F32 dp = getLightDirection() * LLVector3(0.0f, 0.0f, 1.0f);
+ if (dp < 0)
+ {
+ dp = 0;
+ }
+ dp = llmax(dp, 0.1f);
+
+ // 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);
+ mSceneLightStrength = 2.0f * (1.0f + sun_dynamic_range * dp);
+
+ // Axis swaps convert from +x right, +z up, +y at
+ // to CFR +x at, +z up, +y right coord sys
+ LLVector3 sun_direction_cfr(sun_direction.mV[0], -sun_direction.mV[1], sun_direction.mV[2]);
+ LLVector3 moon_direction_cfr(moon_direction.mV[0], -moon_direction.mV[1], moon_direction.mV[2]);
+ gSky.setSunAndMoonDirectionsCFR(sun_direction_cfr, moon_direction_cfr);
}
void LLSettingsVOSky::applySpecial(void *ptarget)
{
LLGLSLShader *shader = (LLGLSLShader *)ptarget;
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, getClampedLightDirection().mV);
+ LLVector4 light_direction = LLEnvironment::instance().getClampedLightNorm();
- shader->uniform4f(LLShaderMgr::GAMMA, getGamma(), 0.0, 0.0, 1.0);
+ if (shader->mShaderGroup == LLGLSLShader::SG_DEFAULT)
+ {
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, light_direction.mV);
+ shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
+ }
+ else if (shader->mShaderGroup == LLGLSLShader::SG_SKY)
+ {
+ LLVector4 light_direction = LLEnvironment::instance().getClampedLightNorm();
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, light_direction.mV);
- {
LLVector4 vect_c_p_d1(mSettings[SETTING_CLOUD_POS_DENSITY1]);
vect_c_p_d1 += LLVector4(LLEnvironment::instance().getCloudScrollDelta());
shader->uniform4fv(LLShaderMgr::CLOUD_POS_DENSITY1, 1, vect_c_p_d1.mV);
- }
+ }
+
+ shader->uniform1f(LLShaderMgr::SCENE_LIGHT_STRENGTH, mSceneLightStrength);
+ shader->uniform4f(LLShaderMgr::GAMMA, getGamma(), 0.0, 0.0, 1.0);
}
LLSettingsSky::parammapping_t LLSettingsVOSky::getParameterMap() const
@@ -519,12 +538,12 @@ LLSettingsSky::parammapping_t LLSettingsVOSky::getParameterMap() const
if (param_map.empty())
{
+// LEGACY_ATMOSPHERICS
+ param_map[SETTING_AMBIENT] = LLShaderMgr::AMBIENT;
param_map[SETTING_BLUE_DENSITY] = LLShaderMgr::BLUE_DENSITY;
param_map[SETTING_BLUE_HORIZON] = LLShaderMgr::BLUE_HORIZON;
param_map[SETTING_HAZE_DENSITY] = LLShaderMgr::HAZE_DENSITY;
param_map[SETTING_HAZE_HORIZON] = LLShaderMgr::HAZE_HORIZON;
-
- param_map[SETTING_AMBIENT] = LLShaderMgr::AMBIENT;
param_map[SETTING_DENSITY_MULTIPLIER] = LLShaderMgr::DENSITY_MULTIPLIER;
param_map[SETTING_DISTANCE_MULTIPLIER] = LLShaderMgr::DISTANCE_MULTIPLIER;
@@ -663,12 +682,16 @@ void LLSettingsVOWater::applySpecial(void *ptarget)
{
LLGLSLShader *shader = (LLGLSLShader *)ptarget;
- shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, getWaterPlane().mV);
- shader->uniform1f(LLShaderMgr::WATER_FOGKS, getWaterFogKS());
+ if (shader->mShaderGroup == LLGLSLShader::SG_WATER)
+ {
+ shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, getWaterPlane().mV);
+ shader->uniform1f(LLShaderMgr::WATER_FOGKS, getWaterFogKS());
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, LLEnvironment::instance().getRotatedLight().mV);
- shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
- shader->uniform1f(LLViewerShaderMgr::DISTANCE_MULTIPLIER, 0);
+ LLVector4 rotated_light_direction = LLEnvironment::instance().getRotatedLightNorm();
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, rotated_light_direction.mV);
+ shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
+ shader->uniform1f(LLViewerShaderMgr::DISTANCE_MULTIPLIER, 0);
+ }
}
void LLSettingsVOWater::updateSettings()
@@ -702,7 +725,7 @@ void LLSettingsVOWater::updateSettings()
mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
- LLVector4 light_direction = LLEnvironment::instance().getLightDirection();
+ LLVector4 light_direction = LLEnvironment::instance().getClampedLightNorm();
mWaterFogKS = 1.f / llmax(light_direction.mV[2], WATER_FOG_LIGHT_CLAMP);
}
@@ -820,7 +843,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildFromLegacyMessage(const LLUUID &regio
for (LLSD::map_iterator itm = skydefs.beginMap(); itm != skydefs.endMap(); ++itm)
{
std::string newname = "sky:" + (*itm).first;
- LLSD newsettings = LLSettingsSky::translateLegacySettings((*itm).second, &newname);
+ LLSD newsettings = LLSettingsSky::translateLegacySettings((*itm).second);
newsettings[SETTING_NAME] = newname;
frames[newname] = newsettings;
diff --git a/indra/newview/llsettingsvo.h b/indra/newview/llsettingsvo.h
index 3339aaf037..2f91117858 100644
--- a/indra/newview/llsettingsvo.h
+++ b/indra/newview/llsettingsvo.h
@@ -107,6 +107,7 @@ protected:
virtual parammapping_t getParameterMap() const override;
bool m_isAdvanced = false;
+ F32 mSceneLightStrength = 3.0f;
};
//=========================================================================
diff --git a/indra/newview/llsky.cpp b/indra/newview/llsky.cpp
index f7ccf7c7ff..41fe206ada 100644
--- a/indra/newview/llsky.cpp
+++ b/indra/newview/llsky.cpp
@@ -129,170 +129,31 @@ void LLSky::resetVertexBuffers()
}
}
-void LLSky::setSunDirection(const LLVector3 &sun_direction, const LLVector3 &moon_direction)
+void LLSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_direction, const LLVector3 &moon_direction)
{
- if(mVOSkyp.notNull()) {
- mVOSkyp->setSunDirection(sun_direction, moon_direction);
+ if(mVOSkyp.notNull()) {
+ mVOSkyp->setSunAndMoonDirectionsCFR(sun_direction, moon_direction);
}
}
-/*LLVector3 LLSky::getSunDirection() const
-{
- if (mVOSkyp)
- {
- return mVOSkyp->getToSun();
- }
- else
- {
- return LLVector3::z_axis;
- }
-}
-
-
-LLVector3 LLSky::getMoonDirection() const
-{
- if (mVOSkyp)
- {
- return mVOSkyp->getToMoon();
- }
- else
- {
- return LLVector3::z_axis;
- }
-}*/
-
-
-LLColor4 LLSky::getSunDiffuseColor() const
-{
- if (mVOSkyp)
- {
- return LLColor4(mVOSkyp->getSunDiffuseColor());
- }
- else
- {
- return LLColor4(1.f, 1.f, 1.f, 1.f);
- }
-}
-
-LLColor4 LLSky::getSunAmbientColor() const
-{
- if (mVOSkyp)
- {
- return LLColor4(mVOSkyp->getSunAmbientColor());
- }
- else
- {
- return LLColor4(0.f, 0.f, 0.f, 1.f);
- }
-}
-
-
-LLColor4 LLSky::getMoonDiffuseColor() const
-{
- if (mVOSkyp)
- {
- return LLColor4(mVOSkyp->getMoonDiffuseColor());
- }
- else
- {
- return LLColor4(1.f, 1.f, 1.f, 1.f);
- }
-}
-
-LLColor4 LLSky::getMoonAmbientColor() const
-{
- if (mVOSkyp)
- {
- return LLColor4(mVOSkyp->getMoonAmbientColor());
- }
- else
- {
- return LLColor4(0.f, 0.f, 0.f, 0.f);
- }
-}
-
-
-LLColor4 LLSky::getTotalAmbientColor() const
-{
- if (mVOSkyp)
- {
- return mVOSkyp->getTotalAmbientColor();
- }
- else
- {
- return LLColor4(1.f, 1.f, 1.f, 1.f);
- }
-}
-
-
-/*BOOL LLSky::sunUp() const
-{
- if (mVOSkyp)
- {
- return mVOSkyp->isSunUp();
- }
- else
- {
- return TRUE;
- }
-}*/
-
-
-LLColor4U LLSky::getFadeColor() const
-{
- if (mVOSkyp)
- {
- return mVOSkyp->getFadeColor();
- }
- else
- {
- return LLColor4(1.f, 1.f, 1.f, 1.f);
- }
-}
-
-
//////////////////////////////////////////////////////////////////////
// Public Methods
//////////////////////////////////////////////////////////////////////
-void LLSky::init(const LLVector3 &sun_direction)
+void LLSky::init()
{
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
-
mVOWLSkyp = static_cast<LLVOWLSky*>(gObjectList.createObjectViewer(LLViewerObject::LL_VO_WL_SKY, NULL));
- mVOWLSkyp->initSunDirection(sun_direction, LLVector3::zero);
+ mVOWLSkyp->init();
gPipeline.createObject(mVOWLSkyp.get());
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
-
mVOSkyp = (LLVOSky *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SKY, NULL);
-
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
-
- mVOSkyp->initSunDirection(sun_direction, LLVector3());
-
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
-
- gPipeline.createObject((LLViewerObject *)mVOSkyp);
-
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
+ mVOSkyp->init();
+ gPipeline.createObject(mVOSkyp.get());
mVOGroundp = (LLVOGround*)gObjectList.createObjectViewer(LLViewerObject::LL_VO_GROUND, NULL);
- LLVOGround *groundp = mVOGroundp;
- gPipeline.createObject((LLViewerObject *)groundp);
-
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
-
- gSky.setFogRatio(gSavedSettings.getF32("RenderFogRatio"));
+ gPipeline.createObject(mVOGroundp.get());
- LLGLState::checkStates();
- LLGLState::checkTextureChannels();
+ gSky.setFogRatio(gSavedSettings.getF32("RenderFogRatio"));
mUpdatedThisFrame = TRUE;
}
diff --git a/indra/newview/llsky.h b/indra/newview/llsky.h
index 626076fea4..8e86853481 100644
--- a/indra/newview/llsky.h
+++ b/indra/newview/llsky.h
@@ -48,11 +48,11 @@ public:
LLSky();
~LLSky();
- void init(const LLVector3 &sun_direction);
-
+ void init();
void cleanup();
- void setSunDirection(const LLVector3 &sun_direction, const LLVector3 &moon_direction);
+ // These directions should be in CFR coord sys (+x at, +z up, +y right)
+ void setSunAndMoonDirectionsCFR(const LLVector3 &sun_direction, const LLVector3 &moon_direction);
LLColor4 getSkyFogColor() const;
@@ -70,19 +70,6 @@ public:
F32 getFogRatio() const;
LLColor4U getFadeColor() const;
- //LLVector3 getSunDirection() const;
- //LLVector3 getMoonDirection() const;
-
- LLColor4 getSunDiffuseColor() const;
- LLColor4 getMoonDiffuseColor() const;
- LLColor4 getSunAmbientColor() const;
- LLColor4 getMoonAmbientColor() const;
- LLColor4 getTotalAmbientColor() const;
- //BOOL sunUp() const;
-
- // Legacy
- void setSunPhase(const F32) { }
-
void destroyGL();
void restoreGL();
void resetVertexBuffers();
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index deebd91198..e7a149ac0c 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -332,7 +332,6 @@ bool idle_startup()
static std::string auth_desc;
static std::string auth_message;
- static LLVector3 initial_sun_direction(1.f, 0.f, 0.f);
static LLVector3 agent_start_position_region(10.f, 10.f, 10.f); // default for when no space server
// last location by default
@@ -1467,7 +1466,7 @@ bool idle_startup()
LLGLState::checkTextureChannels();
LLEnvironment::instance().loadPreferences();
- gSky.init(initial_sun_direction);
+ gSky.init();
LLGLState::checkStates();
LLGLState::checkTextureChannels();
diff --git a/indra/newview/lltoolgun.cpp b/indra/newview/lltoolgun.cpp
index 6903e69d46..fb96804bfa 100644
--- a/indra/newview/lltoolgun.cpp
+++ b/indra/newview/lltoolgun.cpp
@@ -108,7 +108,7 @@ BOOL LLToolGun::handleHover(S32 x, S32 y, MASK mask)
if (gSavedSettings.getBOOL("MouseSun"))
{
LLVector3 sunpos = LLViewerCamera::getInstance()->getAtAxis();
- gSky.setSunDirection(sunpos, -sunpos);
+ gSky.setSunAndMoonDirectionsCFR(sunpos, -sunpos);
gSavedSettings.setVector3("SkySunDefaultPosition", LLViewerCamera::getInstance()->getAtAxis());
}
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index e4c71c1648..e88afdc465 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -3395,6 +3395,7 @@ void process_kill_object(LLMessageSystem *mesgsys, void **user_data)
void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
{
LLVector3 sun_direction;
+ LLVector3 moon_direction;
LLVector3 sun_ang_velocity;
F32 phase;
U64 space_time_usec;
@@ -3416,11 +3417,11 @@ void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
LL_DEBUGS("Windlight Sync") << "Sun phase: " << phase << " rad = " << fmodf(phase / F_TWO_PI + 0.25, 1.f) * 24.f << " h" << LL_ENDL;
- gSky.setSunPhase(phase);
- if ( !gSavedSettings.getBOOL("SkyOverrideSimSunPosition") )
- {
- gSky.setSunDirection(sun_direction, -sun_direction);
- }
+
+ /* LAPRAS
+ We decode these parts of the message but ignore them
+ as the real values are provided elsewhere. */
+ (void)sun_direction, (void)moon_direction, (void)phase;
}
void process_sound_trigger(LLMessageSystem *msg, void **)
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index 5aa29f920e..40cf4c82e6 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -46,6 +46,8 @@
#include "llenvironment.h"
#include "llatmosphere.h"
+#pragma optimize("", off)
+
#ifdef LL_RELEASE_FOR_DOWNLOAD
#define UNIFORM_ERRS LL_WARNS_ONCE("Shader")
#else
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp
index dc4f4a92d4..a2ea3181ca 100644
--- a/indra/newview/llvosky.cpp
+++ b/indra/newview/llvosky.cpp
@@ -53,6 +53,8 @@
#include "llsettingssky.h"
#include "llenvironment.h"
+#pragma optimize("", off)
+
#undef min
#undef max
@@ -71,6 +73,9 @@ 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);
+static const F32 LIGHT_DIRECTION_THRESHOLD = (F32) cosf(DEG_TO_RAD * 1.f);
+static const F32 COLOR_CHANGE_THRESHOLD = 0.01f;
+
// Exported globals
LLUUID gSunTextureID = IMG_SUN;
LLUUID gMoonTextureID = IMG_MOON;
@@ -185,11 +190,165 @@ void LLSkyTex::bindTexture(BOOL curr)
}
/***************************************
- 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;
@@ -227,16 +386,6 @@ LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
mAtmHeight = ATM_HEIGHT;
mEarthCenter = LLVector3(mCameraPosAgent.mV[0], mCameraPosAgent.mV[1], -EARTH_RADIUS);
- // *LAPRAS
- mSunDefaultPosition = LLEnvironment::instance().getCurrentSky()->getSunDirection();
-
- if (gSavedSettings.getBOOL("SkyOverrideSimSunPosition"))
- {
-
- initSunDirection(LLVector3(mSunDefaultPosition.mV[2], mSunDefaultPosition.mV[0], mSunDefaultPosition.mV[1]), LLVector3(0, 0, 0));
- }
-
-
mSun.setIntensity(SUN_INTENSITY);
mMoon.setIntensity(0.1f * SUN_INTENSITY);
@@ -265,6 +414,11 @@ LLVOSky::~LLVOSky()
void LLVOSky::init()
{
+ llassert(!mInitialized);
+
+ // Update sky at least once to get correct initial sun/moon directions and lighting calcs performed
+ LLEnvironment::instance().getCurrentSky()->update();
+
updateDirections();
// Initialize the cached normalized direction vectors
@@ -353,10 +507,11 @@ void LLVOSky::restoreGL()
if(cube_map)
{
cube_map->init(images);
- mForceUpdate = TRUE;
}
}
+ mForceUpdate = TRUE;
+
if (mDrawable)
{
gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
@@ -426,24 +581,13 @@ void LLVOSky::updateDirections(void)
mSun.renewColor();
mMoon.renewDirection();
mMoon.renewColor();
-
- float dp = psky->getSunDirection() * LLVector3::y_axis;
- 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);
- LLEnvironment::instance().setSceneLightStrength(2.0f * (1.0f + sun_dynamic_range * dp));
}
void LLVOSky::idleUpdate(LLAgent &agent, const F64 &time)
{
}
-BOOL LLVOSky::updateSky()
+bool LLVOSky::updateSky()
{
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
@@ -473,6 +617,8 @@ BOOL LLVOSky::updateSky()
mUpdateTimer.reset();
const S32 frame = next_frame;
+ mForceUpdate = mForceUpdate || (total_no_tiles == frame);
+
++next_frame;
next_frame = next_frame % cycle_frame_no;
@@ -482,26 +628,27 @@ BOOL LLVOSky::updateSky()
LLHeavenBody::setInterpVal( mInterpVal );
updateDirections();
- if (mForceUpdate || total_no_tiles == frame)
+ LLVector3 direction = mSun.getDirection();
+ direction.normalize();
+ const F32 dot_lighting = direction * mLastLightingDirection;
+
+ 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 light_direction_changed = (dot_lighting >= LIGHT_DIRECTION_THRESHOLD);
+ bool color_changed = (delta_color.length() >= COLOR_CHANGE_THRESHOLD);
+
+ mForceUpdate = mForceUpdate || light_direction_changed;
+ mForceUpdate = mForceUpdate || color_changed;
+ mForceUpdate = mForceUpdate || !mInitialized;
+
+ if (mForceUpdate)
{
- 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] - total_ambient.mV[0],
- mLastTotalAmbient.mV[1] - total_ambient.mV[1],
- mLastTotalAmbient.mV[2] - total_ambient.mV[2]);
-
- bool light_direction_changed = (dot_lighting >= LIGHT_DIRECTION_THRESHOLD);
- bool color_changed = (delta_color.length() >= COLOR_CHANGE_THRESHOLD);
- bool do_update = !mInitialized || mForceUpdate || light_direction_changed || color_changed;
- if ( do_update && !direction.isExactlyZero())
+ LLSkyTex::stepCurrent();
+
+ if (!direction.isExactlyZero())
{
mLastLightingDirection = direction;
mLastTotalAmbient = total_ambient;
@@ -509,52 +656,49 @@ BOOL LLVOSky::updateSky()
if (mCubeMap)
{
- if (mForceUpdate)
- {
- updateFog(LLViewerCamera::getInstance()->getFar());
+ 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++)
{
- for (int tile = 0; tile < NUM_TILES; tile++)
- {
- createSkyTexture(side, tile);
- }
+ createSkyTexture(side, tile);
}
+ }
- for (int side = 0; side < 6; side++)
- {
- 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));
- }
- next_frame = 0;
-
- // 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<LLPointer<LLImageRaw> > images;
- images.reserve(6);
- for (S32 side = 0; side < 6; side++)
- {
- images.push_back(mShinyTex[side].getImageRaw(TRUE));
- }
- mCubeMap->init(images);
- gGL.getTexUnit(0)->disable();
- }
+ for (int side = 0; side < 6; side++)
+ {
+ 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));
}
+ next_frame = 0;
+
+ // 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<LLPointer<LLImageRaw> > images;
+ images.reserve(6);
+ for (S32 side = 0; side < 6; side++)
+ {
+ images.push_back(mShinyTex[side].getImageRaw(TRUE));
+ }
+ mCubeMap->init(images);
+ gGL.getTexUnit(0)->disable();
+ }
}
}
@@ -706,7 +850,7 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
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())
{
@@ -722,7 +866,7 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
if (height_above_water > 0)
{
- BOOL render_ref = gPipeline.getPool(LLDrawPool::POOL_WATER)->getVertexShaderLevel() == 0;
+ bool render_ref = gPipeline.getPool(LLDrawPool::POOL_WATER)->getVertexShaderLevel() == 0;
if (sun_flag)
{
@@ -750,7 +894,7 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
return TRUE;
}
-BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right)
+bool LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right)
{
mHeavenlyBodyUpdated = TRUE ;
@@ -1180,96 +1324,35 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
void LLVOSky::updateFog(const F32 distance)
{
- LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
- m_legacyAtmospherics.updateFog(distance, psky->getSunDirection());
+ LLEnvironment& environment = LLEnvironment::instance();
+ LLVector3 light_dir = LLVector3(environment.getClampedLightNorm());
+ m_legacyAtmospherics.updateFog(distance, light_dir);
}
-void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity)
+void LLVOSky::setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir_cfr, const LLVector3 &moon_dir_cfr)
{
- 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();
-
- updateDirections();
+ mSun.setDirection(sun_dir_cfr);
+ mMoon.setDirection(moon_dir_cfr);
- if ( !mInitialized )
- {
- init();
- LLSkyTex::stepCurrent();
- }
-}
-
-void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &moon_dir)
-{
- LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir;
- LLVector3 moon_direction = (moon_dir.length() == 0) ? LLVector3::x_axis : moon_dir;
-
- sun_direction.normalize();
- moon_direction.normalize();
+ mLastLightingDirection = mSun.getDirection();
// 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;
+ {
+ // Same as dot product with the up direction + clamp.
+ F32 sunDot = llmax(0.f, sun_dir_cfr.mV[2]);
+ sunDot *= sunDot;
- // 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();
+ // 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;
- F32 dp = mLastLightingDirection * sun_direction;
- mSun.setDirection(sun_direction);
+ // 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();
+ }
- mMoon.setDirection(moon_direction);
updateDirections();
- if (dp < 0.995f) { //the sun jumped a great deal, update immediately
- mForceUpdate = TRUE;
- }
-}
-
-LLVector3 LLVOSky::getLightDirection() const
-{
- return LLEnvironment::instance().getCurrentSky()->getLightDirection();
-}
-
-LLColor4U LLVOSky::getFadeColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getFadeColor();
-}
-
-LLColor3 LLVOSky::getSunDiffuseColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getSunDiffuse();
-}
-
-LLColor3 LLVOSky::getMoonDiffuseColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getMoonDiffuse();
-}
-
-LLColor4 LLVOSky::getSunAmbientColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getSunAmbient();
-}
-
-LLColor4 LLVOSky::getMoonAmbientColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getMoonAmbient();
-}
-
-LLColor4 LLVOSky::getTotalAmbientColor() const
-{
- return LLEnvironment::instance().getCurrentSky()->getTotalAmbient();
+ LLSkyTex::stepCurrent();
}
diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h
index 96fe12e21c..4de3d12068 100644
--- a/indra/newview/llvosky.h
+++ b/indra/newview/llvosky.h
@@ -141,69 +141,56 @@ protected:
LLVector3 mAngularVelocity; // velocity of the local heavenly body
F32 mDiskRadius;
- BOOL mDraw; // FALSE - do not draw.
+ bool mDraw; // FALSE - do not draw.
F32 mHorizonVisibility; // number [0, 1] due to how horizon
F32 mVisibility; // same but due to other objects being in throng.
- BOOL mVisible;
+ bool mVisible;
static F32 sInterpVal;
LLVector3 mQuadCorner[4];
LLVector3 mO;
public:
- 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();
- }
+ LLHeavenBody(const F32 rad);
~LLHeavenBody() {}
- const LLVector3& getDirection() const { return mDirection; }
- void setDirection(const LLVector3 &direction) { mDirection = direction; }
- void setAngularVelocity(const LLVector3 &ang_vel) { mAngularVelocity = ang_vel; }
- const LLVector3& getAngularVelocity() const { return mAngularVelocity; }
+ const LLVector3& getDirection() const;
+ void setDirection(const LLVector3 &direction);
+ void setAngularVelocity(const LLVector3 &ang_vel);
+ const LLVector3& getAngularVelocity() const;
- const LLVector3& getDirectionCached() const { return mDirectionCached; }
- void renewDirection() { mDirectionCached = mDirection; }
+ const LLVector3& getDirectionCached() const;
+ void renewDirection();
- const LLColor3& getColorCached() const { return mColorCached; }
- void setColorCached(const LLColor3& c) { mColorCached = c; }
- const LLColor3& getColor() const { return mColor; }
- void setColor(const LLColor3& c) { mColor = c; }
+ const LLColor3& getColorCached() const;
+ void setColorCached(const LLColor3& c);
+ const LLColor3& getColor() const;
+ void setColor(const LLColor3& c);
- void renewColor() { mColorCached = mColor; }
+ void renewColor();
- static F32 interpVal() { return sInterpVal; }
- static void setInterpVal(const F32 v) { sInterpVal = v; }
+ static F32 interpVal();
+ static void setInterpVal(const F32 v);
- LLColor3 getInterpColor() const
- {
- return sInterpVal * mColor + (1 - sInterpVal) * mColorCached;
- }
+ LLColor3 getInterpColor() const;
- const F32& getVisibility() const { return mVisibility; }
- void setVisibility(const F32 c = 1) { mVisibility = c; }
+ const F32& getVisibility() const;
+ void setVisibility(const F32 c = 1);
- BOOL isVisible() const { return mVisible; }
- void setVisible(const BOOL v) { mVisible = v; }
+ bool isVisible() const;
+ void setVisible(const bool v);
- const F32& getIntensity() const { return mIntensity; }
- void setIntensity(const F32 c) { mIntensity = c; }
+ const F32& getIntensity() const;
+ void setIntensity(const F32 c);
- void setDiskRadius(const F32 radius) { mDiskRadius = radius; }
- F32 getDiskRadius() const { return mDiskRadius; }
+ void setDiskRadius(const F32 radius);
+ F32 getDiskRadius() const;
- void setDraw(const BOOL draw) { mDraw = draw; }
- BOOL getDraw() const { return mDraw; }
+ void setDraw(const bool draw);
+ bool getDraw() const;
- const LLVector3& corner(const S32 n) const { return mQuadCorner[n]; }
- LLVector3& corner(const S32 n) { return mQuadCorner[n]; }
- const LLVector3* corners() const { return mQuadCorner; }
+ const LLVector3& corner(const S32 n) const;
+ LLVector3& corner(const S32 n);
+ const LLVector3* corners() const;
};
class LLCubeMap;
@@ -237,7 +224,7 @@ public:
void restoreGL();
/*virtual*/ void idleUpdate(LLAgent &agent, const F64 &time);
- BOOL updateSky();
+ bool updateSky();
// Graphical stuff for objects - maybe broken out into render class
// later?
@@ -245,29 +232,15 @@ public:
/*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
/*virtual*/ BOOL updateGeometry(LLDrawable *drawable);
- const LLHeavenBody& getSun() const { return mSun; }
+ const LLHeavenBody& getSun() const { return mSun; }
const LLHeavenBody& getMoon() const { return mMoon; }
- //const LLVector3& getToSunLast() const { return mSun.getDirectionCached(); }
- //const LLVector3& getToSun() const { return mSun.getDirection(); }
- //const LLVector3& getToMoon() const { return mMoon.getDirection(); }
- //const LLVector3& getToMoonLast() const { return mMoon.getDirectionCached(); }
- //BOOL isSunUp() const { return mSun.getDirectionCached().mV[2] > -0.05f; }
-
- LLVector3 getLightDirection() const;
- LLColor3 getSunDiffuseColor() const;
- LLColor3 getMoonDiffuseColor() const;
- LLColor4 getSunAmbientColor() const;
- LLColor4 getMoonAmbientColor() const;
- LLColor4 getTotalAmbientColor() const;
-
- BOOL isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; }
-
- void initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity);
+ bool isSameFace(S32 idx, const LLFace* face) const { return mFace[idx] == face; }
- void setSunDirection(const LLVector3 &sun_dir, const LLVector3 &moon_dir);
+ // directions provided should already be in CFR coord sys (+x at, +z up, +y right)
+ void setSunAndMoonDirectionsCFR(const LLVector3 &sun_dir, const LLVector3 &moon_dir);
- BOOL updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 side, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right);
+ bool updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 side, LLHeavenBody& hb, const LLVector3 &up, const LLVector3 &right);
void updateReflectionGeometry(LLDrawable *drawable, F32 H, const LLHeavenBody& HB);
F32 getWorldScale() const { return mWorldScale; }
@@ -291,7 +264,7 @@ public:
LLCubeMap *getCubeMap() const { return mCubeMap; }
S32 getDrawRefl() const { return mDrawRefl; }
void setDrawRefl(const S32 r) { mDrawRefl = r; }
- BOOL isReflFace(const LLFace* face) const { return face == mFace[FACE_REFLECTION]; }
+ bool isReflFace(const LLFace* face) const { return face == mFace[FACE_REFLECTION]; }
LLFace* getReflFace() const { return mFace[FACE_REFLECTION]; }
LLViewerTexture* getSunTex() const { return mSunTexturep; }
@@ -333,12 +306,12 @@ protected:
LLColor3 mBrightestPointNew;
F32 mBrightnessScaleGuess;
LLColor3 mBrightestPointGuess;
- BOOL mWeatherChange;
+ bool mWeatherChange;
F32 mCloudDensity;
F32 mWind;
- BOOL mInitialized;
- BOOL mForceUpdate; //flag to force instantaneous update of cubemap
+ bool mInitialized;
+ bool mForceUpdate; //flag to force instantaneous update of cubemap
LLVector3 mLastLightingDirection;
LLColor3 mLastTotalAmbient;
F32 mAmbientScale;
@@ -351,7 +324,7 @@ protected:
LLFrameTimer mUpdateTimer;
- BOOL mHeavenlyBodyUpdated ;
+ bool mHeavenlyBodyUpdated ;
LLAtmospherics m_legacyAtmospherics;
};
diff --git a/indra/newview/llvowlsky.cpp b/indra/newview/llvowlsky.cpp
index 3ab149fef0..bdef2ed9fb 100644
--- a/indra/newview/llvowlsky.cpp
+++ b/indra/newview/llvowlsky.cpp
@@ -87,11 +87,6 @@ LLVOWLSky::LLVOWLSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regi
initStars();
}
-void LLVOWLSky::initSunDirection(LLVector3 const & sun_direction,
- LLVector3 const & sun_angular_velocity)
-{
-}
-
void LLVOWLSky::idleUpdate(LLAgent &agent, const F64 &time)
{
diff --git a/indra/newview/llvowlsky.h b/indra/newview/llvowlsky.h
index 8bc6afba1b..3c801d5d57 100644
--- a/indra/newview/llvowlsky.h
+++ b/indra/newview/llvowlsky.h
@@ -50,9 +50,6 @@ private:
public:
LLVOWLSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
- void initSunDirection(LLVector3 const & sun_direction,
- LLVector3 const & sun_angular_velocity);
-
/*virtual*/ void idleUpdate(LLAgent &agent, const F64 &time);
/*virtual*/ BOOL isActive(void) const;
/*virtual*/ LLDrawable * createDrawable(LLPipeline *pipeline);
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 625f811789..f3e4291092 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -116,6 +116,8 @@
#include "llenvironment.h"
+#pragma optimize("", off)
+
#ifdef _DEBUG
// Debug indices is disabled for now for debug performance - djs 4/24/02
//#define DEBUG_INDICES
@@ -2145,7 +2147,7 @@ void check_references(LLSpatialGroup* group, LLFace* face)
void LLPipeline::checkReferences(LLFace* face)
{
-#if 0
+#if CHECK_PIPELINE_REFERENCES
if (sCull)
{
for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
@@ -2177,7 +2179,7 @@ void LLPipeline::checkReferences(LLFace* face)
void LLPipeline::checkReferences(LLDrawable* drawable)
{
-#if 0
+#if CHECK_PIPELINE_REFERENCES
if (sCull)
{
for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
@@ -2228,7 +2230,7 @@ void check_references(LLSpatialGroup* group, LLDrawInfo* draw_info)
void LLPipeline::checkReferences(LLDrawInfo* draw_info)
{
-#if 0
+#if CHECK_PIPELINE_REFERENCES
if (sCull)
{
for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
@@ -2254,7 +2256,7 @@ void LLPipeline::checkReferences(LLDrawInfo* draw_info)
void LLPipeline::checkReferences(LLSpatialGroup* group)
{
-#if 0
+#if CHECK_PIPELINE_REFERENCES
if (sCull)
{
for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
@@ -6018,8 +6020,9 @@ void LLPipeline::setupAvatarLights(bool for_edit)
}
else if (gAvatarBacklight) // Always true (unless overridden in a devs .ini)
{
- LLVector3 opposite_pos = -1.f * mSunDir;
- LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis;
+ LLVector3 sun_dir = LLVector3(mSunDir);
+ LLVector3 opposite_pos = -sun_dir;
+ LLVector3 orthog_light_pos = sun_dir % LLVector3::z_axis;
LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f);
backlight_pos.normalize();
@@ -6243,27 +6246,29 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
{
assertInitialized();
+ LLEnvironment& environment = LLEnvironment::instance();
+ LLSettingsSky::ptr_t psky = environment.getCurrentSky();
+
// Ambient
if (!LLGLSLShader::sNoFixedFunction)
{
gGL.syncMatrices();
- LLColor4 ambient = gSky.getTotalAmbientColor();
+ LLColor4 ambient = psky->getTotalAmbient();
gGL.setAmbientLightColor(ambient);
}
// Light 0 = Sun or Moon (All objects)
{
- LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+ LLVector4 light_dir = environment.getLightDirectionCFR();
+ mSunDir.setVec(light_dir);
- if (LLEnvironment::instance().getIsSunUp())
- {
- mSunDir.setVec(psky->getSunDirection());
- mSunDiffuse.setVec(gSky.getSunDiffuseColor());
+ if (environment.getIsSunUp())
+ {
+ mSunDiffuse.setVec(psky->getSunDiffuse());
}
else
{
- mSunDir.setVec(psky->getMoonDirection());
- mSunDiffuse.setVec(gSky.getMoonDiffuseColor());
+ mSunDiffuse.setVec(psky->getMoonDiffuse());
}
F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]);
@@ -6273,20 +6278,12 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
}
mSunDiffuse.clamp();
- LLVector4 light_pos(mSunDir, 0.0f);
LLColor4 light_diffuse = mSunDiffuse;
- if (LLPipeline::sRenderDeferred)
- {
- /*light_diffuse.mV[0] = powf(light_diffuse.mV[0], 2.2f);
- light_diffuse.mV[1] = powf(light_diffuse.mV[1], 2.2f);
- light_diffuse.mV[2] = powf(light_diffuse.mV[2], 2.2f);*/
- }
-
mHWLightColors[0] = light_diffuse;
LLLightState* light = gGL.getLight(0);
- light->setPosition(light_pos);
+ light->setPosition(mSunDir);
light->setDiffuse(light_diffuse);
light->setAmbient(LLColor4::black);
light->setSpecular(LLColor4::black);
@@ -6505,7 +6502,7 @@ void LLPipeline::enableLights(U32 mask)
mLightMask = mask;
stop_glerror();
- LLColor4 ambient = gSky.getTotalAmbientColor();
+ LLColor4 ambient = LLEnvironment::instance().getCurrentSky()->getTotalAmbient();
gGL.setAmbientLightColor(ambient);
}
}
@@ -8470,8 +8467,7 @@ void LLPipeline::renderDeferredLighting()
{
setupHWLights(NULL); //to set mSunDir;
- LLVector4 dir(mSunDir, 0.f);
- glh::vec4f tc(dir.mV);
+ glh::vec4f tc(mSunDir.mV);
mat.mult_matrix_vec(tc);
mTransformedSunDir.set(tc.v);
}
@@ -9084,8 +9080,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target)
{
setupHWLights(NULL); //to set mSunDir;
- LLVector4 dir(mSunDir, 0.f);
- glh::vec4f tc(dir.mV);
+ glh::vec4f tc(mSunDir.mV);
mat.mult_matrix_vec(tc);
mTransformedSunDir.set(tc.v);
}
@@ -10654,15 +10649,17 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
//LLVector3 n = RenderShadowNearDist;
//F32 nearDist[] = { n.mV[0], n.mV[1], n.mV[2], n.mV[2] };
+ LLVector3 sun_dir(mSunDir);
+
//put together a universal "near clip" plane for shadow frusta
LLPlane shadow_near_clip;
- {
+ {
LLVector3 p = gAgent.getPositionAgent();
- p += mSunDir * RenderFarClip*2.f;
- shadow_near_clip.setVec(p, mSunDir);
+ p += sun_dir * RenderFarClip*2.f;
+ shadow_near_clip.setVec(p, sun_dir);
}
- LLVector3 lightDir = -mSunDir;
+ LLVector3 lightDir = -sun_dir;
lightDir.normVec();
glh::vec3f light_dir(lightDir.mV);
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 75fed7dd39..d3fe5b4fdd 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -655,9 +655,9 @@ public:
U32 mTrueNoiseMap;
U32 mLightFunc;
- LLColor4 mSunDiffuse;
- LLVector3 mSunDir;
- LLVector3 mTransformedSunDir;
+ LLColor4 mSunDiffuse;
+ LLVector4 mSunDir;
+ LLVector4 mTransformedSunDir;
bool mInitialized;
bool mVertexShadersEnabled;