#1046 Tweak auto-exposure to not underexpose bright scenes (#1084)

master
RunitaiLinden 2024-03-28 14:06:11 -05:00 committed by GitHub
parent 74b2f5b2dd
commit 617436b7cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 2 deletions

View File

@ -10832,6 +10832,17 @@
<string>F32</string>
<key>Value</key>
<real>0.5</real>
</map>
<key>RenderDiffuseLuminanceScale</key>
<map>
<key>Comment</key>
<string>Luminance adjustment for diffuse surfaces to aid auto-exposure behavior</string>
<key>Persist</key>
<integer>0</integer>
<key>Type</key>
<string>F32</string>
<key>Value</key>
<real>0.5</real>
</map>
<key>RenderShaderLODThreshold</key>
<map>

View File

@ -34,6 +34,8 @@ in vec2 vary_fragcoord;
uniform sampler2D diffuseRect;
uniform sampler2D emissiveRect;
uniform sampler2D normalMap;
uniform float diffuse_luminance_scale;
float lum(vec3 col)
{
@ -45,7 +47,21 @@ void main()
{
vec2 tc = vary_fragcoord*0.6+0.2;
tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky
vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb;
vec3 c = texture(diffuseRect, tc).rgb;
vec4 norm = texture(normalMap, tc);
if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI) &&
!GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS))
{
// Apply the diffuse luminance scale to objects but not the sky
// Prevents underexposing when looking at bright environments
// while still allowing for realistically bright skies.
c *= diffuse_luminance_scale;
}
c += texture(emissiveRect, tc).rgb;
float L = lum(c);
frag_color = vec4(max(L, 0.0));
}

View File

@ -153,6 +153,15 @@ float noise(vec2 x) {
//=============================
void debugExposure(inout vec3 color)
{
float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r;
exp_scale *= 0.5;
if (abs(vary_fragcoord.y-exp_scale) < 0.01 && vary_fragcoord.x < 0.1)
{
color = vec3(1,0,0);
}
}
vec3 legacyGamma(vec3 color)
{
@ -181,7 +190,8 @@ void main()
vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y);
vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb));
diff.rgb += nz*0.003;
//debugExposure(diff.rgb);
frag_color = max(diff, vec4(0));
}

View File

@ -6759,6 +6759,8 @@ void LLPipeline::generateLuminance(LLRenderTarget* src, LLRenderTarget* dst)
gLuminanceProgram.bind();
static LLCachedControl<F32> diffuse_luminance_scale(gSavedSettings, "RenderDiffuseLuminanceScale", 1.0f);
S32 channel = 0;
channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE);
if (channel > -1)
@ -6772,6 +6774,16 @@ void LLPipeline::generateLuminance(LLRenderTarget* src, LLRenderTarget* dst)
mGlow[1].bindTexture(0, channel);
}
channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_NORMAL);
if (channel > -1)
{
// bind the normal map to get the environment mask
mRT->deferredScreen.bindTexture(2, channel, LLTexUnit::TFO_POINT);
}
static LLStaticHashedString diffuse_luminance_scale_s("diffuse_luminance_scale");
gLuminanceProgram.uniform1f(diffuse_luminance_scale_s, diffuse_luminance_scale);
mScreenTriangleVB->setBuffer();
mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
dst->flush();