source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h @ 3175

Revision 3175, 3.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef _DEFERREDRENDERER_H__
2#define _DEFERREDRENDERER_H__
3
4#include "common.h"
5#include "Matrix4x4.h"
6#include "Vector3.h"
7
8namespace CHCDemoEngine
9{
10
11class FrameBufferObject;
12class Vector3;
13class PerspectiveCamera;
14class Matrix4x4;
15class ShadowMap;
16class 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*/
24class DeferredRenderer
25{
26public:
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        // hack: store the color buffer idx for the currently used flip flop-MRT here
60        // TODO matt: make this less hacky
61        static int colorBufferIdx;
62
63
64protected:
65
66        void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
67
68        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
69
70        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
71
72        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
73
74        void ComputeToneParameters(FrameBufferObject *fbo,
75                                                           DirectionalLight *light,
76                                                           float &imageKey,
77                                                           float &whiteLum,
78                                                           float &middleGrey);
79
80        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
81
82
83        void CombineSsao(FrameBufferObject *fbo);
84        void CombineIllum(FrameBufferObject *fbo);
85
86        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
87        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
88                resolution of fbo.
89        */
90        void DownSample(FrameBufferObject *fbo,
91                                        int bufferIdx,
92                                        FrameBufferObject *downSampleFbo,
93                                        int downSampleBufferIdx,
94                                        ShaderProgram *program);
95
96        void DrawQuad(ShaderProgram *p);
97
98        void Output(FrameBufferObject *fbo);
99
100        /** Initialises the deferred shader and loads the required shaders:
101                This function has to be called only once.
102        */
103        void InitCg();
104        /** Is called once per render call and sets the most important parameters.
105        */
106        void InitFrame();
107
108        void FlipFbos(FrameBufferObject *fbo);
109
110        void PrepareSsao(FrameBufferObject *fbo);
111
112        void SortSamples();
113
114
115        ////////////
116
117        int mWidth;
118        int mHeight;
119
120        PerspectiveCamera *mCamera;
121
122        bool mUseTemporalCoherence;
123
124        int mSamplingMethod;
125
126        int mShadingMethod;
127
128        bool mRegenerateSamples;
129
130        int mIllumFboIndex;
131        // the fbo for indirect illumination (ssao + color bleeding)
132        FrameBufferObject *mIllumFbo;
133
134        FrameBufferObject *mDownSampleFbo;
135
136        FBOContainer mFBOs;
137
138        static ShaderContainer sShaders;
139
140        Matrix4x4 mProjViewMatrix;
141        Matrix4x4 mOldProjViewMatrix;
142
143        Vector3 mCornersView[4];
144        Vector3 mOldCornersView[4];
145
146        Vector3 mEyePos;
147        Vector3 mOldEyePos;
148};
149
150
151} // namespace
152
153#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.