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 |
|
---|
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, the exponential smoothing factor for temporal reprojection,
|
---|
26 | and a scaling factor.
|
---|
27 |
|
---|
28 | The parameter scaleFactor must be reciprocal value of the
|
---|
29 | scale factor used for creating the positions texture. It is used recover the
|
---|
30 | exact scene size that was scaled in order to improve floating point precision.
|
---|
31 | */
|
---|
32 | SsaoShader(int w, int h, Camera *cam, float expFactor, float scaleFactor);
|
---|
33 | /** The algorithm renders the scene given an fbo.
|
---|
34 | The fbo must have color buffer, position buffer, normal buffer.
|
---|
35 | */
|
---|
36 | void Render(FrameBufferObject *fbo, FrameBufferObject *fbo2);
|
---|
37 |
|
---|
38 | /** Initialises the deferred shader and loads the required shaders:
|
---|
39 | This function has to be called only once.
|
---|
40 | */
|
---|
41 | static void Init(CGcontext context);
|
---|
42 |
|
---|
43 |
|
---|
44 | protected:
|
---|
45 |
|
---|
46 | void FirstPass(FrameBufferObject *fbo, FrameBufferObject *fbo2);
|
---|
47 |
|
---|
48 | void SecondPass(FrameBufferObject *fbo, FrameBufferObject *fbo2);
|
---|
49 |
|
---|
50 |
|
---|
51 | ////////////
|
---|
52 |
|
---|
53 | int mWidth;
|
---|
54 | int mHeight;
|
---|
55 |
|
---|
56 | /// the temporal smoothing factor
|
---|
57 | float mExpFactor;
|
---|
58 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
59 | float mScaleFactor;
|
---|
60 |
|
---|
61 | Camera *mCamera;
|
---|
62 |
|
---|
63 |
|
---|
64 | private:
|
---|
65 |
|
---|
66 | void CreateNoiseTex2D();
|
---|
67 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
68 |
|
---|
69 | };
|
---|
70 |
|
---|
71 | } // namespace
|
---|
72 | #endif // _SsaoShader_H__ |
---|