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

Revision 2896, 2.8 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, const Matrix4x4 &oldProjViewMatrix, float expFactor, ShadowMap *shadowMap = NULL);
41
42        /** Initialises the deferred shader and loads the required shaders:
43                This function has to be called only once.
44        */
45        static void Init(CGcontext context);
46
47        ~DeferredRenderer();
48
49        void SetUseTemporalCoherence(bool temporal);
50
51        enum SAMPLING_METHOD {POISSON, GAUSS};
52        enum SHADING_METHOD {DEFAULT, SSAO, GI};
53
54        void SetSamplingMethod(SAMPLING_METHOD s);
55
56        void SetShadingMethod(SHADING_METHOD s) { mShadingMethod = s; }
57
58protected:
59
60        void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
61
62        void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
63
64        void FirstPass(FrameBufferObject *fbo);
65
66        void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);
67
68        void CombineSsao(FrameBufferObject *fbo);
69        void CombineIllum(FrameBufferObject *fbo);
70
71        void AntiAliasing(FrameBufferObject *fbo);
72
73        /** Helper method that computes the view vectors in the corners of the current view frustum.
74        */
75        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
76
77
78        ////////////
79
80        int mWidth;
81        int mHeight;
82
83        /// this is just a scale factor for the scene depth in order to get better float precision in the shader
84        float mScaleFactor;
85
86        Camera *mCamera;
87
88        //FrameBufferObject *mOldFbo;
89        //FrameBufferObject *mNewFbo;
90        FrameBufferObject *mFbo;
91
92        bool mUseTemporalCoherence;
93
94        int mSamplingMethod;
95        int mFboIndex;
96
97        int mShadingMethod;
98
99        bool mRegenerateSamples;
100};
101
102} // namespace
103
104#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.