Skip to content

Commit 91b3779

Browse files
author
Rye
committed
Fix RenderHDR toggle rendering incorrectly
1 parent 126659e commit 91b3779

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

indra/newview/llviewershadermgr.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ LLGLSLShader gDeferredPostProgram;
196196
LLGLSLShader gDeferredCoFProgram;
197197
LLGLSLShader gDeferredDoFCombineProgram;
198198
LLGLSLShader gDeferredPostTonemapProgram;
199+
LLGLSLShader gDeferredPostTonemapGammaCorrectProgram;
199200
LLGLSLShader gNoPostTonemapProgram;
200201
LLGLSLShader gDeferredPostGammaCorrectProgram;
201202
LLGLSLShader gLegacyPostGammaCorrectProgram;
202-
LLGLSLShader gNoPostGammaCorrectProgram;
203203
LLGLSLShader gExposureProgram;
204204
LLGLSLShader gExposureProgramNoFade;
205205
LLGLSLShader gLuminanceProgram;
@@ -2331,7 +2331,6 @@ bool LLViewerShaderMgr::loadShadersDeferred()
23312331
gDeferredPostGammaCorrectProgram.mFeatures.isDeferred = true;
23322332
gDeferredPostGammaCorrectProgram.mShaderFiles.clear();
23332333
gDeferredPostGammaCorrectProgram.clearPermutations();
2334-
gDeferredPostGammaCorrectProgram.addPermutation("TONEMAP", "1");
23352334
gDeferredPostGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
23362335
gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
23372336
gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
@@ -2356,21 +2355,6 @@ bool LLViewerShaderMgr::loadShadersDeferred()
23562355
llassert(success);
23572356
}
23582357

2359-
if (success)
2360-
{
2361-
gNoPostGammaCorrectProgram.mName = "No Post Gamma Correction Post Process";
2362-
gNoPostGammaCorrectProgram.mFeatures.hasSrgb = true;
2363-
gNoPostGammaCorrectProgram.mFeatures.isDeferred = true;
2364-
gNoPostGammaCorrectProgram.mShaderFiles.clear();
2365-
gNoPostGammaCorrectProgram.clearPermutations();
2366-
gNoPostGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
2367-
gNoPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
2368-
gNoPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
2369-
gNoPostGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
2370-
success = gNoPostGammaCorrectProgram.createShader();
2371-
llassert(success);
2372-
}
2373-
23742358
if (success)
23752359
{
23762360
gDeferredPostTonemapProgram.mName = "Deferred Tonemap Post Process";
@@ -2385,6 +2369,21 @@ bool LLViewerShaderMgr::loadShadersDeferred()
23852369
success = gDeferredPostTonemapProgram.createShader();
23862370
llassert(success);
23872371
}
2372+
if (success)
2373+
{
2374+
gDeferredPostTonemapGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process";
2375+
gDeferredPostTonemapGammaCorrectProgram.mFeatures.hasSrgb = true;
2376+
gDeferredPostTonemapGammaCorrectProgram.mFeatures.isDeferred = true;
2377+
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.clear();
2378+
gDeferredPostTonemapGammaCorrectProgram.clearPermutations();
2379+
gDeferredPostTonemapGammaCorrectProgram.addPermutation("TONEMAP", "1");
2380+
gDeferredPostTonemapGammaCorrectProgram.addPermutation("GAMMA_CORRECT", "1");
2381+
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
2382+
gDeferredPostTonemapGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredTonemap.glsl", GL_FRAGMENT_SHADER));
2383+
gDeferredPostTonemapGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
2384+
success = gDeferredPostTonemapGammaCorrectProgram.createShader();
2385+
llassert(success);
2386+
}
23882387

23892388
if (success)
23902389
{

indra/newview/llviewershadermgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ extern LLGLSLShader gCASLegacyGammaProgram;
257257
extern LLGLSLShader gDeferredPostNoDoFProgram;
258258
extern LLGLSLShader gDeferredPostGammaCorrectProgram;
259259
extern LLGLSLShader gLegacyPostGammaCorrectProgram;
260-
extern LLGLSLShader gNoPostGammaCorrectProgram;
261260
extern LLGLSLShader gDeferredPostTonemapProgram;
261+
extern LLGLSLShader gDeferredPostTonemapGammaCorrectProgram;
262262
extern LLGLSLShader gNoPostTonemapProgram;
263263
extern LLGLSLShader gExposureProgram;
264264
extern LLGLSLShader gExposureProgramNoFade;

indra/newview/pipeline.cpp

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7102,9 +7102,9 @@ void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst, bool gamma_co
71027102
LLGLSLShader* shader = nullptr;
71037103
if (gamma_correct)
71047104
{
7105-
shader = no_post ? &gNoPostGammaCorrectProgram : // no post (no gamma, no exposure, no tonemapping)
7105+
shader = no_post ? &gDeferredPostGammaCorrectProgram : // no post (no legacy gamma adjustment, no exposure, no tonemapping, still srgb corrected)
71067106
psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gLegacyPostGammaCorrectProgram :
7107-
&gDeferredPostGammaCorrectProgram;
7107+
&gDeferredPostTonemapGammaCorrectProgram;
71087108
}
71097109
else
71107110
{
@@ -7145,6 +7145,34 @@ void LLPipeline::tonemap(LLRenderTarget* src, LLRenderTarget* dst, bool gamma_co
71457145
}
71467146
}
71477147

7148+
void LLPipeline::gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst)
7149+
{
7150+
LL_PROFILE_GPU_ZONE("gamma correct");
7151+
dst->bindTarget();
7152+
// gamma correct lighting
7153+
{
7154+
LLGLDepthTest depth(GL_FALSE, GL_FALSE);
7155+
7156+
static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
7157+
static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
7158+
7159+
bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
7160+
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
7161+
LLGLSLShader& shader = psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f && !no_post ? gLegacyPostGammaCorrectProgram :
7162+
gDeferredPostGammaCorrectProgram;
7163+
7164+
shader.bind();
7165+
shader.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
7166+
shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, (GLfloat)src->getWidth(), (GLfloat)src->getHeight());
7167+
7168+
mScreenTriangleVB->setBuffer();
7169+
mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
7170+
7171+
shader.unbind();
7172+
}
7173+
dst->flush();
7174+
}
7175+
71487176
void LLPipeline::copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst)
71497177
{
71507178
if (RenderScreenSpaceReflections && !gCubeSnapshot)
@@ -7285,11 +7313,13 @@ void LLPipeline::applyCAS(LLRenderTarget* src, LLRenderTarget* dst)
72857313
{
72867314
static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderCASSharpness", 0.4f);
72877315
static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
7316+
static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
72887317

72897318
LL_PROFILE_GPU_ZONE("cas");
72907319

7320+
bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
72917321
LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
7292-
LLGLSLShader* sharpen_shader = psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gCASLegacyGammaProgram : &gCASProgram;
7322+
LLGLSLShader* sharpen_shader = psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f && !no_post ? &gCASLegacyGammaProgram : &gCASProgram;
72937323

72947324
// Bind setup:
72957325
dst->bindTarget();
@@ -7847,12 +7877,8 @@ void LLPipeline::renderFinalize()
78477877
gGL.setColorMask(true, true);
78487878
glClearColor(0, 0, 0, 0);
78497879

7850-
LLRenderTarget* src = &mPostPingMap;
7851-
LLRenderTarget* dest = &mPostPongMap;
7852-
78537880
static LLCachedControl<bool> render_hdr(gSavedSettings, "RenderHDREnabled", true);
78547881
bool hdr = gGLManager.mGLVersion > 4.05f && render_hdr;
7855-
78567882
if (hdr)
78577883
{
78587884
copyScreenSpaceReflections(&mRT->screen, &mSceneMap);
@@ -7866,16 +7892,21 @@ void LLPipeline::renderFinalize()
78667892
{
78677893
tonemap(&mRT->screen, &mRT->deferredLight, false); // Must output to 16F buffer when passing to CAS or banding occurs
78687894

7869-
applyCAS(&mRT->deferredLight, dest); // Gamma corrects after sharpening
7870-
std::swap(src, dest);
7895+
applyCAS(&mRT->deferredLight, &mPostPingMap); // Gamma corrects after sharpening
78717896
}
78727897
else
78737898
{
7874-
tonemap(&mRT->screen, dest);
7875-
std::swap(src, dest);
7899+
tonemap(&mRT->screen, &mPostPingMap);
7900+
}
78767901
}
7902+
else
7903+
{
7904+
gammaCorrect(&mRT->screen, &mPostPingMap);
78777905
}
78787906

7907+
LLRenderTarget* src = &mPostPingMap;
7908+
LLRenderTarget* dest = &mPostPongMap;
7909+
78797910
LLVertexBuffer::unbind();
78807911

78817912
generateGlow(src);

indra/newview/pipeline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class LLPipeline
156156
void generateLuminance(LLRenderTarget* src, LLRenderTarget* dst);
157157
void generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history = true);
158158
void tonemap(LLRenderTarget* src, LLRenderTarget* dst, bool gamma_correct = true);
159+
void gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst);
159160
void generateGlow(LLRenderTarget* src);
160161
void applyCAS(LLRenderTarget* src, LLRenderTarget* dst);
161162
void applyFXAA(LLRenderTarget* src, LLRenderTarget* dst, bool combine_glow);

0 commit comments

Comments
 (0)