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

Revision 3085, 3.5 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                                ShadowMap *shadowMap = NULL
44                                );
45
46       
47        void SetUseTemporalCoherence(bool temporal);
48
49        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
50        enum SHADING_METHOD {DEFAULT, SSAO, GI};
51        /** Set the samplig method for the indirect illumination
52        */
53        void SetSamplingMethod(SAMPLING_METHOD s);
54        /** Set the shading method (SSAO, SSAO + color bleeding
55        */
56        void SetShadingMethod(SHADING_METHOD s);
57
58        // hack: store the color buffer idx for the currently used flip flop-MRT here
59        // TODO matt: make this less hacky
60        static int colorBufferIdx;
61
62
63protected:
64
65        void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
66
67        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
68
69        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
70
71        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
72
73        void ComputeToneParameters(FrameBufferObject *fbo,
74                                                           DirectionalLight *light,
75                                                           float &imageKey,
76                                                           float &whiteLum,
77                                                           float &middleGrey);
78
79        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
80
81
82        void CombineSsao(FrameBufferObject *fbo);
83        void CombineIllum(FrameBufferObject *fbo);
84
85        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
86        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
87                resolution of fbo.
88        */
89        void DownSample(FrameBufferObject *fbo, int bufferIdx,
90                                        FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
91
92        void DrawQuad(ShaderProgram *p);
93
94        /** Initialises the deferred shader and loads the required shaders:
95                This function has to be called only once.
96        */
97        void InitCg();
98        /** Is called once per render call and sets the most important parameters.
99        */
100        void InitFrame();
101
102
103        ////////////
104
105        int mWidth;
106        int mHeight;
107
108        PerspectiveCamera *mCamera;
109
110        bool mUseTemporalCoherence;
111
112        int mSamplingMethod;
113
114        int mShadingMethod;
115
116        bool mRegenerateSamples;
117
118        int mIllumFboIndex;
119        // the fbo for indirect illumination (ssao + color bleeding)
120        FrameBufferObject *mIllumFbo;
121
122        FrameBufferObject *mDownSampleFbo;
123
124        FBOContainer mFBOs;
125
126        static ShaderContainer sShaders;
127
128        Matrix4x4 mProjViewMatrix;
129        Matrix4x4 mOldProjViewMatrix;
130
131        Vector3 mCornersView[4];
132        Vector3 mOldCornersView[4];
133
134        Vector3 mEyePos;
135        Vector3 mOldEyePos;
136};
137
138
139} // namespace
140
141#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.