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

Revision 3006, 3.6 KB checked in by mattausch, 16 years ago (diff)

tried downsampling

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                                bool useToneMapping,
47                                ShadowMap *shadowMap = NULL
48                                );
49
50        /** Initialises the deferred shader and loads the required shaders:
51                This function has to be called only once.
52        */
53        static void Init(CGcontext context);
54
55        ~DeferredRenderer();
56
57        void SetUseTemporalCoherence(bool temporal);
58
59        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
60        enum SHADING_METHOD {DEFAULT, SSAO, GI};
61
62        void SetSamplingMethod(SAMPLING_METHOD s);
63
64        void SetShadingMethod(SHADING_METHOD s);
65        static int colorBufferIdx;
66
67protected:
68
69        void ComputeSsao(FrameBufferObject *fbo,
70                                         float tempCohFactor,
71                                         const Matrix4x4 &oldProjViewMatrix,
72                                         const Matrix4x4 &projViewMatrix);
73
74        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &projViewMatrix, const Matrix4x4 &oldProjViewMatrix);
75
76        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
77
78        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
79
80        void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
81
82        void ToneMap(FrameBufferObject *fbo, DirectionalLight *light, float imageKey, float whiteLum, float middleGrey);
83
84
85        void CombineSsao(FrameBufferObject *fbo);
86        void CombineIllum(FrameBufferObject *fbo);
87
88        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
89        /** Helper method that computes the view vectors in the corners of the current view frustum.
90        */
91        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
92
93        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
94                resolution of fbo.
95        */
96        void DownSample(FrameBufferObject *fbo, int bufferIdx,
97                                        FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
98
99
100        ////////////
101
102        int mWidth;
103        int mHeight;
104
105        /// a scale factor of scene positions in order to get better float precision in the shader
106        float mScaleFactor;
107
108        Camera *mCamera;
109
110        bool mUseTemporalCoherence;
111
112        int mSamplingMethod;
113        int mFboIndex;
114
115        int mShadingMethod;
116
117        bool mRegenerateSamples;
118
119        // the main fbo we are working with
120        FrameBufferObject *mFbo;
121
122        FrameBufferObject *mDownSampleFbo;
123};
124
125} // namespace
126
127#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.