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

Revision 3216, 5.1 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[2952]1#ifndef _DEFERREDRENDERER_H__
2#define _DEFERREDRENDERER_H__
[2858]3
4#include "common.h"
[3085]5#include "Matrix4x4.h"
6#include "Vector3.h"
[2896]7
[2858]8namespace CHCDemoEngine
9{
10
11class FrameBufferObject;
[2860]12class Vector3;
[3062]13class PerspectiveCamera;
[2861]14class Matrix4x4;
[2896]15class ShadowMap;
[2952]16class DirectionalLight;
[2858]17
[2896]18
[3019]19
20
[2859]21/** This class implements a deferred shading algorithm that takes
22        a frame buffer object as input and outputs an image in the given size
[2858]23*/
[2896]24class DeferredRenderer
[2858]25{
26public:
[2874]27        /** Constructor for a deferred shader taking the requested output image size,
[3216]28                the current camera, and if the ssao should be full or half resolution
[2858]29        */
[3216]30        DeferredRenderer(int w, int h, PerspectiveCamera *cam, bool ssaoUsefulResolution);
31        /** Destructor
[2858]32        */
[3021]33        ~DeferredRenderer();
[3216]34        /** The main render function
35            Currently our fbo consists of one combined color + depth buffer, a normal buffer,
36                and a buffer holding the difference of the pixel positions from the last frame.
[3021]37
[3216]38                Set useToneMapping to true if tone mapping should be applied
39                Set useAntiAliasing true if some basic edge antialiasing should be performed
40                If a shadowMap is specified that is not NULL, the shadow mapped shading algorithm is applied.
41
42                The temporal coherence factor is the maximal number of ssao samples that are accumulated
43                without losing any prior sample information.
44                Set this number too low and flickering can be seen, too
45                high and the adaption to some changes in the ssao might be too slow. Usually from about
46                1000 samples a flickering cannot be seen.
47        */
[2900]48        void Render(FrameBufferObject *fbo,
[2901]49                                float tempCohFactor,
[2952]50                                DirectionalLight *light,
[2991]51                                bool useToneMapping,
[3175]52                                bool useAntiAliasing,
[2991]53                                ShadowMap *shadowMap = NULL
54                                );
[2859]55
[3021]56       
[2930]57        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
[3216]58        /** Use ssao or ssao + color bleeding
59        */
[2896]60        enum SHADING_METHOD {DEFAULT, SSAO, GI};
[3068]61        /** Set the samplig method for the indirect illumination
62        */
[2896]63        void SetSamplingMethod(SAMPLING_METHOD s);
[3068]64        /** Set the shading method (SSAO, SSAO + color bleeding
65        */
[2897]66        void SetShadingMethod(SHADING_METHOD s);
[3216]67        /** Sort the samples so texture access is faster
68        */
[3215]69        void SetSortSamples(bool sortSamples);
[3216]70        /** Sets ssao sample intensity.
71        */
[3212]72        void SetSampleIntensity(float sampleIntensity);
[3216]73        /** Sets ssao kernel radius.
74        */
[3212]75        void SetKernelRadius(float kernelRadius);
[3216]76        /** Sets ssao filter radius.
77        */
78        void SetSsaoFilterRadius(float radius);
[3215]79        /** Sets the number of visible pixels of the sun
80        */
81        void SetSunVisiblePixels(int visiblePixels);
[3216]82        /** If true tem poral coherence is used for ssao
83        */
84        void SetUseTemporalCoherence(bool temporal);
[3212]85
86
[3068]87        // hack: store the color buffer idx for the currently used flip flop-MRT here
[3038]88        // TODO matt: make this less hacky
[2976]89        static int colorBufferIdx;
[2887]90
[3038]91
[2859]92protected:
93
[3085]94        void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor);
[2859]95
[3085]96        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor);
[2873]97
[2952]98        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
[2868]99
[2952]100        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
[2896]101
[3038]102        void ComputeToneParameters(FrameBufferObject *fbo,
103                                                           DirectionalLight *light,
104                                                           float &imageKey,
105                                                           float &whiteLum,
106                                                           float &middleGrey);
[2972]107
[3007]108        void ToneMap(FrameBufferObject *fbo, float imageKey, float whiteLum, float middleGrey);
[2972]109
[2973]110
[2880]111        void CombineSsao(FrameBufferObject *fbo);
112        void CombineIllum(FrameBufferObject *fbo);
113
[2970]114        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
[3006]115        /** Downsample buffer of fbo to buffer of downSampleFbo. The downSampleFbo must have half the
116                resolution of fbo.
117        */
[3137]118        void DownSample(FrameBufferObject *fbo,
119                                        int bufferIdx,
120                                        FrameBufferObject *downSampleFbo,
121                                        int downSampleBufferIdx,
122                                        ShaderProgram *program);
[2972]123
[3026]124        void DrawQuad(ShaderProgram *p);
[2972]125
[3132]126        void Output(FrameBufferObject *fbo);
127
[3038]128        /** Initialises the deferred shader and loads the required shaders:
129                This function has to be called only once.
130        */
131        void InitCg();
[3085]132        /** Is called once per render call and sets the most important parameters.
133        */
134        void InitFrame();
[3026]135
[3132]136        void FlipFbos(FrameBufferObject *fbo);
[3026]137
[3155]138        void PrepareSsao(FrameBufferObject *fbo);
[3132]139
[3167]140        void SortSamples();
[3155]141
[3213]142        void LenseFlare(FrameBufferObject *fbo, DirectionalLight *light);
143 
[3216]144        void PrepareSsaoFilter();
[3155]145
[3216]146
[2859]147        ////////////
148
[3215]149        /// deferred shading output image width
[2859]150        int mWidth;
[3215]151        /// deferred shading output image height
[2859]152        int mHeight;
153
[3216]154        //////////////////
155
156
[3062]157        PerspectiveCamera *mCamera;
[2860]158
[2875]159        bool mUseTemporalCoherence;
[2887]160
[2896]161        int mSamplingMethod;
162
163        int mShadingMethod;
164
165        bool mRegenerateSamples;
[2976]166
[3019]167        int mIllumFboIndex;
[3215]168        /// the fbo for indirect illumination (ssao + color bleeding)
[3019]169        FrameBufferObject *mIllumFbo;
[2994]170
171        FrameBufferObject *mDownSampleFbo;
[3019]172
173        FBOContainer mFBOs;
174
[3085]175        Matrix4x4 mProjViewMatrix;
176        Matrix4x4 mOldProjViewMatrix;
177
178        Vector3 mCornersView[4];
179        Vector3 mOldCornersView[4];
180
181        Vector3 mEyePos;
182        Vector3 mOldEyePos;
[3189]183
184        bool mSortSamples;
[3212]185
186        float mKernelRadius;
[3216]187        float mSsaoFilterRadius;
[3212]188        float mSampleIntensity;
[3215]189
190        int mSunVisiblePixels;
[2858]191};
192
[3038]193
[2858]194} // namespace
[2886]195
[2859]196#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.