diff options
| author | RunitaiLinden <davep@lindenlab.com> | 2023-04-05 16:48:34 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-05 16:48:34 -0500 | 
| commit | 5bf60f5d9e722f6210572fd92e79e9994abd2ec1 (patch) | |
| tree | 5fa1c538ff87e0e34af61e1edd2c60807bd2a446 | |
| parent | 1f79379bf215c5368337c64b4f72c7c9ef3e09c2 (diff) | |
SL-19538 Followup -- fix for dynamic exposure having large gaps in it… (#157)
* SL-19538 Followup -- fix for dynamic exposure having large gaps in its luminance sampling.
* SL-19538 Followup -- review feedback changes.
| -rw-r--r-- | indra/llrender/llrendertarget.cpp | 2 | ||||
| -rw-r--r-- | indra/newview/app_settings/settings.xml | 2 | ||||
| -rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl | 38 | ||||
| -rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl | 52 | ||||
| -rw-r--r-- | indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl | 4 | ||||
| -rw-r--r-- | indra/newview/llviewershadermgr.cpp | 14 | ||||
| -rw-r--r-- | indra/newview/llviewershadermgr.h | 1 | ||||
| -rw-r--r-- | indra/newview/pipeline.cpp | 53 | ||||
| -rw-r--r-- | indra/newview/pipeline.h | 1 | 
9 files changed, 117 insertions, 50 deletions
| diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 6dac614eea..7f507a0b58 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -483,7 +483,7 @@ U32 LLRenderTarget::getNumTextures() const  void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options)  { -    gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index)); +    gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index), filter_options == LLTexUnit::TFO_TRILINEAR || filter_options == LLTexUnit::TFO_ANISOTROPIC);      bool isSRGB = false;      llassert(mInternalFormat.size() > index); diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 063f4fcf96..44a86dd22a 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -10500,7 +10500,7 @@      <key>Type</key>      <string>F32</string>      <key>Value</key> -    <real>0.3</real> +    <real>0.175</real>    </map>      <key>RenderShaderLODThreshold</key>      <map> diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index 4c860cdde0..3eda2b9050 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -29,7 +29,6 @@  out vec4 frag_color; -uniform sampler2D diffuseRect;  uniform sampler2D emissiveRect;  uniform sampler2D exposureMap; @@ -46,45 +45,12 @@ float lum(vec3 col)  void main()   { -    float step = 1.0/16.0; +    vec2 tc = vec2(0.5,0.5); -    float start = step; -    float end = 1.0-step; - -    float w = 0.0; - -    vec3 col; - -    //vec2 nz = noiseVec * step * 0.5; - -    for (float x = start; x <= end; x += step) -    { -        for (float y = start; y <= end; y += step) -        { -            vec2 tc = vec2(x,y); // + nz; -            vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; -            float L = max(lum(c), 0.25); - -            float d = length(vec2(0.5)-tc); -            d = 1.0-d; -            d *= d; -            d *= d; -            d *= d; -            L *= d; - -            w += L; - -            col += c * L; -        } -    } - -    col /= w; - -    float L = lum(col); +    float L = textureLod(emissiveRect, tc, 8).r;      float s = clamp(dynamic_exposure_params.x/L, dynamic_exposure_params.y, dynamic_exposure_params.z); -      float prev = texture(exposureMap, vec2(0.5,0.5)).r;      s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl new file mode 100644 index 0000000000..e63e666778 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -0,0 +1,52 @@ +/**  + * @file luminanceF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ +  + +/*[EXTRA_CODE_HERE]*/ + +// take a luminance sample of diffuseRect and emissiveRect  + +out vec4 frag_color; + +in vec2 vary_fragcoord; + +uniform sampler2D diffuseRect; +uniform sampler2D emissiveRect; + +float lum(vec3 col) +{ +    vec3 l = vec3(0.2126, 0.7152, 0.0722); +    return dot(l, col); +} + +void main()  +{ +    vec2 tc = vary_fragcoord*0.6+0.2; +    vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; +    float L = lum(c); + +    frag_color = vec4(L); +} + diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl index 22e93496d2..49ff49fdd8 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsF.glsl @@ -36,7 +36,9 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)  {       light *= atten.r;      additive = srgb_to_linear(additive*2.0); -    additive *= sun_up_factor + 1.0; +    // magic 3.0 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something +    // so it's available to all shaders that call atmosFragLighting instead of just softenLightF.glsl +    additive *= sun_up_factor*3.0 + 1.0;       light += additive;      return light;  } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 8b402e210d..4c34c6f6e5 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -188,6 +188,7 @@ LLGLSLShader			gDeferredCoFProgram;  LLGLSLShader			gDeferredDoFCombineProgram;  LLGLSLShader			gDeferredPostGammaCorrectProgram;  LLGLSLShader			gExposureProgram; +LLGLSLShader			gLuminanceProgram;  LLGLSLShader			gFXAAProgram;  LLGLSLShader			gDeferredPostNoDoFProgram;  LLGLSLShader			gDeferredWLSkyProgram; @@ -1002,6 +1003,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()  		gDeferredCoFProgram.unload();		  		gDeferredDoFCombineProgram.unload();          gExposureProgram.unload(); +        gLuminanceProgram.unload();  		gDeferredPostGammaCorrectProgram.unload();  		gFXAAProgram.unload();  		gDeferredWLSkyProgram.unload(); @@ -2534,6 +2536,18 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()          llassert(success);      } +    if (success) +    { +        gLuminanceProgram.mName = "Luminance"; +        gLuminanceProgram.mShaderFiles.clear(); +        gLuminanceProgram.clearPermutations(); +        gLuminanceProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER)); +        gLuminanceProgram.mShaderFiles.push_back(make_pair("deferred/luminanceF.glsl", GL_FRAGMENT_SHADER)); +        gLuminanceProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED]; +        success = gLuminanceProgram.createShader(NULL, NULL); +        llassert(success); +    } +  	if (success)  	{  		gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 6fb2bc3fec..0a23c33b78 100644 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -236,6 +236,7 @@ extern LLGLSLShader			gFXAAProgram;  extern LLGLSLShader			gDeferredPostNoDoFProgram;  extern LLGLSLShader			gDeferredPostGammaCorrectProgram;  extern LLGLSLShader			gExposureProgram; +extern LLGLSLShader			gLuminanceProgram;  extern LLGLSLShader			gDeferredAvatarShadowProgram;  extern LLGLSLShader			gDeferredAvatarAlphaShadowProgram;  extern LLGLSLShader			gDeferredAvatarAlphaMaskShadowProgram; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 1222613c66..4ab6483c88 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1082,6 +1082,7 @@ void LLPipeline::releaseLUTBuffers()      mPbrBrdfLut.release();      mExposureMap.release(); +    mLuminanceMap.release();      mLastExposure.release();  } @@ -1266,6 +1267,8 @@ void LLPipeline::createLUTBuffers()      mExposureMap.clear();      mExposureMap.flush(); +    mLuminanceMap.allocate(256, 256, GL_R16F); +      mLastExposure.allocate(1, 1, GL_R16F);  } @@ -7262,6 +7265,43 @@ void LLPipeline::renderFinalize()              dst.flush();          } +        // luminance sample and mipmap generation +        { +            LL_PROFILE_GPU_ZONE("luminance sample"); + +            mLuminanceMap.bindTarget(); + +            LLGLDepthTest depth(GL_FALSE, GL_FALSE); + +            gLuminanceProgram.bind(); + + +            S32 channel = 0; +            channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE); +            if (channel > -1) +            { +                screenTarget()->bindTexture(0, channel, LLTexUnit::TFO_POINT); +            } + +            channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE); +            if (channel > -1) +            { +                mGlow[1].bindTexture(0, channel); +            } + + +            mScreenTriangleVB->setBuffer(); +            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3); +            mLuminanceMap.flush(); + +            mLuminanceMap.bindTexture(0, 0, LLTexUnit::TFO_TRILINEAR); +            glGenerateMipmap(GL_TEXTURE_2D); + +            // note -- unbind AFTER the glGenerateMipMap so time in generatemipmap can be profiled under "Luminance" +            // also note -- keep an eye on the performance of glGenerateMipmap, might need to replace it with a mip generation shader +            gLuminanceProgram.unbind(); +        } +          // exposure sample          {              LL_PROFILE_GPU_ZONE("exposure sample"); @@ -7278,25 +7318,16 @@ void LLPipeline::renderFinalize()                  mLastExposure.flush();              } -              mExposureMap.bindTarget();              LLGLDepthTest depth(GL_FALSE, GL_FALSE);              gExposureProgram.bind(); - -            S32 channel = 0; -            channel = gExposureProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE); -            if (channel > -1) -            { -                screenTarget()->bindTexture(0, channel, LLTexUnit::TFO_POINT); -            } - -            channel = gExposureProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE); +            S32 channel = gExposureProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);              if (channel > -1)              { -                mGlow[1].bindTexture(0, channel); +                mLuminanceMap.bindTexture(0, channel, LLTexUnit::TFO_TRILINEAR);              }              channel = gExposureProgram.enableTexture(LLShaderMgr::EXPOSURE_MAP); diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index eb30c85993..a231084e5c 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -678,6 +678,7 @@ public:      LLRenderTarget          mSceneMap;      // exposure map for getting average color in scene +    LLRenderTarget          mLuminanceMap;      LLRenderTarget          mExposureMap;      LLRenderTarget          mLastExposure; | 
