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

Revision 2973, 3.3 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;
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 ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
78
79        void ToneMap(FrameBufferObject *fbo, DirectionalLight *light, float imageKey, float whiteLum, float middleGrey);
80
81
82        void CombineSsao(FrameBufferObject *fbo);
83        void CombineIllum(FrameBufferObject *fbo);
84
85        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
86        /** Helper method that computes the view vectors in the corners of the current view frustum.
87        */
88        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
89       
90        void DownSample(FrameBufferObject *fbo);
91
92
93
94        ////////////
95
96        int mWidth;
97        int mHeight;
98
99        /// a scale factor of scene positions in order to get better float precision in the shader
100        float mScaleFactor;
101
102        Camera *mCamera;
103
104        FrameBufferObject *mFbo;
105
106        bool mUseTemporalCoherence;
107
108        int mSamplingMethod;
109        int mFboIndex;
110
111        int mShadingMethod;
112
113        bool mRegenerateSamples;
114};
115
116} // namespace
117
118#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.