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

Revision 3038, 3.8 KB checked in by mattausch, 16 years ago (diff)

unified shader stuff, but phreetham sky not working anymore for forward rendering

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