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

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

removed leaks. added class for shaders

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 Camera;
18class Matrix4x4;
19class ShadowMap;
20class DirectionalLight;
21
22
23
24typedef  std::vector<FrameBufferObject *> FBOContainer;
25
26/** This class implements a deferred shading algorithm that takes
27        a frame buffer object as input and outputs an image in the given size
28*/
29class DeferredRenderer
30{
31public:
32        /** Constructor for a deferred shader taking the requested output image size,
33                the current camera,     and a scaling factor.
34                       
35                The parameter scaleFactor must be reciprocal value of the
36                scale factor used for creating the world space position texture. It is used recover the
37                exact scene size that was scaled in order to improve floating point precision.
38        */
39        DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
40        /** The algorithm renders the scene given an fbo consists of 1 color buffer,
41                1 position buffer, and 1 normal buffer.
42                We also need the  projection view matrix of the last frame for reprojection, and
43                a smoothing factor for temporal coherence
44        */
45
46        ~DeferredRenderer();
47
48        void Render(FrameBufferObject *fbo,
49                        const Matrix4x4 &oldProjViewMatrix,
50                                const Matrix4x4 &projViewMatrix,
51                                float tempCohFactor,
52                                DirectionalLight *light,
53                                bool useToneMapping,
54                                ShadowMap *shadowMap = NULL
55                                );
56
57       
58        void SetUseTemporalCoherence(bool temporal);
59
60        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
61        enum SHADING_METHOD {DEFAULT, SSAO, GI};
62
63        void SetSamplingMethod(SAMPLING_METHOD s);
64
65        void SetShadingMethod(SHADING_METHOD s);
66       
67        /** Initialises the deferred shader and loads the required shaders:
68                This function has to be called only once.
69        */
70        static void InitCG(CGcontext context);
71        /** Releases all shader resources.
72        */
73        static void ReleaseCG();
74
75        static int colorBufferIdx;
76
77protected:
78
79        void ComputeSsao(FrameBufferObject *fbo,
80                                         float tempCohFactor,
81                                         const Matrix4x4 &oldProjViewMatrix,
82                                         const Matrix4x4 &projViewMatrix);
83
84        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &projViewMatrix, const Matrix4x4 &oldProjViewMatrix);
85
86        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
87
88        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
89
90        void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, 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
110        ////////////
111
112        int mWidth;
113        int mHeight;
114
115        Camera *mCamera;
116
117        bool mUseTemporalCoherence;
118
119        int mSamplingMethod;
120
121        int mShadingMethod;
122
123        bool mRegenerateSamples;
124
125        int mIllumFboIndex;
126        // the fbo for indirect illumination (ssao + color bleeding)
127        FrameBufferObject *mIllumFbo;
128
129        FrameBufferObject *mDownSampleFbo;
130
131        FBOContainer mFBOs;
132
133        static ShaderContainer sShaders;
134};
135
136} // namespace
137
138#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.