Skip to content

Commit 85c4cd5

Browse files
GLTF Viewer: attenuate SSR by alpha
1 parent 2f0a177 commit 85c4cd5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Samples/GLTFViewer/assets/shaders/ApplyPostEffects.psh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ float4 main(in FullScreenTriangleVSOutput VSOut) : SV_Target
2121
float4 SSR = g_tex2DSSR.Load(int3(VSOut.f4PixelPos.xy, 0));
2222
float4 IBL = g_tex2DIBL.Load(int3(VSOut.f4PixelPos.xy, 0));
2323

24-
Color.rgb += (SSR.rgb - IBL.rgb) * SSR.w;
25-
24+
Color.rgb += (SSR.rgb - IBL.rgb) * SSR.w * Color.a;
25+
2626
{
2727
// Perform tone mapping
2828
ToneMappingAttribs TMAttribs;

Samples/GLTFViewer/src/GLTFViewer.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ void main(in float4 Pos : SV_Position,
413413
out float4 MotionVec : SV_Target3,
414414
out float4 IBL : SV_Target4)
415415
{
416-
Color.rgb = SampleEnvMap(ClipPos);
417-
Color.a = 1.0;
416+
Color = SampleEnvMap(ClipPos);
418417
419418
Normal = float4(0.0, 0.0, 0.0, 0.0);
420419
MaterialData = float4(0.0, 0.0, 0.0, 0.0);
@@ -1127,10 +1126,13 @@ void GLTFViewer::Render()
11271126
TMAttribs.fLuminanceSaturation = 1.0;
11281127

11291128
EnvMapRenderer::RenderAttribs EnvMapAttribs;
1130-
EnvMapAttribs.pContext = m_pImmediateContext;
1131-
EnvMapAttribs.pEnvMap = pEnvMapSRV;
1132-
EnvMapAttribs.AverageLogLum = m_ShaderAttribs.AverageLogLum;
1133-
EnvMapAttribs.MipLevel = m_EnvMapMipLevel;
1129+
EnvMapAttribs.pContext = m_pImmediateContext;
1130+
EnvMapAttribs.pEnvMap = pEnvMapSRV;
1131+
EnvMapAttribs.AverageLogLum = m_ShaderAttribs.AverageLogLum;
1132+
EnvMapAttribs.MipLevel = m_EnvMapMipLevel;
1133+
// It is essential to write zero alpha because we use alpha channel
1134+
// to attenuate SSR for transparent surfaces.
1135+
EnvMapAttribs.Alpha = 0.0;
11341136
EnvMapAttribs.ConvertOutputToSRGB = (m_RenderParams.Flags & GLTF_PBR_Renderer::PSO_FLAG_CONVERT_OUTPUT_TO_SRGB) != 0;
11351137

11361138
m_EnvMapRenderer->Render(EnvMapAttribs, TMAttribs);
@@ -1210,7 +1212,7 @@ void GLTFViewer::Render()
12101212
// Render motion vectors in the opposite direction
12111213
Attribs.Scale = float2{-0.05f} / std::max(m_ElapsedTime, 0.001f);
12121214
Attribs.StartColor = float4{1};
1213-
Attribs.EndColor = float4{0.5};
1215+
Attribs.EndColor = float4{0.5, 0.5, 0.5, 1.0};
12141216
Attribs.ConvertOutputToSRGB = (SCDesc.ColorBufferFormat == TEX_FORMAT_RGBA8_UNORM || SCDesc.ColorBufferFormat == TEX_FORMAT_BGRA8_UNORM);
12151217

12161218
Attribs.pVectorField = m_GBuffer->GetBuffer(GBUFFER_RT_MOTION_VECTORS)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);

0 commit comments

Comments
 (0)