43
43
#include " CommandLineParser.hpp"
44
44
#include " GraphicsAccessories.hpp"
45
45
#include " EnvMapRenderer.hpp"
46
+ #include " VectorFieldRenderer.hpp"
46
47
#include " Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
47
48
#include " ShaderSourceFactoryUtils.h"
48
49
@@ -368,7 +369,7 @@ struct PSOutput
368
369
}
369
370
# endif
370
371
371
- PSOut.MotionVec = float4(0.0, 0.0 , 0.0, 1.0);
372
+ PSOut.MotionVec = float4(MotionVector , 0.0, 1.0);
372
373
return PSOut;
373
374
)" ;
374
375
@@ -498,6 +499,16 @@ void GLTFViewer::CrateEnvMapRenderer()
498
499
m_EnvMapRenderer = std::make_unique<EnvMapRenderer>(EnvMapRendererCI);
499
500
}
500
501
502
+ void GLTFViewer::CreateVectorFieldRenderer ()
503
+ {
504
+ VectorFieldRenderer::CreateInfo CI;
505
+ CI.pDevice = m_pDevice;
506
+ CI.NumRenderTargets = 1 ;
507
+ CI.RTVFormats [0 ] = m_pSwapChain->GetDesc ().ColorBufferFormat ;
508
+
509
+ m_VectorFieldRenderer = std::make_unique<VectorFieldRenderer>(CI);
510
+ }
511
+
501
512
void GLTFViewer::Initialize (const SampleInitInfo& InitInfo)
502
513
{
503
514
SampleBase::Initialize (InitInfo);
@@ -534,6 +545,7 @@ void GLTFViewer::Initialize(const SampleInitInfo& InitInfo)
534
545
535
546
CreateGLTFRenderer ();
536
547
CrateEnvMapRenderer ();
548
+ CreateVectorFieldRenderer ();
537
549
538
550
RefCntAutoPtr<IRenderStateNotationParser> pRSNParser;
539
551
{
@@ -724,7 +736,13 @@ void GLTFViewer::UpdateUI()
724
736
ImGui::SetNextItemOpen (true , ImGuiCond_FirstUseEver);
725
737
if (ImGui::TreeNode (" Animation" ))
726
738
{
727
- ImGui::Checkbox (" Play" , &m_PlayAnimation);
739
+ if (ImGui::Checkbox (" Play" , &m_PlayAnimation))
740
+ {
741
+ if (!m_PlayAnimation)
742
+ {
743
+ m_Transforms[(m_CurrentFrameNumber + 1 ) & 0x01 ] = m_Transforms[m_CurrentFrameNumber & 0x01 ];
744
+ }
745
+ }
728
746
std::vector<const char *> Animations (m_Model->Animations .size ());
729
747
for (size_t i = 0 ; i < m_Model->Animations .size (); ++i)
730
748
Animations[i] = m_Model->Animations [i].Name .c_str ();
@@ -773,7 +791,7 @@ void GLTFViewer::UpdateUI()
773
791
{GLTF_PBR_Renderer::DebugViewType::ShadingNormal, " Shading normal" },
774
792
{GLTF_PBR_Renderer::DebugViewType::MotionVectors, " Motion Vectors" },
775
793
{GLTF_PBR_Renderer::DebugViewType::NdotV, " n*v" },
776
- {PBR_Renderer ::DebugViewType::PunctualLighting, " Punctual Lighting" },
794
+ {GLTF_PBR_Renderer ::DebugViewType::PunctualLighting, " Punctual Lighting" },
777
795
{GLTF_PBR_Renderer::DebugViewType::DiffuseIBL, " Diffuse IBL" },
778
796
{GLTF_PBR_Renderer::DebugViewType::SpecularIBL, " Specular IBL" },
779
797
{GLTF_PBR_Renderer::DebugViewType::ClearCoat, " Clear Coat" },
@@ -933,8 +951,9 @@ GLTFViewer::~GLTFViewer()
933
951
// Render a frame
934
952
void GLTFViewer::Render ()
935
953
{
936
- auto * pRTV = m_pSwapChain->GetCurrentBackBufferRTV ();
937
- auto * pDSV = m_pSwapChain->GetDepthBufferDSV ();
954
+ ITextureView* pRTV = m_pSwapChain->GetCurrentBackBufferRTV ();
955
+ ITextureView* pDSV = m_pSwapChain->GetDepthBufferDSV ();
956
+ const SwapChainDesc& SCDesc = m_pSwapChain->GetDesc ();
938
957
939
958
if (m_bEnablePostProcessing)
940
959
{
@@ -943,7 +962,6 @@ void GLTFViewer::Render()
943
962
m_ApplyPostFX.Initialize (m_pDevice, m_pSwapChain->GetDesc ().ColorBufferFormat , m_FrameAttribsCB);
944
963
}
945
964
946
- const auto & SCDesc = m_pSwapChain->GetDesc ();
947
965
m_GBuffer->Resize (m_pDevice, SCDesc.Width , SCDesc.Height );
948
966
m_GBuffer->Bind (m_pImmediateContext, GBUFFER_RT_FLAG_ALL, nullptr , GBUFFER_RT_FLAG_ALL);
949
967
}
@@ -1077,6 +1095,26 @@ void GLTFViewer::Render()
1077
1095
m_ApplyPostFX.ptex2DColorVar ->Set (m_GBuffer->GetBuffer (GBUFFER_RT_COLOR)->GetDefaultView (TEXTURE_VIEW_SHADER_RESOURCE));
1078
1096
m_pImmediateContext->CommitShaderResources (m_ApplyPostFX.pSRB , RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
1079
1097
m_pImmediateContext->Draw ({3 , DRAW_FLAG_VERIFY_ALL});
1098
+
1099
+ if (m_VectorFieldRenderer &&
1100
+ (m_RenderParams.DebugView == GLTF_PBR_Renderer::DebugViewType::MotionVectors) &&
1101
+ (m_RenderParams.Flags & GLTF_PBR_Renderer::PSO_FLAG_COMPUTE_MOTION_VECTORS) != 0 )
1102
+ {
1103
+ VectorFieldRenderer::RenderAttribs Attribs;
1104
+ Attribs.pContext = m_pImmediateContext;
1105
+ Attribs.GridSize = {SCDesc.Width / 20 , SCDesc.Height / 20 };
1106
+ // Render motion vectors in the opposite direction
1107
+ Attribs.Scale = float2{-0 .05f } / std::max (m_ElapsedTime, 0 .001f );
1108
+ Attribs.StartColor = float4{1 };
1109
+ Attribs.EndColor = float4{0.5 };
1110
+ Attribs.ConvertOutputToSRGB = (SCDesc.ColorBufferFormat == TEX_FORMAT_RGBA8_UNORM || SCDesc.ColorBufferFormat == TEX_FORMAT_BGRA8_UNORM);
1111
+
1112
+ StateTransitionDesc Barrier{m_GBuffer->GetBuffer (GBUFFER_RT_MOTION_VECTORS), RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE, STATE_TRANSITION_FLAG_UPDATE_STATE};
1113
+ m_pImmediateContext->TransitionResourceStates (1 , &Barrier);
1114
+
1115
+ Attribs.pVectorField = m_GBuffer->GetBuffer (GBUFFER_RT_MOTION_VECTORS)->GetDefaultView (TEXTURE_VIEW_SHADER_RESOURCE);
1116
+ m_VectorFieldRenderer->Render (Attribs);
1117
+ }
1080
1118
}
1081
1119
}
1082
1120
@@ -1090,6 +1128,8 @@ void GLTFViewer::Update(double CurrTime, double ElapsedTime)
1090
1128
SampleBase::Update (CurrTime, ElapsedTime);
1091
1129
UpdateUI ();
1092
1130
1131
+ m_ElapsedTime = static_cast <float >(ElapsedTime);
1132
+
1093
1133
float YFov = PI_F / 4 .0f ;
1094
1134
float ZNear = 0 .1f ;
1095
1135
float ZFar = 100 .f ;
0 commit comments