SL-12902 Fix for doing the technically correct but compatibility wrong thing WRT light color values.

master
Runitai Linden 2020-03-26 16:48:33 -05:00
parent 9e0cf3edaa
commit d756e18573
7 changed files with 69 additions and 26 deletions

View File

@ -537,9 +537,12 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
}
}
// This converts from a non-linear sRGB floating point value (0..1) to a linear value.
// Useful for gamma correction and such. Note: any values passed through this should not be serialized. You should also ideally cache the output of this.
inline float sRGBtoLinear(const float val) {
// Converts given value from a linear RGB floating point value (0..1) to a gamma corrected (sRGB) value.
// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space.
// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses
inline float linearTosRGB(const float val) {
if (val < 0.0031308f) {
return val * 12.92f;
}
@ -548,7 +551,13 @@ inline float sRGBtoLinear(const float val) {
}
}
inline float linearTosRGB(const float val) {
// Converts given value from a gamma corrected (sRGB) floating point value (0..1) to a linear color value.
// Some shaders require color values in linear space, while others require color values in gamma corrected (sRGB) space.
// Note: In our code, values labeled as sRGB are gamma corrected linear values, NOT linear values with monitor gamma applied
// Note: Stored color values should generally be gamma corrected sRGB.
// If you're serializing the return value of this function, you're probably doing it wrong.
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
inline float sRGBtoLinear(const float val) {
if (val < 0.04045f) {
return val / 12.92f;
}

View File

@ -484,4 +484,13 @@ inline const LLColor3 srgbColor3(const LLColor3 &a) {
return srgbColor;
}
inline const LLColor3 linearColor3(const LLColor3 &a) {
LLColor3 linearColor;
linearColor.mV[0] = sRGBtoLinear(a.mV[0]);
linearColor.mV[1] = sRGBtoLinear(a.mV[1]);
linearColor.mV[2] = sRGBtoLinear(a.mV[2]);
return linearColor;
}
#endif

View File

@ -656,6 +656,7 @@ void LLColor4::clamp()
}
}
// Return the given linear space color value in gamma corrected (sRGB) space
inline const LLColor4 srgbColor4(const LLColor4 &a) {
LLColor4 srgbColor;
@ -667,5 +668,15 @@ inline const LLColor4 srgbColor4(const LLColor4 &a) {
return srgbColor;
}
// Return the given gamma corrected (sRGB) color in linear space
inline const LLColor4 linearColor4(const LLColor4 &a)
{
LLColor4 linearColor;
linearColor.mV[0] = sRGBtoLinear(a.mV[0]);
linearColor.mV[1] = sRGBtoLinear(a.mV[1]);
linearColor.mV[2] = sRGBtoLinear(a.mV[2]);
linearColor.mV[3] = a.mV[3];
}
#endif

View File

@ -132,8 +132,7 @@ extern const F32 LIGHT_MAX_CUTOFF;
class LLLightParams : public LLNetworkData
{
protected:
LLColor4 mColor; // alpha = intensity
LLColor4 mSRGBColor; // Only used in deferred (for now?)
LLColor4 mColor; // gamma corrected color (sRGB), alpha = intensity
F32 mRadius;
F32 mFalloff;
F32 mCutoff;
@ -151,13 +150,20 @@ public:
bool fromLLSD(LLSD& sd);
void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); mSRGBColor = srgbColor4(mColor); }
// set the color
// color - gamma corrected color value (directly taken from an on-screen color swatch)
void setColor(const LLColor4& color) { mColor = color; mColor.clamp(); }
void setRadius(F32 radius) { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
void setFalloff(F32 falloff) { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
void setCutoff(F32 cutoff) { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
// same as getSRGBColor
LLColor4 getColor() const { return mColor; }
LLColor4 getSRGBColor() const { return mSRGBColor; }
// get the sRGB (gamma corrected) color of this light
LLColor4 getSRGBColor() const { return mColor; }
// get the linear space color of this light
LLColor4 getLinearColor() const { return linearColor4(mColor); }
F32 getRadius() const { return mRadius; }
F32 getFalloff() const { return mFalloff; }
F32 getCutoff() const { return mCutoff; }

View File

@ -3234,17 +3234,11 @@ LLColor3 LLVOVolume::getLightBaseColor() const
}
}
LLColor3 LLVOVolume::getLightColor() const
LLColor3 LLVOVolume::getLightLinearColor() const
{
const LLLightParams *param_block = (const LLLightParams *)getParameterEntry(LLNetworkData::PARAMS_LIGHT);
if (param_block)
{
return LLColor3(param_block->getColor()) * param_block->getColor().mV[3];
}
else
{
return LLColor3(1,1,1);
}
LLColor3 ret = getLightSRGBColor();
ret = linearColor3(ret);
return ret;
}
LLColor3 LLVOVolume::getLightSRGBColor() const

View File

@ -251,9 +251,20 @@ public:
void setSpotLightParams(LLVector3 params);
BOOL getIsLight() const;
LLColor3 getLightBaseColor() const; // not scaled by intensity
LLColor3 getLightColor() const; // scaled by intensity
LLColor3 getLightSRGBColor() const; // Used to get the (cached) light color in sRGB color space. Also scaled by intensity.
// Get the light color in sRGB color space NOT scaled by intensity.
LLColor3 getLightBaseColor() const;
//same as getLightSRGBColor()
LLColor3 getLightColor() const { return getLightSRGBColor(); }
// Same as linearColor3(getLightSRGBColor)
LLColor3 getLightLinearColor() const;
// Get the light color in sRGB color space scaled by intensity.
LLColor3 getLightSRGBColor() const;
LLUUID getLightTextureID() const;
bool isLightSpotlight() const;
LLVector3 getSpotLightParams() const;

View File

@ -6325,7 +6325,8 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
mLightMovingMask |= (1<<cur_light);
}
LLColor4 light_color = sRenderDeferred ? light->getLightSRGBColor() : light->getLightColor();
//NOTE: for legacy reasons, send sRGB color to light shader for both deferred and non-deferred path
LLColor4 light_color = light->getLightColor();
light_color.mV[3] = 0.0f;
F32 fade = iter->fade;
@ -8767,7 +8768,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
const F32* c = center.getF32ptr();
F32 s = volume->getLightRadius()*1.5f;
LLColor3 col = volume->getLightSRGBColor();
//NOTE: for legacy reasons, send sRGB color to light shader
LLColor3 col = volume->getLightColor();
if (col.magVecSquared() < 0.001f)
{
@ -8859,7 +8861,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
setupSpotLight(gDeferredSpotLightProgram, drawablep);
LLColor3 col = volume->getLightSRGBColor();
//NOTE: for legacy reasons, send sRGB color to light shader
LLColor3 col = volume->getLightColor();
gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
@ -8948,8 +8951,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target)
setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
LLColor3 col = volume->getLightSRGBColor();
//NOTE: for legacy reasons, send sRGB color to light shader
LLColor3 col = volume->getLightColor();
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);