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

Revision 2928, 2.9 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 "glInterface.h"
6
7#include <Cg/cg.h>
8#include <Cg/cgGL.h>
9
10
11namespace CHCDemoEngine
12{
13
14class FrameBufferObject;
15class Vector3;
16class Camera;
17class Matrix4x4;
18class ShadowMap;
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 a scaling factor.
29                       
30                The parameter scaleFactor must be reciprocal value of the
31                scale factor used for creating the positions texture. It is used recover the
32                exact scene size that was scaled in order to improve floating point precision.
33        */
34        DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
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        void Render(FrameBufferObject *fbo,
41                        const Matrix4x4 &oldProjViewMatrix,
42                                const Matrix4x4 &projViewMatrix,
43                                float tempCohFactor,
44                                ShadowMap *shadowMap = NULL);
45
46        /** Initialises the deferred shader and loads the required shaders:
47                This function has to be called only once.
48        */
49        static void Init(CGcontext context);
50
51        ~DeferredRenderer();
52
53        void SetUseTemporalCoherence(bool temporal);
54
55        enum SAMPLING_METHOD {POISSON, GAUSS};
56        enum SHADING_METHOD {DEFAULT, SSAO, GI};
57
58        void SetSamplingMethod(SAMPLING_METHOD s);
59
60        void SetShadingMethod(SHADING_METHOD s);
61
62protected:
63
64        void ComputeSsao(FrameBufferObject *fbo,
65                                         float tempCohFactor,
66                                         const Matrix4x4 &oldProjViewMatrix,
67                                         const Matrix4x4 &projViewMatrix);
68
69        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
70
71        void FirstPass(FrameBufferObject *fbo);
72
73        void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);
74
75        void CombineSsao(FrameBufferObject *fbo);
76        void CombineIllum(FrameBufferObject *fbo);
77
78        void AntiAliasing(FrameBufferObject *fbo);
79
80        /** Helper method that computes the view vectors in the corners of the current view frustum.
81        */
82        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
83
84
85        void ShadowDebug(FrameBufferObject *fbo, ShadowMap *shadowMap);
86
87
88        ////////////
89
90        int mWidth;
91        int mHeight;
92
93        /// this is just a scale factor for the scene depth in order to get better float precision in the shader
94        float mScaleFactor;
95
96        Camera *mCamera;
97
98        FrameBufferObject *mFbo;
99
100        bool mUseTemporalCoherence;
101
102        int mSamplingMethod;
103        int mFboIndex;
104
105        int mShadingMethod;
106
107        bool mRegenerateSamples;
108};
109
110} // namespace
111
112#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.