This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
vaGTAO.h
137 lines (106 loc) · 9.19 KB
/
vaGTAO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016-2021, Intel Corporation
//
// SPDX-License-Identifier: MIT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// XeGTAO is based on GTAO/GTSO "Jimenez et al. / Practical Real-Time Strategies for Accurate Indirect Occlusion",
// https://www.activision.com/cdn/research/Practical_Real_Time_Strategies_for_Accurate_Indirect_Occlusion_NEW%20VERSION_COLOR.pdf
//
// Implementation: Filip Strugar ([email protected]), Steve Mccalla <[email protected]> (\_/)
// Version: (see XeGTAO.h) (='.'=)
// Details: https://github.com/GameTechDev/XeGTAO (")_(")
//
// Version history: see XeGTAO.h
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "Rendering/Shaders/vaShaderCore.h"
#include "Rendering/vaRendering.h"
#include "Rendering/vaShader.h"
#include "Rendering/vaRenderBuffers.h"
#include "Rendering/vaTexture.h"
#include "Core/vaUI.h"
#include "IntegratedExternals/vaImguiIntegration.h"
#include "Rendering/Shaders/XeGTAO.h"
namespace Vanilla
{
class vaGTAO : public vaRenderingModule, public vaUIPanel
{
protected:
mutable bool m_debugShowNormals = false;
mutable bool m_debugShowBentNormals = false;
mutable bool m_debugShowEdges = false;
mutable bool m_debugShowGTAODebugViz = false;
bool m_use32bitDepth = false;
bool m_use16bitMath = true;
bool m_generateNormals = false;
vaVector2i m_size;
shared_ptr<vaTexture> m_workingDepths;
shared_ptr<vaTexture> m_workingDepthsMIPViews[XE_GTAO_DEPTH_MIP_LEVELS];
shared_ptr<vaTexture> m_workingAOTerm; // AO alone or AO+BentNormals
shared_ptr<vaTexture> m_workingAOTermPong; // same as ^, used for ping-ponging
shared_ptr<vaTexture> m_workingEdges;
shared_ptr<vaTexture> m_debugImage;
shared_ptr<vaTexture> m_workingNormals;
shared_ptr<vaTexture> m_hilbertLUT;
mutable XeGTAO::GTAOSettings m_settings;
bool m_constantsMatchDefaults = false; // just an optimization thing - see XE_GTAO_USE_DEFAULT_CONSTANTS
bool m_outputBentNormals = false; // as given in the last Compute( ... ) call
// MSAA versions include 1-sample for non-MSAA
shared_ptr<vaComputeShader> m_CSGenerateNormals; // optional screen space normal generation from depth (and results could be reused elsewhere)
shared_ptr<vaComputeShader> m_CSPrefilterDepths16x16; // pass 1
shared_ptr<vaComputeShader> m_CSGTAOLow; // pass 2 - low quality
shared_ptr<vaComputeShader> m_CSGTAOMedium; // pass 2 - medium quality
shared_ptr<vaComputeShader> m_CSGTAOHigh; // pass 2 - high quality
shared_ptr<vaComputeShader> m_CSGTAOUltra; // pass 2 - ultra quality
shared_ptr<vaComputeShader> m_CSDenoisePass; // pass 3 - one denoiser pass
shared_ptr<vaComputeShader> m_CSDenoiseLastPass; // pass 3 - last denoiser pass that outputs into the final output
bool m_shadersDirty = true;
shared_ptr<vaConstantBuffer> m_constantBuffer;
std::vector< pair< string, string > > m_staticShaderMacros;
// **************************************** Reference AO raytracer ****************************************
mutable bool m_enableReferenceRTAO = false;
//
XeGTAO::ReferenceRTAOConstants m_referenceRTAOConstants;
shared_ptr<vaRenderBuffer> m_referenceRTAOConstantsBuffer;
shared_ptr<vaTexture> m_referenceRTAOBuffer;
shared_ptr<vaTexture> m_referenceRTAONormalsDepths; // RGB are normal xyz, A is viewspace Z (linear depth buffer)
shared_ptr<vaShaderLibrary> m_referenceRTAOShaders;
vaCameraBase m_referenceRTAOLastCamera; // these are for accumulating
const int m_referenceRTAOAccumFrameGoal = 512; // these are for accumulating
int m_referenceRTAOAccumFrameCount = 0; // these are for accumulating
//
string m_referenceRTAOAutoTrainingDumpTarget = ""; // if this is != "", we'll automatically dump data when ready (all
bool m_referenceRTAOAutoTrainingDumpDone = false; // if the above was used, and data was dumped,
// *****************************************************************************************************
protected:
VA_RENDERING_MODULE_MAKE_FRIENDS( );
vaGTAO( const vaRenderingModuleParams & params );
public:
virtual ~vaGTAO( ) { }
public:
vaDrawResultFlags Compute( vaRenderDeviceContext & renderContext, const vaCameraBase & cameraBase, bool usingTAA, bool outputBentNormals, const shared_ptr<vaTexture> & outputAO, const shared_ptr<vaTexture> & inputDepth, const shared_ptr<vaTexture> & inputNormals = nullptr );
vaDrawResultFlags ComputeReferenceRTAO( vaRenderDeviceContext & renderContext, const vaCameraBase & cameraBase, vaSceneRaytracing * sceneRaytracing, const shared_ptr<vaTexture> & inputDepth );
public:
XeGTAO::GTAOSettings & Settings( ) { return m_settings; }
bool & Use16bitMath( ) { return m_use16bitMath; }
bool & DebugShowNormals( ) { return m_debugShowNormals; }
bool & DebugShowEdges( ) { return m_debugShowEdges; }
bool & DebugShowBentNormals( ) { return m_debugShowBentNormals; }
bool DebugShowImage( ) { return m_debugShowNormals || m_debugShowBentNormals || m_debugShowEdges; }
const shared_ptr<vaTexture> DebugImage( ) { return m_debugImage; }
bool & ReferenceRTAOEnabled( ) { return m_enableReferenceRTAO; }
// use "" to reset / abort
//void ReferenceRTAORecordWhenReady( const string & path ) { assert( m_enableReferenceRTAO ); assert( m_referenceRTAOAutoTrainingDumpTarget == "" ); m_referenceRTAOAutoTrainingDumpTarget = path; m_referenceRTAOAutoTrainingDumpDone = false; }
//bool ReferenceRTAORecorded( ) { return m_referenceRTAOAutoTrainingDumpDone; }
int ReferenceRTAOSampleCount( ) const { return m_referenceRTAOAccumFrameCount; }
int ReferenceRTAOSampleGoal( ) const { return m_referenceRTAOAccumFrameGoal; }
// this is a signal that ComputeReferenceRTAO needs to get called
bool RequiresRaytracing( ) const { return m_enableReferenceRTAO; }
public:
virtual void UIPanelTick( vaApplicationBase & application ) override;
private:
bool UpdateTexturesAndShaders( int width, int height );
void UpdateConstants( vaRenderDeviceContext & renderContext, const vaMatrix4x4 & projMatrix, bool usingTAA );
};
} // namespace Vanilla