source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h @ 2879

Revision 2879, 2.2 KB checked in by mattausch, 16 years ago (diff)

improved performance

Line 
1#ifndef _SsaoShader_H__
2#define _SsaoShader_H__
3
4#include "common.h"
5#include "glInterface.h"
6#include <Cg/cg.h>
7#include <Cg/cgGL.h>
8
9
10namespace CHCDemoEngine
11{
12
13class FrameBufferObject;
14class Vector3;
15class Camera;
16class Matrix4x4;
17
18/** This class implements a deferred shading algorithm that takes
19        a frame buffer object as input and outputs an image in the given size
20*/
21class SsaoShader
22{
23public:
24        /** Constructor for a deferred shader taking the requested output image size,
25                the current camera,     and a scaling factor.
26                       
27                The parameter scaleFactor must be reciprocal value of the
28                scale factor used for creating the positions texture. It is used recover the
29                exact scene size that was scaled in order to improve floating point precision.
30        */
31        SsaoShader(int w, int h, Camera *cam, float scaleFactor);
32        /** The algorithm renders the scene given an fbo consists of 1 color buffer,
33                1 position buffer, and 1 normal buffer.
34                We also need the  projection view matrix of the last frame for reprojection, and
35                a smoothing factor for temporal coherence
36        */
37        void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor);
38
39        /** Initialises the deferred shader and loads the required shaders:
40                This function has to be called only once.
41        */
42        static void Init(CGcontext context);
43
44        ~SsaoShader();
45
46        void SetUseGlobIllum(bool useGlobIllum);
47        void SetUseTemporalCoherence(bool temporal);
48
49
50protected:
51
52        void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
53
54        void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
55
56        void FirstPass(FrameBufferObject *fbo);
57
58        void AntiAliasing(FrameBufferObject *fbo);
59
60        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
61
62
63        ////////////
64
65        int mWidth;
66        int mHeight;
67
68        /// this is just a scale factor for the scene depth in order to get better float precision in the shader
69        float mScaleFactor;
70
71        Camera *mCamera;
72
73        FrameBufferObject *mOldFbo;
74        FrameBufferObject *mNewFbo;
75        //FrameBufferObject *mFbo;
76
77        bool mUseGlobIllum;
78        bool mUseTemporalCoherence;
79};
80
81} // namespace
82#endif // _SsaoShader_H__
Note: See TracBrowser for help on using the repository browser.