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.
master
Graham Linden 2019-07-10 13:02:09 -07:00
parent 5e84b7af35
commit d23bf2c16e
7 changed files with 128 additions and 240 deletions

View File

@ -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;
}

View File

@ -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<std::string, S32> mapNameToUniformId_t;

View File

@ -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())

View File

@ -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 = psky->gammaCorrect(vars.hazeColor * 2.0f);
LLColor3 sky_color = calcSkyColorWLFrag(Pn, vars);
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));
temp2.mV[1] = 1.f / temp2.mV[1];
componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1]));
if (temp2.mV[1] > 0.0000001f)
{
temp2.mV[1] = 1.f / temp2.mV[1];
}
temp2.mV[1] = llmax(temp2.mV[1], 0.0000001f);
// Distance
componentMultBy(sunlight, componentExp((light_atten * -1.f) * temp2.mV[1]));
componentMultBy(sunlight, light_transmittance);
// 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));
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);
// 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]));
// Attenuate cloud color by atmosphere
temp1 = componentSqrt(temp1); //less atmos opacity (more transparency) below clouds
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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<LLViewerFetchedTexture> mSunTexturep[2];
LLPointer<LLViewerFetchedTexture> mMoonTexturep[2];