Skip to content

Commit d3d0e79

Browse files
committed
GITechDemo:
* Added motion blur as a new post-process effect * Fixed downsample pass still rendering when bloom and tone mapping were disabled (it's not used by anything else, currently) * Fixed a bug where only the luminance measurement pass of the tone mapping effect group would be disabled when tone mapping was disabled
1 parent e6842c9 commit d3d0e79

17 files changed

+332
-43
lines changed

GITechDemo/Code/AppMain/GITechDemo.vcxproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
<ClInclude Include="GITechDemo\RenderScheme\HDRToneMappingPass.h" />
270270
<ClInclude Include="GITechDemo\RenderScheme\HUDPass.h" />
271271
<ClInclude Include="GITechDemo\RenderScheme\LightingPass.h" />
272+
<ClInclude Include="GITechDemo\RenderScheme\MotionBlurPass.h" />
272273
<ClInclude Include="GITechDemo\RenderScheme\PostProcessingPass.h" />
273274
<ClInclude Include="GITechDemo\RenderScheme\RenderPass.h" />
274275
<ClInclude Include="GITechDemo\RenderScheme\RenderScheme.h" />
@@ -299,6 +300,7 @@
299300
<ClCompile Include="GITechDemo\RenderScheme\HDRToneMappingPass.cpp" />
300301
<ClCompile Include="GITechDemo\RenderScheme\HUDPass.cpp" />
301302
<ClCompile Include="GITechDemo\RenderScheme\LightingPass.cpp" />
303+
<ClCompile Include="GITechDemo\RenderScheme\MotionBlurPass.cpp" />
302304
<ClCompile Include="GITechDemo\RenderScheme\PostProcessingPass.cpp" />
303305
<ClCompile Include="GITechDemo\RenderScheme\RenderPass.cpp" />
304306
<ClCompile Include="GITechDemo\RenderScheme\RenderScheme.cpp" />
@@ -703,6 +705,39 @@ call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(
703705
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
704706
<Outputs Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
705707
</CustomBuild>
708+
<CustomBuild Include="..\..\Data\shaders\MotionBlur.hlsl">
709+
<FileType>Document</FileType>
710+
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
711+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
712+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
713+
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
714+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
715+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
716+
<Command Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
717+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
718+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
719+
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
720+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
721+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
722+
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
723+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
724+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
725+
<Command Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">call "%25DXSDK_DIR%25\Utilities\bin\dx_setenv.cmd"
726+
call fxc.exe /T vs_3_0 /E vsmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm" "%(FullPath)"
727+
call fxc.exe /T ps_3_0 /E psmain /O3 /nologo /Fc "$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm" "%(FullPath)"</Command>
728+
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compiling shader "%(Filename)%(Extension)"</Message>
729+
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling shader "%(Filename)%(Extension)"</Message>
730+
<Message Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">Compiling shader "%(Filename)%(Extension)"</Message>
731+
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compiling shader "%(Filename)%(Extension)"</Message>
732+
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling shader "%(Filename)%(Extension)"</Message>
733+
<Message Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">Compiling shader "%(Filename)%(Extension)"</Message>
734+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
735+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
736+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
737+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
738+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
739+
<Outputs Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).vsasm;$(SolutionDir)..\..\BinTemp\$(ProjectName)\Shaders\%(Filename).psasm;%(Outputs)</Outputs>
740+
</CustomBuild>
706741
<None Include="..\..\Data\shaders\PostProcessingUtils.hlsl">
707742
<FileType>Document</FileType>
708743
</None>

GITechDemo/Code/AppMain/GITechDemo.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
<ClInclude Include="GITechDemo\Resource.h">
112112
<Filter>Header Files</Filter>
113113
</ClInclude>
114+
<ClInclude Include="GITechDemo\RenderScheme\MotionBlurPass.h">
115+
<Filter>Header Files</Filter>
116+
</ClInclude>
114117
</ItemGroup>
115118
<ItemGroup>
116119
<ClCompile Include="Framework\Windows\stdafx.cpp">
@@ -197,6 +200,9 @@
197200
<ClCompile Include="GITechDemo\Resources\ArtistParametersDef.cpp">
198201
<Filter>Source Files</Filter>
199202
</ClCompile>
203+
<ClCompile Include="GITechDemo\RenderScheme\MotionBlurPass.cpp">
204+
<Filter>Source Files</Filter>
205+
</ClCompile>
200206
</ItemGroup>
201207
<ItemGroup>
202208
<Image Include="Framework\Windows\Framework.ico">
@@ -246,6 +252,9 @@
246252
<None Include="..\..\Build\build_data_win.py">
247253
<Filter>Build</Filter>
248254
</None>
255+
<None Include="..\..\Data\shaders\MotionBlur.hlsl">
256+
<Filter>Shaders</Filter>
257+
</None>
249258
</ItemGroup>
250259
<ItemGroup>
251260
<ResourceCompile Include="GITechDemo\GITechDemo.rc">

GITechDemo/Code/AppMain/GITechDemo/GITechDemo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,15 @@ void GITechDemo::Update(const float fDeltaTime)
421421

422422
// Calculate some composite matrices
423423
gmtl::invertFull((Matrix44f&)f44InvViewMat, (Matrix44f&)f44ViewMat);
424+
f44PrevViewProjMat = f44ViewProjMat; // View-projection matrix from last frame
424425
f44ViewProjMat = f44ProjMat * f44ViewMat;
425426
f44InvViewProjMat = f44InvViewMat * f44InvProjMat;
426427

428+
// For the first frame, set the last frame's view-projection matrix
429+
// to the current frame's view-projection matrix
430+
if (f44PrevViewProjMat.GetCurrentValue() == MAT_IDENTITY44F)
431+
f44PrevViewProjMat = f44ViewProjMat;
432+
427433
// Set the size of the backbuffer accordingly
428434
RenderContext->SetBackBufferSize(viewportSize);
429435

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/HDRDownsamplePass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ using namespace GITechDemoApp;
1212

1313
#include "RenderResourcesDef.h"
1414

15+
namespace GITechDemoApp
16+
{
17+
extern bool BLOOM_ENABLED;
18+
extern bool HDR_TONE_MAPPING_ENABLED;
19+
}
20+
1521
HDRDownsamplePass::HDRDownsamplePass(const char* const passName, RenderPass* const parentPass)
1622
: RenderPass(passName, parentPass)
1723
{}
@@ -67,6 +73,9 @@ void HDRDownsamplePass::DownsamplePass(GITechDemoApp::RenderTarget* const pSourc
6773

6874
void HDRDownsamplePass::Draw()
6975
{
76+
if (!BLOOM_ENABLED && !HDR_TONE_MAPPING_ENABLED)
77+
return;
78+
7079
Renderer* RenderContext = Renderer::GetInstance();
7180
if (!RenderContext)
7281
return;

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/HDRToneMappingPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ void HDRToneMappingPass::Update(const float fDeltaTime)
5757
// Measure average luminance level of scene
5858
void HDRToneMappingPass::LuminanceMeasurementPass()
5959
{
60-
if (!HDR_TONE_MAPPING_ENABLED)
61-
return;
62-
6360
Renderer* RenderContext = Renderer::GetInstance();
6461
if (!RenderContext)
6562
return;
@@ -184,6 +181,9 @@ void HDRToneMappingPass::ToneMappingPass()
184181

185182
void HDRToneMappingPass::Draw()
186183
{
184+
if (!HDR_TONE_MAPPING_ENABLED)
185+
return;
186+
187187
LuminanceMeasurementPass();
188188
LuminanceAdaptationPass();
189189
ToneMappingPass();
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include "stdafx.h"
2+
3+
#include <Renderer.h>
4+
#include <RenderTarget.h>
5+
#include <RenderState.h>
6+
#include <ResourceManager.h>
7+
#include <Texture.h>
8+
using namespace LibRendererDll;
9+
10+
#include "MotionBlurPass.h"
11+
using namespace GITechDemoApp;
12+
13+
#include "RenderResourcesDef.h"
14+
15+
namespace GITechDemoApp
16+
{
17+
bool MOTION_BLUR_ENABLED = true;
18+
}
19+
20+
MotionBlurPass::MotionBlurPass(const char* const passName, RenderPass* const parentPass)
21+
: RenderPass(passName, parentPass)
22+
{}
23+
24+
MotionBlurPass::~MotionBlurPass()
25+
{}
26+
27+
void MotionBlurPass::Update(const float fDeltaTime)
28+
{}
29+
30+
void MotionBlurPass::Draw()
31+
{
32+
if(!MOTION_BLUR_ENABLED)
33+
return;
34+
35+
CalculateMotionBlur();
36+
ApplyMotionBlur();
37+
}
38+
39+
void MotionBlurPass::CalculateMotionBlur()
40+
{
41+
Renderer* RenderContext = Renderer::GetInstance();
42+
if (!RenderContext)
43+
return;
44+
45+
PUSH_PROFILE_MARKER("Calculate");
46+
47+
MotionBlurBuffer.Enable();
48+
49+
const bool colorBlendEnabled = RenderContext->GetRenderStateManager()->GetColorBlendEnabled();
50+
RenderContext->GetRenderStateManager()->SetColorBlendEnabled(false);
51+
52+
f2HalfTexelOffset = Vec2f(
53+
0.5f / LightAccumulationBuffer.GetRenderTarget()->GetWidth(),
54+
0.5f / LightAccumulationBuffer.GetRenderTarget()->GetHeight()
55+
);
56+
texSource = LightAccumulationBuffer.GetRenderTarget()->GetColorBuffer();
57+
texDepthBuffer = GBuffer.GetRenderTarget()->GetDepthBuffer();
58+
59+
MotionBlurShader.Enable();
60+
RenderContext->DrawVertexBuffer(FullScreenTri);
61+
MotionBlurShader.Disable();
62+
63+
RenderContext->GetRenderStateManager()->SetColorBlendEnabled(colorBlendEnabled);
64+
65+
MotionBlurBuffer.Disable();
66+
67+
POP_PROFILE_MARKER();
68+
}
69+
70+
void MotionBlurPass::ApplyMotionBlur()
71+
{
72+
Renderer* RenderContext = Renderer::GetInstance();
73+
if (!RenderContext)
74+
return;
75+
76+
PUSH_PROFILE_MARKER("Apply");
77+
78+
LightAccumulationBuffer.Enable();
79+
80+
const bool blendEnabled = RenderContext->GetRenderStateManager()->GetColorBlendEnabled();
81+
bool zWrite = RenderContext->GetRenderStateManager()->GetZWriteEnabled();
82+
Cmp zFunc = RenderContext->GetRenderStateManager()->GetZFunc();
83+
84+
RenderContext->GetRenderStateManager()->SetColorBlendEnabled(false);
85+
RenderContext->GetRenderStateManager()->SetZWriteEnabled(false);
86+
RenderContext->GetRenderStateManager()->SetZFunc(CMP_ALWAYS);
87+
88+
f2HalfTexelOffset = Vec2f(
89+
0.5f / LightAccumulationBuffer.GetRenderTarget()->GetWidth(),
90+
0.5f / LightAccumulationBuffer.GetRenderTarget()->GetHeight()
91+
);
92+
texSource = MotionBlurBuffer.GetRenderTarget()->GetColorBuffer();
93+
94+
ColorCopyShader.Enable();
95+
RenderContext->DrawVertexBuffer(FullScreenTri);
96+
ColorCopyShader.Disable();
97+
98+
RenderContext->GetRenderStateManager()->SetColorBlendEnabled(blendEnabled);
99+
RenderContext->GetRenderStateManager()->SetZWriteEnabled(zWrite);
100+
RenderContext->GetRenderStateManager()->SetZFunc(zFunc);
101+
102+
LightAccumulationBuffer.Disable();
103+
104+
POP_PROFILE_MARKER();
105+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef MOTION_BLUR_PASS_H_
2+
#define MOTION_BLUR_PASS_H_
3+
4+
#include "RenderPass.h"
5+
6+
namespace GITechDemoApp
7+
{
8+
class MotionBlurPass : public RenderPass
9+
{
10+
IMPLEMENT_RENDER_PASS(MotionBlurPass);
11+
12+
private:
13+
void CalculateMotionBlur();
14+
void ApplyMotionBlur();
15+
};
16+
}
17+
18+
#endif // MOTION_BLUR_PASS_H_

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/PostProcessingPass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace GITechDemoApp
2222
extern bool FXAA_ENABLED;
2323
// DoF
2424
extern bool DOF_ENABLED;
25+
// Motion blur
26+
extern bool MOTION_BLUR_ENABLED;
2527
}
2628

2729
PostProcessingPass::PostProcessingPass(const char* const passName, RenderPass* const parentPass)
@@ -41,6 +43,9 @@ void PostProcessingPass::Update(const float fDeltaTime)
4143
if (DOF_ENABLED)
4244
m_pFinalImageBuffer = LightAccumulationBuffer.GetRenderTarget();
4345

46+
if (MOTION_BLUR_ENABLED)
47+
m_pFinalImageBuffer = LightAccumulationBuffer.GetRenderTarget();
48+
4449
if (BLOOM_ENABLED)
4550
m_pFinalImageBuffer = LightAccumulationBuffer.GetRenderTarget();
4651

0 commit comments

Comments
 (0)