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

Revision 2976, 3.3 KB checked in by mattausch, 16 years ago (diff)

cannot read mipmap, but stayed on gpu

RevLine 
[2952]1#ifndef _DEFERREDRENDERER_H__
2#define _DEFERREDRENDERER_H__
[2858]3
4#include "common.h"
[2859]5#include "glInterface.h"
[2896]6
[2859]7#include <Cg/cg.h>
8#include <Cg/cgGL.h>
[2858]9
[2859]10
[2858]11namespace CHCDemoEngine
12{
13
14class FrameBufferObject;
[2860]15class Vector3;
16class Camera;
[2861]17class Matrix4x4;
[2896]18class ShadowMap;
[2952]19class DirectionalLight;
[2858]20
[2896]21
[2859]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
[2858]24*/
[2896]25class DeferredRenderer
[2858]26{
27public:
[2874]28        /** Constructor for a deferred shader taking the requested output image size,
[2861]29                the current camera,     and a scaling factor.
[2860]30                       
31                The parameter scaleFactor must be reciprocal value of the
[2952]32                scale factor used for creating the world space position texture. It is used recover the
[2860]33                exact scene size that was scaled in order to improve floating point precision.
[2858]34        */
[2896]35        DeferredRenderer(int w, int h, Camera *cam, float scaleFactor);
[2874]36        /** The algorithm renders the scene given an fbo consists of 1 color buffer,
[2861]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
[2858]40        */
[2900]41        void Render(FrameBufferObject *fbo,
42                        const Matrix4x4 &oldProjViewMatrix,
43                                const Matrix4x4 &projViewMatrix,
[2901]44                                float tempCohFactor,
[2952]45                                DirectionalLight *light,
[2900]46                                ShadowMap *shadowMap = NULL);
[2859]47
48        /** Initialises the deferred shader and loads the required shaders:
49                This function has to be called only once.
50        */
51        static void Init(CGcontext context);
52
[2896]53        ~DeferredRenderer();
[2859]54
[2875]55        void SetUseTemporalCoherence(bool temporal);
[2874]56
[2930]57        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT};
[2896]58        enum SHADING_METHOD {DEFAULT, SSAO, GI};
[2875]59
[2896]60        void SetSamplingMethod(SAMPLING_METHOD s);
[2887]61
[2897]62        void SetShadingMethod(SHADING_METHOD s);
[2976]63        static int colorBufferIdx;
[2887]64
[2859]65protected:
66
[2928]67        void ComputeSsao(FrameBufferObject *fbo,
68                                         float tempCohFactor,
69                                         const Matrix4x4 &oldProjViewMatrix,
70                                         const Matrix4x4 &projViewMatrix);
[2859]71
[2901]72        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
[2873]73
[2952]74        void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
[2868]75
[2952]76        void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
[2896]77
[2973]78        void ComputeToneParameters(FrameBufferObject *fbo, DirectionalLight *light, float &imageKey, float &whiteLum, float &middleGrey);
[2972]79
[2973]80        void ToneMap(FrameBufferObject *fbo, DirectionalLight *light, float imageKey, float whiteLum, float middleGrey);
[2972]81
[2973]82
[2880]83        void CombineSsao(FrameBufferObject *fbo);
84        void CombineIllum(FrameBufferObject *fbo);
85
[2970]86        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
[2889]87        /** Helper method that computes the view vectors in the corners of the current view frustum.
88        */
[2861]89        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
[2965]90       
[2972]91        void DownSample(FrameBufferObject *fbo);
[2859]92
[2972]93
94
[2859]95        ////////////
96
97        int mWidth;
98        int mHeight;
99
[2957]100        /// a scale factor of scene positions in order to get better float precision in the shader
[2859]101        float mScaleFactor;
[2860]102
103        Camera *mCamera;
104
[2891]105        FrameBufferObject *mFbo;
[2875]106
107        bool mUseTemporalCoherence;
[2887]108
[2896]109        int mSamplingMethod;
[2891]110        int mFboIndex;
[2896]111
112        int mShadingMethod;
113
114        bool mRegenerateSamples;
[2976]115
[2858]116};
117
118} // namespace
[2886]119
[2859]120#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.