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

Revision 3213, 4.0 KB checked in by mattausch, 16 years ago (diff)

lense flare starting to work

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        void SetSortSamples(bool sortSamples) { mSortSamples = sortSamples; }
60
61        void SetSampleIntensity(float sampleIntensity);
62
63        void SetKernelRadius(float kernelRadius);
64
65
66        // hack: store the color buffer idx for the currently used flip flop-MRT here
67        // TODO matt: make this less hacky
68        static int colorBufferIdx;
69
70
71protected:
72
73        void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
74
75        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
76
77        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
78
79        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
80
81        void ComputeToneParameters(FrameBufferObject *fbo,
82                                                           DirectionalLight *light,
83                                                           float &imageKey,
84                                                           float &whiteLum,
85                                                           float &middleGrey);
86
87        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
88
89
90        void CombineSsao(FrameBufferObject *fbo);
91        void CombineIllum(FrameBufferObject *fbo);
92
93        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
94        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
95                resolution of fbo.
96        */
97        void DownSample(FrameBufferObject *fbo,
98                                        int bufferIdx,
99                                        FrameBufferObject *downSampleFbo,
100                                        int downSampleBufferIdx,
101                                        ShaderProgram *program);
102
103        void DrawQuad(ShaderProgram *p);
104
105        void Output(FrameBufferObject *fbo);
106
107        /** Initialises the deferred shader and loads the required shaders:
108                This function has to be called only once.
109        */
110        void InitCg();
111        /** Is called once per render call and sets the most important parameters.
112        */
113        void InitFrame();
114
115        void FlipFbos(FrameBufferObject *fbo);
116
117        void PrepareSsao(FrameBufferObject *fbo);
118
119        void SortSamples();
120
121        void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light);
122 
123
124        ////////////
125
126        int mWidth;
127        int mHeight;
128
129        PerspectiveCamera *mCamera;
130
131        bool mUseTemporalCoherence;
132
133        int mSamplingMethod;
134
135        int mShadingMethod;
136
137        bool mRegenerateSamples;
138
139        int mIllumFboIndex;
140        // the fbo for indirect illumination (ssao + color bleeding)
141        FrameBufferObject *mIllumFbo;
142
143        FrameBufferObject *mDownSampleFbo;
144
145        FBOContainer mFBOs;
146
147        static ShaderContainer sShaders;
148
149        Matrix4x4 mProjViewMatrix;
150        Matrix4x4 mOldProjViewMatrix;
151
152        Vector3 mCornersView[4];
153        Vector3 mOldCornersView[4];
154
155        Vector3 mEyePos;
156        Vector3 mOldEyePos;
157
158        bool mSortSamples;
159
160        float mKernelRadius;
161        float mSampleIntensity;
162};
163
164
165} // namespace
166
167#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.