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 |
|
---|
10 | namespace CHCDemoEngine
|
---|
11 | {
|
---|
12 |
|
---|
13 | class FrameBufferObject;
|
---|
14 | class Vector3;
|
---|
15 | class Camera;
|
---|
16 | class 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 | */
|
---|
21 | class SsaoShader
|
---|
22 | {
|
---|
23 | public:
|
---|
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 | /**
|
---|
33 |
|
---|
34 | The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
35 | 1 position buffer, and 1 normal buffer.
|
---|
36 | We also need the projection view matrix of the last frame for reprojection, and
|
---|
37 | a smoothing factor for temporal coherence
|
---|
38 | */
|
---|
39 | void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor);
|
---|
40 |
|
---|
41 | /** Initialises the deferred shader and loads the required shaders:
|
---|
42 | This function has to be called only once.
|
---|
43 | */
|
---|
44 | static void Init(CGcontext context);
|
---|
45 |
|
---|
46 | ~SsaoShader();
|
---|
47 |
|
---|
48 | protected:
|
---|
49 |
|
---|
50 | void ComputeSsao(FrameBufferObject *fbo, float expFactor);
|
---|
51 |
|
---|
52 | //void DisplayTexture();
|
---|
53 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
54 |
|
---|
55 | void CreateNoiseTex2D();
|
---|
56 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
57 |
|
---|
58 |
|
---|
59 | ////////////
|
---|
60 |
|
---|
61 | int mWidth;
|
---|
62 | int mHeight;
|
---|
63 |
|
---|
64 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
65 | float mScaleFactor;
|
---|
66 |
|
---|
67 | Camera *mCamera;
|
---|
68 |
|
---|
69 | FrameBufferObject *mOldFbo;
|
---|
70 | FrameBufferObject *mNewFbo;
|
---|
71 | };
|
---|
72 |
|
---|
73 | } // namespace
|
---|
74 | #endif // _SsaoShader_H__ |
---|