1 | #ifndef _DEFERREDRENDERER_H__
|
---|
2 | #define _DEFERREDRENDERER_H__
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "Matrix4x4.h"
|
---|
6 | #include "Vector3.h"
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 | class FrameBufferObject;
|
---|
12 | class Vector3;
|
---|
13 | class PerspectiveCamera;
|
---|
14 | class Matrix4x4;
|
---|
15 | class ShadowMap;
|
---|
16 | class DirectionalLight;
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | /** This class implements a deferred shading algorithm that takes
|
---|
22 | a frame buffer object as input and outputs an image in the given size
|
---|
23 | */
|
---|
24 | class DeferredRenderer
|
---|
25 | {
|
---|
26 | public:
|
---|
27 | /** Constructor for a deferred shader taking the requested output image size,
|
---|
28 | the current camera;
|
---|
29 | */
|
---|
30 | DeferredRenderer(int w, int h, PerspectiveCamera *cam);
|
---|
31 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
32 | 1 position buffer, and 1 normal buffer.
|
---|
33 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
34 | a smoothing factor for temporal coherence
|
---|
35 | */
|
---|
36 |
|
---|
37 | ~DeferredRenderer();
|
---|
38 |
|
---|
39 | void Render(FrameBufferObject *fbo,
|
---|
40 | float tempCohFactor,
|
---|
41 | DirectionalLight *light,
|
---|
42 | bool useToneMapping,
|
---|
43 | bool useAntiAliasing,
|
---|
44 | ShadowMap *shadowMap = NULL
|
---|
45 | );
|
---|
46 |
|
---|
47 |
|
---|
48 | void SetUseTemporalCoherence(bool temporal);
|
---|
49 |
|
---|
50 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
51 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
52 | /** Set the samplig method for the indirect illumination
|
---|
53 | */
|
---|
54 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
55 | /** Set the shading method (SSAO, SSAO + color bleeding
|
---|
56 | */
|
---|
57 | void SetShadingMethod(SHADING_METHOD s);
|
---|
58 |
|
---|
59 | void SetSortSamples(bool sortSamples) { mSortSamples = sortSamples; }
|
---|
60 |
|
---|
61 | // hack: store the color buffer idx for the currently used flip flop-MRT here
|
---|
62 | // TODO matt: make this less hacky
|
---|
63 | static int colorBufferIdx;
|
---|
64 |
|
---|
65 |
|
---|
66 | protected:
|
---|
67 |
|
---|
68 | void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
|
---|
69 |
|
---|
70 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
|
---|
71 |
|
---|
72 | void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
73 |
|
---|
74 | void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
|
---|
75 |
|
---|
76 | void ComputeToneParameters(FrameBufferObject *fbo,
|
---|
77 | DirectionalLight *light,
|
---|
78 | float &imageKey,
|
---|
79 | float &whiteLum,
|
---|
80 | float &middleGrey);
|
---|
81 |
|
---|
82 | void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
|
---|
83 |
|
---|
84 |
|
---|
85 | void CombineSsao(FrameBufferObject *fbo);
|
---|
86 | void CombineIllum(FrameBufferObject *fbo);
|
---|
87 |
|
---|
88 | void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
|
---|
89 | /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
|
---|
90 | resolution of fbo.
|
---|
91 | */
|
---|
92 | void DownSample(FrameBufferObject *fbo,
|
---|
93 | int bufferIdx,
|
---|
94 | FrameBufferObject *downSampleFbo,
|
---|
95 | int downSampleBufferIdx,
|
---|
96 | ShaderProgram *program);
|
---|
97 |
|
---|
98 | void DrawQuad(ShaderProgram *p);
|
---|
99 |
|
---|
100 | void Output(FrameBufferObject *fbo);
|
---|
101 |
|
---|
102 | /** Initialises the deferred shader and loads the required shaders:
|
---|
103 | This function has to be called only once.
|
---|
104 | */
|
---|
105 | void InitCg();
|
---|
106 | /** Is called once per render call and sets the most important parameters.
|
---|
107 | */
|
---|
108 | void InitFrame();
|
---|
109 |
|
---|
110 | void FlipFbos(FrameBufferObject *fbo);
|
---|
111 |
|
---|
112 | void PrepareSsao(FrameBufferObject *fbo);
|
---|
113 |
|
---|
114 | void SortSamples();
|
---|
115 |
|
---|
116 |
|
---|
117 | ////////////
|
---|
118 |
|
---|
119 | int mWidth;
|
---|
120 | int mHeight;
|
---|
121 |
|
---|
122 | PerspectiveCamera *mCamera;
|
---|
123 |
|
---|
124 | bool mUseTemporalCoherence;
|
---|
125 |
|
---|
126 | int mSamplingMethod;
|
---|
127 |
|
---|
128 | int mShadingMethod;
|
---|
129 |
|
---|
130 | bool mRegenerateSamples;
|
---|
131 |
|
---|
132 | int mIllumFboIndex;
|
---|
133 | // the fbo for indirect illumination (ssao + color bleeding)
|
---|
134 | FrameBufferObject *mIllumFbo;
|
---|
135 |
|
---|
136 | FrameBufferObject *mDownSampleFbo;
|
---|
137 |
|
---|
138 | FBOContainer mFBOs;
|
---|
139 |
|
---|
140 | static ShaderContainer sShaders;
|
---|
141 |
|
---|
142 | Matrix4x4 mProjViewMatrix;
|
---|
143 | Matrix4x4 mOldProjViewMatrix;
|
---|
144 |
|
---|
145 | Vector3 mCornersView[4];
|
---|
146 | Vector3 mOldCornersView[4];
|
---|
147 |
|
---|
148 | Vector3 mEyePos;
|
---|
149 | Vector3 mOldEyePos;
|
---|
150 |
|
---|
151 | bool mSortSamples;
|
---|
152 | };
|
---|
153 |
|
---|
154 |
|
---|
155 | } // namespace
|
---|
156 |
|
---|
157 | #endif // _SsaoShader_H__ |
---|