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

Revision 3305, 6.1 KB checked in by mattausch, 15 years ago (diff)

removed filter radius

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, and if the ssao should be full or half resolution
29        */
30        DeferredRenderer(int w, int h, PerspectiveCamera *cam, bool ssaoUsefulResolution);
31        /** Destructor
32        */
33        ~DeferredRenderer();
34        /** The main render function
35            Currently our fbo consists of one combined color + depth buffer, a normal buffer,
36                and a buffer holding the difference of the pixel positions from the last frame.
37
38                If a shadowMap is specified that is not NULL, the shadow mapped shading algorithm is applied.
39        */
40        void Render(FrameBufferObject *fbo,
41                                DirectionalLight *light,
42                                ShadowMap *shadowMap = NULL
43                                );
44
45       
46        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
47        /** Use ssao or ssao + color bleeding
48        */
49        enum SHADING_METHOD {DEFAULT, SSAO, GI};
50        /** Set the samplig method for the indirect illumination
51        */
52        void SetSamplingMethod(SAMPLING_METHOD s);
53        /** Set the shading method (SSAO, SSAO + color bleeding
54        */
55        void SetShadingMethod(SHADING_METHOD s);
56        /** Sort the samples in order to provide faster texture accesses.
57        */
58        //void SetSortSamples(bool sortSamples);
59        /** Sets ssao sample intensity.
60        */
61        void SetSampleIntensity(float sampleIntensity);
62        /** Sets ssao kernel radius.
63        */
64        void SetKernelRadius(float kernelRadius);
65        /** Passes the number of pixels that are visible from the sun.
66        */
67        void SetSunVisiblePixels(int visiblePixels);
68        /** If true temporal coherence is used for ssao
69        */
70        void SetUseTemporalCoherence(bool temporal);
71        /** if set to something other than -1 the current frame is stored on disc
72                using the specified frame number
73        */
74        void SetSaveFrame(const std::string &suffix, int frameNumber);
75        /** Sets the maximal visible distance.
76        */
77        void SetMaxDistance(float maxDist);
78        /**     Enables / disables toneMapping
79        */
80        void SetUseToneMapping(bool toneMapping);
81       
82        /** Enable antiAliasing if some basic edge antialiasing should be performed
83        */
84        void SetUseAntiAliasing(bool antiAliasing);
85        /** Enables / disables depth of field.
86        */
87        void SetUseDepthOfField(bool dof);
88        /**
89                The temporal coherence factor is the maximal number of ssao samples that are accumulated
90                without losing any prior sample information.
91                Set this number too low and flickering can be seen, too
92                high and the adaption to some changes in the ssao might be too slow. Usually from about
93                1000 samples a flickering cannot be seen.
94        */
95        void SetTemporalCoherenceFactorForSsao(float factor);
96
97
98        // hack: store the color buffer idx for the currently used flip flop-MRT here
99        // TODO matt: make this less hacky
100        static int colorBufferIdx;
101
102
103protected:
104
105        void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
106
107        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
108
109        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
110
111        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
112
113        void ComputeToneParameters(FrameBufferObject *fbo,
114                                                           DirectionalLight *light,
115                                                           float &imageKey,
116                                                           float &whiteLum,
117                                                           float &middleGrey);
118
119        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
120
121
122        void CombineSsao(FrameBufferObject *fbo);
123
124        void CombineIllum(FrameBufferObject *fbo);
125        /** Does some basic antialiasing (searches for edges using a edge detector,
126                smoothes these edges.
127                This function is usually the last function in the pipeline,
128                so one can specify if the frame should be put out directly or stored to
129                another texture.
130        */
131        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light, bool displayFrame = true);
132        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
133                resolution of fbo.
134        */
135        void DownSample(FrameBufferObject *fbo,
136                                        int bufferIdx,
137                                        FrameBufferObject *downSampleFbo,
138                                        int downSampleBufferIdx,
139                                        ShaderProgram *program);
140
141        void DrawQuad(ShaderProgram *p);
142
143        void Output(FrameBufferObject *fbo);
144
145        /** Initialises the deferred shader and loads the required shaders:
146                This function has to be called only once.
147        */
148        void InitCg();
149        /** Is called once per render call and sets the most important parameters.
150        */
151        void InitFrame();
152
153        void FlipFbos(FrameBufferObject *fbo);
154
155        void PrepareSsao(FrameBufferObject *fbo);
156
157        void SortSamples();
158
159        void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light);
160
161        void SaveFrame(FrameBufferObject *fbo);
162
163        void DepthOfField(FrameBufferObject *fbo);
164
165        void FilterSsao(FrameBufferObject *fbo);
166
167
168        ////////////
169
170        /// deferred shading output image width
171        int mWidth;
172        /// deferred shading output image height
173        int mHeight;
174
175        //////////////////
176
177
178        PerspectiveCamera *mCamera;
179
180        bool mUseTemporalCoherence;
181
182        int mSamplingMethod;
183
184        int mShadingMethod;
185
186        bool mRegenerateSamples;
187
188        int mIllumFboIndex;
189        /// the fbo for indirect illumination (ssao + color bleeding)
190        FrameBufferObject *mIllumFbo;
191
192        FrameBufferObject *mDownSampleFbo;
193        FrameBufferObject *mTempFbo;
194
195        FBOContainer mFBOs;
196
197        Matrix4x4 mProjViewMatrix;
198        Matrix4x4 mOldProjViewMatrix;
199
200        Vector3 mCornersView[4];
201        Vector3 mOldCornersView[4];
202
203        Vector3 mEyePos;
204        Vector3 mOldEyePos;
205
206        bool mSortSamples;
207
208        float mKernelRadius;
209        float mSampleIntensity;
210
211        int mSunVisiblePixels;
212
213        int mSavedFrameNumber;
214        std::string mSavedFrameSuffix;
215
216        float mMaxDistance;
217
218        float mTempCohFactor;
219        bool mUseToneMapping;
220        bool mUseAntiAliasing;
221        bool mUseDepthOfField;
222
223        bool mSsaoUseFullResolution;
224};
225
226
227} // namespace
228
229#endif // _SSAOSHADER_H__
Note: See TracBrowser for help on using the repository browser.