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

Revision 3021, 3.7 KB checked in by mattausch, 16 years ago (diff)

removed leaks. added class for shaders

RevLine 
[2952]1#ifndef _DEFERREDRENDERER_H__
2#define _DEFERREDRENDERER_H__
[2858]3
4#include "common.h"
[2859]5#include "glInterface.h"
[3021]6#include "ShaderProgram.h"
[2896]7
[2859]8#include <Cg/cg.h>
9#include <Cg/cgGL.h>
[2858]10
[2859]11
[2858]12namespace CHCDemoEngine
13{
14
15class FrameBufferObject;
[2860]16class Vector3;
17class Camera;
[2861]18class Matrix4x4;
[2896]19class ShadowMap;
[2952]20class DirectionalLight;
[2858]21
[2896]22
[3019]23
24typedef  std::vector<FrameBufferObject *> FBOContainer;
25
[2859]26/** This class implements a deferred shading algorithm that takes
27        a frame buffer object as input and outputs an image in the given size
[2858]28*/
[2896]29class DeferredRenderer
[2858]30{
31public:
[2874]32        /** Constructor for a deferred shader taking the requested output image size,
[2861]33                the current camera,     and a scaling factor.
[2860]34                       
35                The parameter scaleFactor must be reciprocal value of the
[2952]36                scale factor used for creating the world space position texture. It is used recover the
[2860]37                exact scene size that was scaled in order to improve floating point precision.
[2858]38        */
[2896]39        DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
[2874]40        /** The algorithm renders the scene given an fbo consists of 1 color buffer,
[2861]41                1 position buffer, and 1 normal buffer.
42                We also need the  projection view matrix of the last frame for reprojection, and
43                a smoothing factor for temporal coherence
[2858]44        */
[3021]45
46        ~DeferredRenderer();
47
[2900]48        void Render(FrameBufferObject *fbo,
49                        const Matrix4x4 &oldProjViewMatrix,
50                                const Matrix4x4 &projViewMatrix,
[2901]51                                float tempCohFactor,
[2952]52                                DirectionalLight *light,
[2991]53                                bool useToneMapping,
54                                ShadowMap *shadowMap = NULL
55                                );
[2859]56
[3021]57       
[2875]58        void SetUseTemporalCoherence(bool temporal);
[2874]59
[2930]60        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
[2896]61        enum SHADING_METHOD {DEFAULT, SSAO, GI};
[2875]62
[2896]63        void SetSamplingMethod(SAMPLING_METHOD s);
[2887]64
[2897]65        void SetShadingMethod(SHADING_METHOD s);
[3021]66       
67        /** Initialises the deferred shader and loads the required shaders:
68                This function has to be called only once.
69        */
70        static void InitCG(CGcontext context);
71        /** Releases all shader resources.
72        */
73        static void ReleaseCG();
74
[2976]75        static int colorBufferIdx;
[2887]76
[2859]77protected:
78
[2928]79        void ComputeSsao(FrameBufferObject *fbo,
80                                         float tempCohFactor,
81                                         const Matrix4x4 &oldProjViewMatrix,
82                                         const Matrix4x4 &projViewMatrix);
[2859]83
[3006]84        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &projViewMatrix, const Matrix4x4 &oldProjViewMatrix);
[2873]85
[2952]86        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
[2868]87
[2952]88        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
[2896]89
[2973]90        void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
[2972]91
[3007]92        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
[2972]93
[2973]94
[2880]95        void CombineSsao(FrameBufferObject *fbo);
96        void CombineIllum(FrameBufferObject *fbo);
97
[2970]98        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
[2889]99        /** Helper method that computes the view vectors in the corners of the current view frustum.
100        */
[2861]101        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
[2859]102
[3006]103        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
104                resolution of fbo.
105        */
106        void DownSample(FrameBufferObject *fbo, int bufferIdx,
107                                        FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
[2972]108
109
[2859]110        ////////////
111
112        int mWidth;
113        int mHeight;
114
[2860]115        Camera *mCamera;
116
[2875]117        bool mUseTemporalCoherence;
[2887]118
[2896]119        int mSamplingMethod;
120
121        int mShadingMethod;
122
123        bool mRegenerateSamples;
[2976]124
[3019]125        int mIllumFboIndex;
126        // the fbo for indirect illumination (ssao + color bleeding)
127        FrameBufferObject *mIllumFbo;
[2994]128
129        FrameBufferObject *mDownSampleFbo;
[3019]130
131        FBOContainer mFBOs;
132
133        static ShaderContainer sShaders;
[2858]134};
135
136} // namespace
[2886]137
[2859]138#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.