Skip to content

Commit 25c43a7

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
GLTF Viewer: Added PostFXContext
1 parent f8cdc2d commit 25c43a7

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

Samples/Atmosphere/assets/shaders/BasicStructures.fxh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ struct CameraAttribs
138138
matrix mViewProjInv;
139139
#endif
140140

141-
float4 f4ExtraData[5]; // Any appliation-specific data
141+
uint iFrameIndex;
142+
float fDummy0;
143+
float fDummy1;
144+
float fDummy2;
145+
146+
float4 f4ExtraData[4]; // Any appliation-specific data
142147
// Sizeof(CameraAttribs) == 256*2
143148
};
144149
#ifdef CHECK_STRUCT_ALIGNMENT

Samples/GLTFViewer/src/GLTFViewer.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "GraphicsAccessories.hpp"
4545
#include "EnvMapRenderer.hpp"
4646
#include "VectorFieldRenderer.hpp"
47+
#include "PostFXContext.hpp"
4748
#include "ScreenSpaceReflection.hpp"
4849
#include "Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
4950
#include "ShaderSourceFactoryUtils.h"
@@ -57,6 +58,7 @@ namespace HLSL
5758
#include "Shaders/Common/public/BasicStructures.fxh"
5859
#include "Shaders/PBR/public/PBR_Structures.fxh"
5960
#include "Shaders/PBR/private/RenderPBR_Structures.fxh"
61+
#include "Shaders/PostProcess/ScreenSpaceReflection/public/ScreenSpaceReflectionStructures.fxh"
6062

6163
} // namespace HLSL
6264

@@ -592,7 +594,8 @@ void GLTFViewer::Initialize(const SampleInitInfo& InitInfo)
592594
CreateGLTFRenderer();
593595
CrateEnvMapRenderer();
594596
CreateVectorFieldRenderer();
595-
m_SSR = std::make_unique<ScreenSpaceReflection>(m_pDevice);
597+
m_PostFXContext = std::make_unique<PostFXContext>(m_pDevice);
598+
m_SSR = std::make_unique<ScreenSpaceReflection>(m_pDevice);
596599

597600
RefCntAutoPtr<IRenderStateNotationParser> pRSNParser;
598601
{
@@ -983,13 +986,14 @@ void GLTFViewer::UpdateUI()
983986
CrateEnvMapRenderer();
984987
}
985988

989+
ImGui::SliderFloat("SSAO scale", &m_ShaderAttribs.SSAOScale, 0.f, 1.f);
986990
ImGui::SliderFloat("SSR scale", &m_ShaderAttribs.SSRScale, 0.f, 1.f);
987991

988-
ImGui::Combo("SSR Debug View", &m_ShaderAttribs.SSRDebugMode,
992+
ImGui::Combo("Debug View", &m_ShaderAttribs.PostFXDebugMode,
989993
"None\0"
990-
"Radiance\0"
991-
"Reflection\0"
992-
"Confidence\0\0");
994+
"SSR: Radiance\0"
995+
"SSR: Reflection\0"
996+
"SSR: Confidence\0\0");
993997

994998
ImGui::TreePop();
995999
}
@@ -1063,7 +1067,7 @@ void GLTFViewer::Render()
10631067
{
10641068
FrameAttribs->PrevCamera.f4ExtraData[0] = float4{
10651069
m_ShaderAttribs.SSRScale,
1066-
static_cast<float>(m_ShaderAttribs.SSRDebugMode),
1070+
static_cast<float>(m_ShaderAttribs.PostFXDebugMode),
10671071
0,
10681072
0,
10691073
};
@@ -1212,33 +1216,30 @@ void GLTFViewer::Render()
12121216
}
12131217

12141218
{
1219+
PostFXContext::RenderAttributes PostFXAttibs;
1220+
PostFXAttibs.pDevice = m_pDevice;
1221+
PostFXAttibs.pDeviceContext = m_pImmediateContext;
1222+
PostFXAttibs.pCameraAttribsCB = m_FrameAttribsCB;
1223+
PostFXAttibs.FrameIndex = m_CurrentFrameNumber;
1224+
m_PostFXContext->PrepareResources(PostFXAttibs);
1225+
}
1226+
1227+
{
1228+
HLSL::ScreenSpaceReflectionAttribs SSRAttribs{};
1229+
SSRAttribs.IBLFactor = m_ShaderAttribs.IBLScale;
1230+
SSRAttribs.RoughnessChannel = 0;
1231+
SSRAttribs.IsRoughnessPerceptual = true;
1232+
12151233
ScreenSpaceReflection::RenderAttributes SSRRenderAttribs{};
12161234
SSRRenderAttribs.pDevice = m_pDevice;
12171235
SSRRenderAttribs.pDeviceContext = m_pImmediateContext;
1236+
SSRRenderAttribs.pPostFXContext = m_PostFXContext.get();
12181237
SSRRenderAttribs.pColorBufferSRV = m_GBuffer->GetBuffer(GBUFFER_RT_RADIANCE)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
12191238
SSRRenderAttribs.pDepthBufferSRV = m_GBuffer->GetBuffer(GBUFFER_RT_DEPTH)->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL);
12201239
SSRRenderAttribs.pNormalBufferSRV = m_GBuffer->GetBuffer(GBUFFER_RT_NORMAL)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
12211240
SSRRenderAttribs.pMaterialBufferSRV = m_GBuffer->GetBuffer(GBUFFER_RT_MATERIAL_DATA)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
12221241
SSRRenderAttribs.pMotionVectorsSRV = m_GBuffer->GetBuffer(GBUFFER_RT_MOTION_VECTORS)->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
1223-
1224-
SSRRenderAttribs.SSRAttribs.ProjMatrix = CurrCamAttribs.mProjT;
1225-
SSRRenderAttribs.SSRAttribs.ViewMatrix = CurrCamAttribs.mViewT;
1226-
SSRRenderAttribs.SSRAttribs.ViewProjMatrix = CurrCamAttribs.mViewProjT;
1227-
SSRRenderAttribs.SSRAttribs.InvProjMatrix = CurrCamAttribs.mProjInvT;
1228-
SSRRenderAttribs.SSRAttribs.InvViewMatrix = CurrCamAttribs.mViewInvT;
1229-
SSRRenderAttribs.SSRAttribs.InvViewProjMatrix = CurrCamAttribs.mViewProjInvT;
1230-
SSRRenderAttribs.SSRAttribs.PrevViewProjMatrix = PrevCamAttribs.mViewProjT;
1231-
SSRRenderAttribs.SSRAttribs.InvPrevViewProjMatrix = PrevCamAttribs.mViewProjInvT;
1232-
SSRRenderAttribs.SSRAttribs.CameraPosition = CurrCamAttribs.f4Position;
1233-
1234-
SSRRenderAttribs.SSRAttribs.RenderSize.x = SCDesc.Width;
1235-
SSRRenderAttribs.SSRAttribs.RenderSize.y = SCDesc.Height;
1236-
SSRRenderAttribs.SSRAttribs.InverseRenderSize.x = 1.0f / static_cast<float>(SCDesc.Width);
1237-
SSRRenderAttribs.SSRAttribs.InverseRenderSize.y = 1.0f / static_cast<float>(SCDesc.Height);
1238-
SSRRenderAttribs.SSRAttribs.FrameIndex = m_CurrentFrameNumber;
1239-
SSRRenderAttribs.SSRAttribs.IBLFactor = m_ShaderAttribs.IBLScale;
1240-
SSRRenderAttribs.SSRAttribs.RoughnessChannel = 0;
1241-
SSRRenderAttribs.SSRAttribs.IsRoughnessPerceptual = true;
1242+
SSRRenderAttribs.pSSRAttribs = &SSRAttribs;
12421243
m_SSR->Execute(SSRRenderAttribs);
12431244
}
12441245

Samples/GLTFViewer/src/GLTFViewer.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct CameraAttribs;
4949

5050
class EnvMapRenderer;
5151
class VectorFieldRenderer;
52+
class PostFXContext;
5253
class ScreenSpaceReflection;
5354

5455
class GLTFViewer final : public SampleBase
@@ -99,8 +100,9 @@ class GLTFViewer final : public SampleBase
99100
float4 HighlightColor = float4{0, 0, 0, 0};
100101
float4 WireframeColor = float4{0.8f, 0.7f, 0.5f, 1.0f};
101102

102-
float SSRScale = 1;
103-
int SSRDebugMode = 0;
103+
float SSRScale = 1;
104+
float SSAOScale = 1;
105+
int PostFXDebugMode = 0;
104106
};
105107
ShaderParams m_ShaderAttribs;
106108

@@ -166,6 +168,7 @@ class GLTFViewer final : public SampleBase
166168

167169
std::unique_ptr<EnvMapRenderer> m_EnvMapRenderer;
168170
std::unique_ptr<VectorFieldRenderer> m_VectorFieldRenderer;
171+
std::unique_ptr<PostFXContext> m_PostFXContext;
169172
std::unique_ptr<ScreenSpaceReflection> m_SSR;
170173

171174
bool m_bUseResourceCache = false;

Samples/Shadows/assets/shaders/BasicStructures.fxh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ struct CameraAttribs
138138
matrix mViewProjInv;
139139
#endif
140140

141-
float4 f4ExtraData[5]; // Any appliation-specific data
141+
uint iFrameIndex;
142+
float fDummy0;
143+
float fDummy1;
144+
float fDummy2;
145+
146+
float4 f4ExtraData[4]; // Any appliation-specific data
142147
// Sizeof(CameraAttribs) == 256*2
143148
};
144149
#ifdef CHECK_STRUCT_ALIGNMENT

0 commit comments

Comments
 (0)