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

Revision 3027, 4.0 KB checked in by mattausch, 16 years ago (diff)

implemented shader program wrapper

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,
[3027]81                                         const Matrix4x4 &projViewMatrix,
82                                         const Matrix4x4 &oldProjViewMatrix
83                                         );
[2859]84
[3027]85        void ComputeGlobIllum(FrameBufferObject *fbo,
86                                  float tempCohFactor,
87                                                  const Matrix4x4 &projViewMatrix,
88                                                  const Matrix4x4 &oldProjViewMatrix);
[2873]89
[2952]90        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
[2868]91
[2952]92        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
[2896]93
[2973]94        void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
[2972]95
[3007]96        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
[2972]97
[2973]98
[2880]99        void CombineSsao(FrameBufferObject *fbo);
100        void CombineIllum(FrameBufferObject *fbo);
101
[2970]102        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
[2889]103        /** Helper method that computes the view vectors in the corners of the current view frustum.
104        */
[2861]105        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
[2859]106
[3006]107        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
108                resolution of fbo.
109        */
110        void DownSample(FrameBufferObject *fbo, int bufferIdx,
111                                        FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
[2972]112
[3026]113        void DrawQuad(ShaderProgram *p);
[2972]114
[3026]115        static bool InitProgram(ShaderProgram **program,
116                                    CGcontext context,
117                                                        const std::string &filename,
118                                                        const std::string &functionName);
119
120
[2859]121        ////////////
122
123        int mWidth;
124        int mHeight;
125
[2860]126        Camera *mCamera;
127
[2875]128        bool mUseTemporalCoherence;
[2887]129
[2896]130        int mSamplingMethod;
131
132        int mShadingMethod;
133
134        bool mRegenerateSamples;
[2976]135
[3019]136        int mIllumFboIndex;
137        // the fbo for indirect illumination (ssao + color bleeding)
138        FrameBufferObject *mIllumFbo;
[2994]139
140        FrameBufferObject *mDownSampleFbo;
[3019]141
142        FBOContainer mFBOs;
143
144        static ShaderContainer sShaders;
[2858]145};
146
147} // namespace
[2886]148
[2859]149#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.