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

Revision 3068, 3.7 KB checked in by mattausch, 16 years ago (diff)

working on dynamic stuff again

Line 
1#ifndef _DEFERREDRENDERER_H__
2#define _DEFERREDRENDERER_H__
3
4#include "common.h"
5#include "glInterface.h"
6#include "ShaderProgram.h"
7
8#include <Cg/cg.h>
9#include <Cg/cgGL.h>
10
11
12namespace CHCDemoEngine
13{
14
15class FrameBufferObject;
16class Vector3;
17class PerspectiveCamera;
18class Matrix4x4;
19class ShadowMap;
20class DirectionalLight;
21
22
23
24
25/** This class implements a deferred shading algorithm that takes
26        a frame buffer object as input and outputs an image in the given size
27*/
28class DeferredRenderer
29{
30public:
31        /** Constructor for a deferred shader taking the requested output image size,
32                the current camera;
33        */
34        DeferredRenderer(int w, int h, PerspectiveCamera *cam);
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
41        ~DeferredRenderer();
42
43        void Render(FrameBufferObject *fbo,
44                        const Matrix4x4 &oldProjViewMatrix,
45                                const Matrix4x4 &projViewMatrix,
46                                float tempCohFactor,
47                                DirectionalLight *light,
48                                bool useToneMapping,
49                                ShadowMap *shadowMap = NULL
50                                );
51
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        /** Set the samplig method for the indirect illumination
58        */
59        void SetSamplingMethod(SAMPLING_METHOD s);
60        /** Set the shading method (SSAO, SSAO + color bleeding
61        */
62        void SetShadingMethod(SHADING_METHOD s);
63
64        // hack: store the color buffer idx for the currently used flip flop-MRT here
65        // TODO matt: make this less hacky
66        static int colorBufferIdx;
67
68
69protected:
70
71        void ComputeSsao(FrameBufferObject *fbo,
72                                         float tempCohFactor,
73                                         const Matrix4x4 &projViewMatrix,
74                                         const Matrix4x4 &oldProjViewMatrix
75                                         );
76
77        void ComputeGlobIllum(FrameBufferObject *fbo,
78                                  float tempCohFactor,
79                                                  const Matrix4x4 &projViewMatrix,
80                                                  const Matrix4x4 &oldProjViewMatrix);
81
82        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
83
84        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
85
86        void ComputeToneParameters(FrameBufferObject *fbo,
87                                                           DirectionalLight *light,
88                                                           float &imageKey,
89                                                           float &whiteLum,
90                                                           float &middleGrey);
91
92        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
93
94
95        void CombineSsao(FrameBufferObject *fbo);
96        void CombineIllum(FrameBufferObject *fbo);
97
98        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
99        /** Helper method that computes the view vectors in the corners of the current view frustum.
100        */
101        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
102
103        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
104                resolution of fbo.
105        */
106        void DownSample(FrameBufferObject *fbo, int bufferIdx,
107                                        FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
108
109        void DrawQuad(ShaderProgram *p);
110
111        /** Initialises the deferred shader and loads the required shaders:
112                This function has to be called only once.
113        */
114        void InitCg();
115
116
117        ////////////
118
119        int mWidth;
120        int mHeight;
121
122        PerspectiveCamera *mCamera;
123
124        bool mUseTemporalCoherence;
125
126        int mSamplingMethod;
127
128        int mShadingMethod;
129
130        bool mRegenerateSamples;
131
132        int mIllumFboIndex;
133        // the fbo for indirect illumination (ssao + color bleeding)
134        FrameBufferObject *mIllumFbo;
135
136        FrameBufferObject *mDownSampleFbo;
137
138        FBOContainer mFBOs;
139
140        static ShaderContainer sShaders;
141};
142
143
144} // namespace
145
146#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.