From 2513aa0ed1331ca022fb8bbd7442b1ba750ead4d Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 03:18:02 -0700 Subject: [PATCH 01/12] Additional gamma correction work: start moving over to EXT_texture_sRGB_decode. --- indra/llrender/llglslshader.cpp | 7 ++++--- indra/llrender/llglslshader.h | 4 ++-- indra/llrender/llimagegl.cpp | 4 ++-- indra/llrender/llrender.cpp | 14 ++++++++++++++ indra/llrender/llrender.h | 11 +++++++++++ indra/newview/pipeline.cpp | 11 ++++++----- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 8f3a56e1cf..f8b5dd0559 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -974,7 +974,7 @@ S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode) return uniform; } -S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { @@ -986,11 +986,12 @@ S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode) { gGL.getTexUnit(index)->activate(); gGL.getTexUnit(index)->enable(mode); + gGL.getTexUnit(index)->setTextureColorSpace(space); } return index; } -S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) +S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space) { if (uniform < 0 || uniform >= (S32)mTexture.size()) { @@ -1000,7 +1001,7 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode) S32 index = mTexture[uniform]; if (index != -1 && gGL.getTexUnit(index)->getCurrType() != LLTexUnit::TT_NONE) { - if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode) + if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode && gGL.getTexUnit(index)->getCurrColorSpace() != space) { if (gDebugSession) { diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index c1ce3d3aad..974d0ea005 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -153,8 +153,8 @@ public: //if given texture uniform is active in the shader, //the corresponding channel will be active upon return //returns channel texture is enabled in from [0-MAX) - S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); - S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE); + S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); + S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR); // bindTexture returns the texture unit we've bound the texture to. // You can reuse the return value to unbind a texture when required. diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 2d526a2113..8b51bf4b9f 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1385,12 +1385,12 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S mFormatType = GL_UNSIGNED_BYTE; break; case 3: - mFormatInternal = GL_RGB8; + mFormatInternal = GL_SRGB8; mFormatPrimary = GL_RGB; mFormatType = GL_UNSIGNED_BYTE; break; case 4: - mFormatInternal = GL_RGBA8; + mFormatInternal = GL_SRGB8_ALPHA8; mFormatPrimary = GL_RGBA; mFormatType = GL_UNSIGNED_BYTE; break; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 2bf7ad9902..53a30a63c4 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -838,6 +838,20 @@ void LLTexUnit::debugTextureUnit(void) } } +void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { + mTexColorSpace = space; + if (space == TCS_SRGB) { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); + } + else { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } + + if (gDebugGL) { + assert_glerror(); + } +} + LLLightState::LLLightState(S32 index) : mIndex(index), mEnabled(false), diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index ad9cd11283..2f15edc20e 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -131,6 +131,12 @@ public: TBS_ONE_MINUS_CONST_ALPHA } eTextureBlendSrc; + typedef enum + { + TCS_LINEAR = 0, + TCS_SRGB + } eTextureColorSpace; + LLTexUnit(S32 index); // Refreshes renderer state of the texture unit to the cached values @@ -198,6 +204,10 @@ public: void setHasMipMaps(bool hasMips) { mHasMipMaps = hasMips; } + void setTextureColorSpace(eTextureColorSpace space); + + eTextureColorSpace getCurrColorSpace() { return mTexColorSpace; } + protected: const S32 mIndex; U32 mCurrTexture; @@ -209,6 +219,7 @@ protected: eTextureBlendOp mCurrAlphaOp; eTextureBlendSrc mCurrAlphaSrc1; eTextureBlendSrc mCurrAlphaSrc2; + eTextureColorSpace mTexColorSpace; S32 mCurrColorScale; S32 mCurrAlphaScale; bool mHasMipMaps; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index f84cd594c9..b9a917cfb4 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8779,7 +8779,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); for (LLDrawable::drawable_list_t::iterator iter = spot_lights.begin(); iter != spot_lights.end(); ++iter) { @@ -8807,7 +8807,8 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); } - gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); + unbindDeferredShader(gDeferredSpotLightProgram); } @@ -8863,7 +8864,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) bindDeferredShader(gDeferredMultiSpotLightProgram); - gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); @@ -8894,7 +8895,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); } - gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); unbindDeferredShader(gDeferredMultiSpotLightProgram); gGL.popMatrix(); @@ -9139,7 +9140,7 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) img = LLViewerFetchedTexture::sWhiteImagep; } - S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); if (channel > -1) { From a158c879578822a116e3f6a8c5dbbd1a14bb8c83 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 17:22:54 -0700 Subject: [PATCH 02/12] Hide sRGB decode behind a flag, and make sure that sRGB decodes is strictly opt-in. --- indra/llrender/llgl.cpp | 6 +++ indra/llrender/llgl.h | 1 + indra/llrender/llrender.cpp | 41 ++++++++++++------- indra/llrender/llrender.h | 2 +- .../class1/deferred/multiSpotLightF.glsl | 3 -- .../class2/deferred/multiSpotLightF.glsl | 2 - indra/newview/pipeline.cpp | 5 +-- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 54a41c9d23..d18512f613 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -999,6 +999,12 @@ void LLGLManager::initExtensions() mHassRGBFramebuffer = ExtensionExists("GL_EXT_framebuffer_sRGB", gGLHExts.mSysExts); #endif +#ifdef GL_EXT_texture_sRGB_decode + mHasTexturesRGBDecode = ExtensionExists("GL_EXT_texture_sRGB_decode", gGLHExts.mSysExts); +#else + mHasTexturesRGBDecode = ExtensionExists("GL_ARB_texture_sRGB_decode", gGLHExts.mSysExts); +#endif + mHasMipMapGeneration = mHasFramebufferObject || mGLVersion >= 1.4f; mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 362fda5fb1..a7faea7d33 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -118,6 +118,7 @@ public: BOOL mHasDebugOutput; BOOL mHassRGBTexture; BOOL mHassRGBFramebuffer; + BOOL mHasTexturesRGBDecode; // Vendor-specific extensions BOOL mIsATI; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 53a30a63c4..5dc61d0e8f 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -105,7 +105,7 @@ LLTexUnit::LLTexUnit(S32 index) mCurrColorOp(TBO_MULT), mCurrAlphaOp(TBO_MULT), mCurrColorSrc1(TBS_TEX_COLOR), mCurrColorSrc2(TBS_PREV_COLOR), mCurrAlphaSrc1(TBS_TEX_ALPHA), mCurrAlphaSrc2(TBS_PREV_ALPHA), - mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), + mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), mTexColorSpace(TCS_LINEAR), mHasMipMaps(false), mIndex(index) { @@ -162,6 +162,8 @@ void LLTexUnit::refreshState(void) setTextureCombiner(mCurrColorOp, mCurrColorSrc1, mCurrColorSrc2, false); setTextureCombiner(mCurrAlphaOp, mCurrAlphaSrc1, mCurrAlphaSrc2, true); } + + setTextureColorSpace(mTexColorSpace); } void LLTexUnit::activate(void) @@ -191,7 +193,6 @@ void LLTexUnit::enable(eTextureType type) stop_glerror(); } mCurrTexType = type; - gGL.flush(); if (!LLGLSLShader::sNoFixedFunction && type != LLTexUnit::TT_MULTISAMPLE_TEXTURE && @@ -219,6 +220,8 @@ void LLTexUnit::disable(void) { glDisable(sGLTextureType[mCurrTexType]); } + + setTextureColorSpace(TCS_LINEAR); mCurrTexType = TT_NONE; } @@ -255,7 +258,8 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) gl_tex->mTexOptionsDirty = false; setTextureAddressMode(gl_tex->mAddressMode); setTextureFilteringOption(gl_tex->mFilterOption); - } + } + setTextureColorSpace(mTexColorSpace); } } else @@ -330,6 +334,7 @@ bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind) setTextureFilteringOption(texture->mFilterOption); stop_glerror(); } + setTextureColorSpace(mTexColorSpace); } stop_glerror(); @@ -355,7 +360,7 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap) { activate(); enable(LLTexUnit::TT_CUBE_MAP); - mCurrTexture = cubeMap->mImages[0]->getTexName(); + mCurrTexture = cubeMap->mImages[0]->getTexName(); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mCurrTexture); mHasMipMaps = cubeMap->mImages[0]->mHasMipMaps; cubeMap->mImages[0]->updateBindStats(cubeMap->mImages[0]->mTextureMemory); @@ -364,7 +369,8 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap) cubeMap->mImages[0]->mTexOptionsDirty = false; setTextureAddressMode(cubeMap->mImages[0]->mAddressMode); setTextureFilteringOption(cubeMap->mImages[0]->mFilterOption); - } + } + setTextureColorSpace(mTexColorSpace); return true; } else @@ -415,7 +421,8 @@ bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips) enable(type); mCurrTexture = texture; glBindTexture(sGLTextureType[type], texture); - mHasMipMaps = hasMips; + mHasMipMaps = hasMips; + setTextureColorSpace(mTexColorSpace); } return true; } @@ -435,6 +442,9 @@ void LLTexUnit::unbind(eTextureType type) if (mCurrTexType == type) { mCurrTexture = 0; + + // Always make sure our texture color space is reset to linear. SRGB sampling should be opt-in in the vast majority of cases. Also prevents color space "popping". + mTexColorSpace = TCS_LINEAR; if (LLGLSLShader::sNoFixedFunction && type == LLTexUnit::TT_TEXTURE) { glBindTexture(sGLTextureType[type], sWhiteTexture); @@ -840,15 +850,18 @@ void LLTexUnit::debugTextureUnit(void) void LLTexUnit::setTextureColorSpace(eTextureColorSpace space) { mTexColorSpace = space; - if (space == TCS_SRGB) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); - } - else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); - } + if (gGLManager.mHasTexturesRGBDecode) { - if (gDebugGL) { - assert_glerror(); + if (space == TCS_SRGB) { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); + } + else { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); + } + + if (gDebugGL) { + assert_glerror(); + } } } diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 2f15edc20e..41f4fe4017 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -159,7 +159,7 @@ public: // Binds the LLImageGL to this texture unit // (automatically enables the unit for the LLImageGL's texture type) bool bind(LLImageGL* texture, bool for_rendering = false, bool forceBind = false); - bool bind(LLTexture* texture, bool for_rendering = false, bool forceBind = false); + bool bind(LLTexture* texture, bool for_rendering = false, bool forceBind = false); // Binds a cubemap to this texture unit // (automatically enables the texture unit for cubemaps) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 57916eb3e5..6489508c00 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -78,7 +78,6 @@ vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -98,7 +97,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -116,7 +114,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 9e14c03a96..ab380f70e8 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -83,7 +83,6 @@ vec4 correctWithGamma(vec4 col) vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -103,7 +102,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index b9a917cfb4..df6383e88b 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8281,7 +8281,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ stop_glerror(); - channel = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP); + channel = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP, LLTexUnit::TCS_SRGB); if (channel > -1) { LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL; @@ -8808,7 +8808,6 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); } gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION, LLTexUnit::TT_TEXTURE, LLTexUnit::TCS_SRGB); - unbindDeferredShader(gDeferredSpotLightProgram); } @@ -9192,7 +9191,7 @@ void LLPipeline::unbindDeferredShader(LLGLSLShader &shader) shader.disableTexture(LLShaderMgr::DEFERRED_NOISE); shader.disableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC); - S32 channel = shader.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP); + S32 channel = shader.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP, LLTexUnit::TCS_SRGB); if (channel > -1) { LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL; From 9d03722479a282592f3c339bdc267bfb84c78137 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 30 Mar 2019 17:47:08 -0700 Subject: [PATCH 03/12] Make sure the specular and diffuse buffers are being sampled in sRGB space. --- indra/newview/pipeline.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index df6383e88b..313edca345 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8145,6 +8145,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ { deferred_target->bindTexture(0,channel); gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + gGL.getTexUnit(channel)->setTextureColorSpace(LLTexUnit::TCS_SRGB); } channel = shader.enableTexture(LLShaderMgr::DEFERRED_SPECULAR, deferred_target->getUsage()); @@ -8152,6 +8153,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ { deferred_target->bindTexture(1, channel); gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + gGL.getTexUnit(channel)->setTextureColorSpace(LLTexUnit::TCS_SRGB); } channel = shader.enableTexture(LLShaderMgr::DEFERRED_NORMAL, deferred_target->getUsage()); @@ -8159,6 +8161,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ { deferred_target->bindTexture(2, channel); gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + gGL.getTexUnit(channel)->setTextureColorSpace(LLTexUnit::TCS_LINEAR); } channel = shader.enableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_depth_target->getUsage()); From 233f3310aaf790b4cf12bcb9f42dd193467d25f3 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 12:12:33 -0700 Subject: [PATCH 04/12] Whoops, forgot a shader! --- .../app_settings/shaders/class2/deferred/spotLightF.glsl | 3 --- 1 file changed, 3 deletions(-) diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 93b55ab9c1..a9482ea54c 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -82,7 +82,6 @@ vec4 correctWithGamma(vec4 col) vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -102,7 +101,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -120,7 +118,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); From 0e47ca896d701eeb3c38a3bcb188bcceacaba80b Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 18:34:56 -0700 Subject: [PATCH 05/12] Make LLImageGL's loading of assets as sRGB or linear conditional based upon sRGB decode support. --- indra/llrender/llimagegl.cpp | 65 +++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 8b51bf4b9f..16fd6ffe8a 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1370,33 +1370,44 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S if( !mHasExplicitFormat ) { - switch (mComponents) - { - case 1: - // Use luminance alpha (for fonts) - mFormatInternal = GL_LUMINANCE8; - mFormatPrimary = GL_LUMINANCE; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 2: - // Use luminance alpha (for fonts) - mFormatInternal = GL_LUMINANCE8_ALPHA8; - mFormatPrimary = GL_LUMINANCE_ALPHA; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 3: - mFormatInternal = GL_SRGB8; - mFormatPrimary = GL_RGB; - mFormatType = GL_UNSIGNED_BYTE; - break; - case 4: - mFormatInternal = GL_SRGB8_ALPHA8; - mFormatPrimary = GL_RGBA; - mFormatType = GL_UNSIGNED_BYTE; - break; - default: - LL_ERRS() << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL; - } + switch (mComponents) + { + case 1: + // Use luminance alpha (for fonts) + mFormatInternal = GL_LUMINANCE8; + mFormatPrimary = GL_LUMINANCE; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 2: + // Use luminance alpha (for fonts) + mFormatInternal = GL_LUMINANCE8_ALPHA8; + mFormatPrimary = GL_LUMINANCE_ALPHA; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 3: + if (gGLManager.mHasTexturesRGBDecode) + { + mFormatInternal = GL_SRGB8; + } + else { + mFormatInternal = GL_RGB8; + } + mFormatPrimary = GL_RGB; + mFormatType = GL_UNSIGNED_BYTE; + break; + case 4: + if (gGLManager.mHasTexturesRGBDecode) + { + mFormatInternal = GL_SRGB8_ALPHA8; + } + else { + mFormatInternal = GL_RGBA8; + } + mFormatType = GL_UNSIGNED_BYTE; + break; + default: + LL_ERRS() << "Bad number of components for texture: " << (U32)getComponents() << LL_ENDL; + } calcAlphaChannelOffsetAndStride() ; } From 3a42d2b94a0f2d27b4baef63abaf49e64139ff01 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 18:51:28 -0700 Subject: [PATCH 06/12] Whoops! Always make sure that our primary format is assigned. --- indra/llrender/llimagegl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 16fd6ffe8a..2f1f702d2c 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1403,6 +1403,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S else { mFormatInternal = GL_RGBA8; } + mFormatPrimary = GL_RGBA; mFormatType = GL_UNSIGNED_BYTE; break; default: From 558eaef3ea09ff560c1fead65f1d1b3b75b4bdc5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 23:09:43 -0700 Subject: [PATCH 07/12] Make sure that atmospheric calcs aren't done twice. The atomospherics were being applied both in the G-buffer and during the sun light pass. This ensures that is not the case. Additionally, re-enable specular on the water plane, scale the bloom factor to something more reasonable, and also someone broke specular on emissive surfaces. That's fixed too now. --- .../shaders/class1/deferred/softenLightF.glsl | 4 ++-- .../app_settings/shaders/class1/deferred/waterF.glsl | 11 ++++------- .../shaders/class2/deferred/softenLightF.glsl | 8 +++----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a39a73f1b6..a04a24955e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -130,11 +130,11 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + bloom = dot(spec_contrib, spec_contrib) / 32; col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); + col.rgb += diffuse.a * diffuse.rgb; if (envIntensity > 0.0) { //add environmentmap diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index be5e3538a7..9a8a098a19 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,21 +153,18 @@ void main() vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); vec4 fb = texture2D(screenTex, distort2); - //mix with reflection // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); vec4 pos = vary_position; - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClipFrag(color.rgb); + //color.rgb = atmosTransport(color.rgb); + //color.rgb = scaleSoftClipFrag(color.rgb) * 0; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); frag_data[0] = vec4(color.rgb, 1); // diffuse - frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 + frag_data[1] = vec4(specular, 0.75); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 27532ce458..39776f1791 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -142,11 +142,11 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; + bloom = dot(spec_contrib, spec_contrib) / 64; col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); + col.rgb += diffuse.a * diffuse.rgb; if (envIntensity > 0.0) { //add environmentmap @@ -154,9 +154,7 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; col = mix(col.rgb, refcol, envIntensity); } - - -vec3 a = col.rgb; + if (norm.w < 0.5) { col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); From 6b54c48dff9a38a0a1410ed9bcd06d2667320df3 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2019 23:25:48 -0700 Subject: [PATCH 08/12] Scale the specular contribution to account for brighter highlights. This is more or less to achieve the non-ALM bloom behavior in most circumstances. Why scale it? Normalized blinn-phong gets brighter the higher the specular exponent. As it stood, the old spec contribution was extremely bright despite looking "correct". This is largely eyeballed, but generally looks better for all light sources applied to the surface of the water. --- .../shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class1/deferred/waterF.glsl | 10 ++-------- .../shaders/class2/deferred/softenLightF.glsl | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a04a24955e..cbeab3fc72 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -130,7 +130,7 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 32; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 9a8a098a19..c3c8683f6b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -142,13 +142,7 @@ void main() vec4 baseCol = texture2D(refTex, refvec4); refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - + //figure out distortion vector (ripply) vec2 distort2 = distort+wavef.xy*refScale * 0.33/max(dmod*df1, 1.0); @@ -165,6 +159,6 @@ void main() vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); frag_data[0] = vec4(color.rgb, 1); // diffuse - frag_data[1] = vec4(specular, 0.75); // speccolor, spec + frag_data[1] = vec4(specular * 0.4, 0.75); // speccolor, spec frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 39776f1791..47fc20e256 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -142,7 +142,7 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 64; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; } From f07a1741e91fe44423d27585e4eeb7b69542e299 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 2 Apr 2019 01:28:57 -0700 Subject: [PATCH 09/12] Make sure emissive is actually handled with atmospherics consistently. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 6 ++++-- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index cbeab3fc72..2df55f6cfc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -145,8 +145,10 @@ void main() if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); } #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 47fc20e256..28248aaf6d 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -157,8 +157,10 @@ void main() if (norm.w < 0.5) { - col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); - col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + //col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); + //col = mix(scaleSoftClipFrag(col), fullbrightScaleSoftClipFrag(col, additive, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); + col = scaleSoftClipFrag(col); } #ifdef WATER_FOG From 5be000f566021650ca83bcdb279b50fbdcc06fde Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 08:47:03 -0700 Subject: [PATCH 10/12] Fix mismerge of autobuild leading to MD5 sum check fail for M64 build. --- autobuild.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autobuild.xml b/autobuild.xml index d95e2952d0..86676ce71b 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -2670,7 +2670,7 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors archive hash - 2cbec24a9c0a6f63fb7de8714d844dc2 + f7013e1f0b6a877090622fd73ec72cbc url http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/1114/2576/openjpeg-1.5.1.501102-darwin64-501102.tar.bz2 From f3d04dfa1ed30fb7e85f53a9cc9f877e6902e1fc Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 09:28:42 -0700 Subject: [PATCH 11/12] Roll back KDU to 7.a.4 version instead of updating to 7.a.7 --- autobuild.xml | 22 +++++++++++----------- indra/newview/llviewershadermgr.cpp | 4 ++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/autobuild.xml b/autobuild.xml index 86676ce71b..62542be8d8 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -1700,9 +1700,9 @@ archive hash - c90551bee423e9b494a46f29403f7f4a + d1521becaf21bf7233173722af63f57d url - http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/34357/286135/kdu-7.10.7.525514-darwin64-525514.tar.bz2 + http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/15257/98440/kdu-7.10.4.513518-darwin64-513518.tar.bz2 name darwin64 @@ -1712,9 +1712,9 @@ archive hash - 4fcb1fa70d8317f69284be3830df3a29 + 43d7a6a69a54534a736f132e9c81795b url - http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/34358/286148/kdu-7.10.7.525514-linux-525514.tar.bz2 + http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/15255/98451/kdu-7.10.4.513518-linux-513518.tar.bz2 name linux @@ -1724,9 +1724,9 @@ archive hash - 09cd4cdd385448b9c55fad2ced7685e2 + a705a665810a71e7b0114a97ae9a2224 url - http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/34356/286142/kdu-7.10.7.525514-linux64-525514.tar.bz2 + http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/15256/98457/kdu-7.10.4.513518-linux64-513518.tar.bz2 name linux64 @@ -1736,9 +1736,9 @@ archive hash - 4da8daa8c254be1eb2e4a942e42cd61c + 0e5b37a03a3f873d15142473b193ec5f url - http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/34360/286161/kdu-7.10.7.525514-windows-525514.tar.bz2 + http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/15259/98463/kdu-7.10.4.513518-windows-513518.tar.bz2 name windows @@ -1748,16 +1748,16 @@ archive hash - eea37ff2c006dc9542bbaa1bb6799417 + da3b1ea90797b189d80ab5d50fdf05d4 url - http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/34359/286155/kdu-7.10.7.525514-windows64-525514.tar.bz2 + http://s3-proxy.lindenlab.com/private-builds-secondlife-com/ct2/15260/98469/kdu-7.10.4.513518-windows64-513518.tar.bz2 name windows64 version - 7.A.7.525512 + 7.A.4.513518 libhunspell diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 5f35f71742..b4d378ffd1 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -49,6 +49,10 @@ #include "lljoint.h" #include "llskinningutil.h" +#if LL_WINDOWS +#pragma optimize("", off) +#endif + static LLStaticHashedString sTexture0("texture0"); static LLStaticHashedString sTexture1("texture1"); static LLStaticHashedString sTex0("tex0"); From 1199d139810f49de6052ceb90b4359042eb9a639 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Apr 2019 09:30:56 -0700 Subject: [PATCH 12/12] Remove pragma for turning off optimization for debugging. --- indra/newview/llviewershadermgr.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index b4d378ffd1..5f35f71742 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -49,10 +49,6 @@ #include "lljoint.h" #include "llskinningutil.h" -#if LL_WINDOWS -#pragma optimize("", off) -#endif - static LLStaticHashedString sTexture0("texture0"); static LLStaticHashedString sTexture1("texture1"); static LLStaticHashedString sTex0("tex0");