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

Revision 2994, 3.4 KB checked in by mattausch, 16 years ago (diff)

started to use a downsampling fbo

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 &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        void DownSample(FrameBufferObject *fbo);
94
95
96
97        ////////////
98
99        int mWidth;
100        int mHeight;
101
102        /// a scale factor of scene positions in order to get better float precision in the shader
103        float mScaleFactor;
104
105        Camera *mCamera;
106
107        bool mUseTemporalCoherence;
108
109        int mSamplingMethod;
110        int mFboIndex;
111
112        int mShadingMethod;
113
114        bool mRegenerateSamples;
115
116        // the main fbo we are working with
117        FrameBufferObject *mFbo;
118
119        FrameBufferObject *mDownSampleFbo;
120};
121
122} // namespace
123
124#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.