1 | #ifndef _DeferredRenderer_H__
|
---|
2 | #define _DeferredRenderer_H__
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "glInterface.h"
|
---|
6 |
|
---|
7 | #include <Cg/cg.h>
|
---|
8 | #include <Cg/cgGL.h>
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace CHCDemoEngine
|
---|
12 | {
|
---|
13 |
|
---|
14 | class FrameBufferObject;
|
---|
15 | class Vector3;
|
---|
16 | class Camera;
|
---|
17 | class Matrix4x4;
|
---|
18 | class ShadowMap;
|
---|
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, and a scaling factor.
|
---|
29 |
|
---|
30 | The parameter scaleFactor must be reciprocal value of the
|
---|
31 | scale factor used for creating the positions texture. It is used recover the
|
---|
32 | exact scene size that was scaled in order to improve floating point precision.
|
---|
33 | */
|
---|
34 | DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
|
---|
35 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
36 | 1 position buffer, and 1 normal buffer.
|
---|
37 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
38 | a smoothing factor for temporal coherence
|
---|
39 | */
|
---|
40 | void Render(FrameBufferObject *fbo,
|
---|
41 | const Matrix4x4 &oldProjViewMatrix,
|
---|
42 | const Matrix4x4 &projViewMatrix,
|
---|
43 | float tempCohFactor,
|
---|
44 | ShadowMap *shadowMap = NULL);
|
---|
45 |
|
---|
46 | /** Initialises the deferred shader and loads the required shaders:
|
---|
47 | This function has to be called only once.
|
---|
48 | */
|
---|
49 | static void Init(CGcontext context);
|
---|
50 |
|
---|
51 | ~DeferredRenderer();
|
---|
52 |
|
---|
53 | void SetUseTemporalCoherence(bool temporal);
|
---|
54 |
|
---|
55 | enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
|
---|
56 | enum SHADING_METHOD {DEFAULT, SSAO, GI};
|
---|
57 |
|
---|
58 | void SetSamplingMethod(SAMPLING_METHOD s);
|
---|
59 |
|
---|
60 | void SetShadingMethod(SHADING_METHOD s);
|
---|
61 |
|
---|
62 | protected:
|
---|
63 |
|
---|
64 | void ComputeSsao(FrameBufferObject *fbo,
|
---|
65 | float tempCohFactor,
|
---|
66 | const Matrix4x4 &oldProjViewMatrix,
|
---|
67 | const Matrix4x4 &projViewMatrix);
|
---|
68 |
|
---|
69 | void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
70 |
|
---|
71 | void FirstPass(FrameBufferObject *fbo);
|
---|
72 |
|
---|
73 | void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);
|
---|
74 |
|
---|
75 | void CombineSsao(FrameBufferObject *fbo);
|
---|
76 | void CombineIllum(FrameBufferObject *fbo);
|
---|
77 |
|
---|
78 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
79 | /** Helper method that computes the view vectors in the corners of the current view frustum.
|
---|
80 | */
|
---|
81 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | ////////////
|
---|
86 |
|
---|
87 | int mWidth;
|
---|
88 | int mHeight;
|
---|
89 |
|
---|
90 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
91 | float mScaleFactor;
|
---|
92 |
|
---|
93 | Camera *mCamera;
|
---|
94 |
|
---|
95 | FrameBufferObject *mFbo;
|
---|
96 |
|
---|
97 | bool mUseTemporalCoherence;
|
---|
98 |
|
---|
99 | int mSamplingMethod;
|
---|
100 | int mFboIndex;
|
---|
101 |
|
---|
102 | int mShadingMethod;
|
---|
103 |
|
---|
104 | bool mRegenerateSamples;
|
---|
105 | };
|
---|
106 |
|
---|
107 | } // namespace
|
---|
108 |
|
---|
109 | #endif // _SsaoShader_H__ |
---|