Skip to content

Commit 687930d

Browse files
author
Rye
committed
Integrate glow combine pass with other post process render passes to reduce another full screen copy
1 parent a57d82b commit 687930d

File tree

12 files changed

+171
-113
lines changed

12 files changed

+171
-113
lines changed

indra/newview/app_settings/shaders/class1/deferred/SMAANeighborhoodBlendF.glsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ in vec2 vary_texcoord0;
3131
in vec4 vary_offset;
3232

3333
uniform sampler2D diffuseRect;
34+
uniform sampler2D emissiveRect;
3435
uniform sampler2D blendTex;
3536
#if SMAA_REPROJECTION
3637
uniform sampler2D velocityTex;
3738
#endif
39+
uniform sampler2D depthMap;
3840

3941
#define float4 vec4
4042
#define float2 vec2
@@ -51,13 +53,19 @@ float4 SMAANeighborhoodBlendingPS(float2 texcoord,
5153

5254
void main()
5355
{
54-
frag_color = SMAANeighborhoodBlendingPS(vary_texcoord0,
56+
vec4 diff = SMAANeighborhoodBlendingPS(vary_texcoord0,
5557
vary_offset,
5658
diffuseRect,
5759
blendTex
5860
#if SMAA_REPROJECTION
5961
, velocityTex
6062
#endif
6163
);
64+
#ifndef NO_GLOW
65+
diff.rgb += texture2D(emissiveRect, vary_texcoord0).rgb;
66+
#endif
67+
frag_color = diff;
68+
69+
gl_FragDepth = texture(depthMap, vary_texcoord0.xy).r;
6270
}
6371

indra/newview/app_settings/shaders/class1/deferred/cofF.glsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ out vec4 frag_color;
2929

3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D depthMap;
32+
uniform sampler2D emissiveRect;
3233

3334
uniform float focal_distance;
3435
uniform float blur_constant;
@@ -66,12 +67,13 @@ void main()
6667
vec4 p = inv_proj*ndc;
6768
float depth = p.z/p.w;
6869

69-
vec4 diff = texture(diffuseRect, vary_fragcoord.xy);
70+
vec4 diff = texture(diffuseRect, tc);
7071

7172
float sc = calc_cof(depth);
7273
sc = min(sc, max_cof);
7374
sc = max(sc, -max_cof);
7475

75-
frag_color.rgb = diff.rgb;
76+
vec4 bloom = texture2D(emissiveRect, tc);
77+
frag_color.rgb = diff.rgb + bloom.rgb;
7678
frag_color.a = sc/max_cof*0.5+0.5;
7779
}

indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ out vec4 frag_color;
3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D depthMap;
3232

33-
uniform vec2 screen_res;
3433
in vec2 vary_fragcoord;
3534

3635
void main()

indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ out vec4 frag_color;
2929

3030
uniform sampler2D diffuseRect;
3131
uniform sampler2D emissiveRect;
32+
uniform sampler2D depthMap;
3233

3334
in vec2 tc;
3435

3536
void main()
3637
{
3738
frag_color = texture(diffuseRect, tc) + texture(emissiveRect, tc);
39+
gl_FragDepth = texture(depthMap, tc.xy).r;
3840
}

indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAF.glsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
out vec4 frag_color;
2929

3030
uniform sampler2D diffuseRect;
31+
uniform sampler2D emissiveRect;
3132

3233
uniform vec2 screen_res;
3334

@@ -36,6 +37,8 @@ in vec2 vary_tc;
3637
void main()
3738
{
3839
vec3 col = texture(diffuseRect, vary_tc).rgb;
39-
40-
frag_color = vec4(col.rgb, dot(col.rgb, vec3(0.299, 0.587, 0.144)));
40+
#ifndef NO_GLOW
41+
col += texture2D(emissiveRect, vary_tc).rgb;
42+
#endif
43+
frag_color = vec4(col, dot(col, vec3(0.299, 0.587, 0.144)));
4144
}

indra/newview/llgltfmaterialpreviewmgr.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -529,32 +529,14 @@ bool LLGLTFPreviewTexture::render()
529529
gPipeline.tonemap(&screen, dst);
530530
std::swap(src, dst);
531531

532+
// Final render
532533
LLVertexBuffer::unbind();
533534
gPipeline.generateGlow(src);
534-
gPipeline.combineGlow(src, dst);
535-
std::swap(src, dst);
535+
gPipeline.combineGlow(src, nullptr);
536536

537537
// *HACK: Restore mExposureMap (it will be consumed by generateExposure next frame)
538538
gPipeline.mExposureMap.swapFBORefs(gPipeline.mLastExposure);
539539

540-
// Final render
541-
542-
gDeferredPostNoDoFProgram.bind();
543-
544-
// From LLPipeline::renderFinalize: "Whatever is last in the above post processing chain should _always_ be rendered directly here. If not, expect problems."
545-
gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src);
546-
gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, mBoundTarget, true);
547-
548-
gDeferredPostNoDoFProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, (GLfloat)src->getWidth(), (GLfloat)src->getHeight());
549-
550-
{
551-
LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
552-
gPipeline.mScreenTriangleVB->setBuffer();
553-
gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
554-
}
555-
556-
gDeferredPostNoDoFProgram.unbind();
557-
558540
// Clean up
559541
gPipeline.setupHWLights();
560542
gPipeline.mReflectionMapManager.forceDefaultProbeAndUpdateUniforms(false);

indra/newview/llviewershadermgr.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ LLGLSLShader gRadianceGenProgram;
8787
LLGLSLShader gHeroRadianceGenProgram;
8888
LLGLSLShader gIrradianceGenProgram;
8989
LLGLSLShader gGlowCombineFXAAProgram;
90+
LLGLSLShader gFXAALumaGenProgram;
9091
LLGLSLShader gTwoTextureCompareProgram;
9192
LLGLSLShader gOneTextureFilterProgram;
9293
LLGLSLShader gDebugProgram;
@@ -206,6 +207,7 @@ LLGLSLShader gFXAAProgram[4];
206207
LLGLSLShader gSMAAEdgeDetectProgram[4];
207208
LLGLSLShader gSMAABlendWeightsProgram[4];
208209
LLGLSLShader gSMAANeighborhoodBlendProgram[4];
210+
LLGLSLShader gSMAANeighborhoodBlendGlowCombineProgram[4];
209211
LLGLSLShader gCASProgram;
210212
LLGLSLShader gCASLegacyGammaProgram;
211213
LLGLSLShader gDeferredPostNoDoFProgram;
@@ -2496,15 +2498,35 @@ bool LLViewerShaderMgr::loadShadersDeferred()
24962498

24972499
gSMAANeighborhoodBlendProgram[i].clearPermutations();
24982500
gSMAANeighborhoodBlendProgram[i].addPermutations(defines);
2501+
gSMAANeighborhoodBlendProgram[i].addPermutation("NO_GLOW", "1");
24992502

25002503
gSMAANeighborhoodBlendProgram[i].mShaderFiles.clear();
25012504
gSMAANeighborhoodBlendProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAANeighborhoodBlendF.glsl", GL_FRAGMENT_SHADER_ARB));
25022505
gSMAANeighborhoodBlendProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAANeighborhoodBlendV.glsl", GL_VERTEX_SHADER_ARB));
25032506
gSMAANeighborhoodBlendProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAA.glsl", GL_FRAGMENT_SHADER_ARB));
25042507
gSMAANeighborhoodBlendProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAA.glsl", GL_VERTEX_SHADER_ARB));
25052508
gSMAANeighborhoodBlendProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
2509+
25062510
success = gSMAANeighborhoodBlendProgram[i].createShader();
25072511
}
2512+
2513+
if (success)
2514+
{
2515+
gSMAANeighborhoodBlendGlowCombineProgram[i].mName = llformat("SMAA Neighborhood Blending Glow Combine (%s)", smaa_pair.second.c_str());
2516+
gSMAANeighborhoodBlendGlowCombineProgram[i].mFeatures.isDeferred = true;
2517+
2518+
gSMAANeighborhoodBlendGlowCombineProgram[i].clearPermutations();
2519+
gSMAANeighborhoodBlendGlowCombineProgram[i].addPermutations(defines);
2520+
2521+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderFiles.clear();
2522+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAANeighborhoodBlendF.glsl", GL_FRAGMENT_SHADER_ARB));
2523+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAANeighborhoodBlendV.glsl", GL_VERTEX_SHADER_ARB));
2524+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAA.glsl", GL_FRAGMENT_SHADER_ARB));
2525+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderFiles.push_back(make_pair("deferred/SMAA.glsl", GL_VERTEX_SHADER_ARB));
2526+
gSMAANeighborhoodBlendGlowCombineProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
2527+
2528+
success = gSMAANeighborhoodBlendGlowCombineProgram[i].createShader();
2529+
}
25082530
++i;
25092531
}
25102532
}
@@ -2970,7 +2992,7 @@ bool LLViewerShaderMgr::loadShadersInterface()
29702992

29712993
if (success)
29722994
{
2973-
gGlowCombineFXAAProgram.mName = "Glow CombineFXAA Shader";
2995+
gGlowCombineFXAAProgram.mName = "Glow Combine FXAA Luma Gen Shader";
29742996
gGlowCombineFXAAProgram.mShaderFiles.clear();
29752997
gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAV.glsl", GL_VERTEX_SHADER));
29762998
gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAF.glsl", GL_FRAGMENT_SHADER));
@@ -2985,6 +3007,25 @@ bool LLViewerShaderMgr::loadShadersInterface()
29853007
}
29863008
}
29873009

3010+
if (success)
3011+
{
3012+
gFXAALumaGenProgram.mName = "FXAA Luma Gen Shader";
3013+
gFXAALumaGenProgram.mShaderFiles.clear();
3014+
gFXAALumaGenProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAV.glsl", GL_VERTEX_SHADER));
3015+
gFXAALumaGenProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAF.glsl", GL_FRAGMENT_SHADER));
3016+
gFXAALumaGenProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
3017+
gFXAALumaGenProgram.clearPermutations();
3018+
gFXAALumaGenProgram.addPermutation("NO_GLOW", "1");
3019+
success = gFXAALumaGenProgram.createShader();
3020+
if (success)
3021+
{
3022+
gFXAALumaGenProgram.bind();
3023+
gFXAALumaGenProgram.uniform1i(sGlowMap, 0);
3024+
gFXAALumaGenProgram.uniform1i(sScreenMap, 1);
3025+
gFXAALumaGenProgram.unbind();
3026+
}
3027+
}
3028+
29883029
#ifdef LL_WINDOWS
29893030
if (success)
29903031
{

indra/newview/llviewershadermgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ extern LLGLSLShader gRadianceGenProgram;
160160
extern LLGLSLShader gHeroRadianceGenProgram;
161161
extern LLGLSLShader gIrradianceGenProgram;
162162
extern LLGLSLShader gGlowCombineFXAAProgram;
163+
extern LLGLSLShader gFXAALumaGenProgram;
163164
extern LLGLSLShader gDebugProgram;
164165
enum NormalDebugShaderVariant : S32
165166
{
@@ -250,6 +251,7 @@ extern LLGLSLShader gFXAAProgram[4];
250251
extern LLGLSLShader gSMAAEdgeDetectProgram[4];
251252
extern LLGLSLShader gSMAABlendWeightsProgram[4];
252253
extern LLGLSLShader gSMAANeighborhoodBlendProgram[4];
254+
extern LLGLSLShader gSMAANeighborhoodBlendGlowCombineProgram[4];
253255
extern LLGLSLShader gCASProgram;
254256
extern LLGLSLShader gCASLegacyGammaProgram;
255257
extern LLGLSLShader gDeferredPostNoDoFProgram;

0 commit comments

Comments
 (0)