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

Revision 2965, 2.9 KB checked in by mattausch, 16 years ago (diff)

removed dirttexture stuff. started tonemapping stuff

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;
19class DirectionalLight;
20
21
22/** This class implements a deferred shading algorithm that takes
23        a frame buffer object as input and outputs an image in the given size
24*/
25class DeferredRenderer
26{
27public:
28        /** Constructor for a deferred shader taking the requested output image size,
29                the current camera,     and a scaling factor.
30                       
31                The parameter scaleFactor must be reciprocal value of the
32                scale factor used for creating the world space position texture. It is used recover the
33                exact scene size that was scaled in order to improve floating point precision.
34        */
35        DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
36        /** The algorithm renders the scene given an fbo consists of 1 color buffer,
37                1 position buffer, and 1 normal buffer.
38                We also need the  projection view matrix of the last frame for reprojection, and
39                a smoothing factor for temporal coherence
40        */
41        void Render(FrameBufferObject *fbo,
42                        const Matrix4x4 &oldProjViewMatrix,
43                                const Matrix4x4 &projViewMatrix,
44                                float tempCohFactor,
45                                DirectionalLight *light,
46                                ShadowMap *shadowMap = NULL);
47
48        /** Initialises the deferred shader and loads the required shaders:
49                This function has to be called only once.
50        */
51        static void Init(CGcontext context);
52
53        ~DeferredRenderer();
54
55        void SetUseTemporalCoherence(bool temporal);
56
57        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
58        enum SHADING_METHOD {DEFAULT, SSAO, GI};
59
60        void SetSamplingMethod(SAMPLING_METHOD s);
61
62        void SetShadingMethod(SHADING_METHOD s);
63
64protected:
65
66        void ComputeSsao(FrameBufferObject *fbo,
67                                         float tempCohFactor,
68                                         const Matrix4x4 &oldProjViewMatrix,
69                                         const Matrix4x4 &projViewMatrix);
70
71        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
72
73        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
74
75        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
76
77        void CombineSsao(FrameBufferObject *fbo);
78        void CombineIllum(FrameBufferObject *fbo);
79
80        void AntiAliasing(FrameBufferObject *fbo);
81        /** Helper method that computes the view vectors in the corners of the current view frustum.
82        */
83        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
84       
85
86        ////////////
87
88        int mWidth;
89        int mHeight;
90
91        /// a scale factor of scene positions in order to get better float precision in the shader
92        float mScaleFactor;
93
94        Camera *mCamera;
95
96        FrameBufferObject *mFbo;
97
98        bool mUseTemporalCoherence;
99
100        int mSamplingMethod;
101        int mFboIndex;
102
103        int mShadingMethod;
104
105        bool mRegenerateSamples;
106};
107
108} // namespace
109
110#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.