[2859] | 1 | #ifndef _SsaoShader_H__
|
---|
| 2 | #define _SsaoShader_H__
|
---|
[2858] | 3 |
|
---|
| 4 | #include "common.h"
|
---|
[2859] | 5 | #include "glInterface.h"
|
---|
| 6 | #include <Cg/cg.h>
|
---|
| 7 | #include <Cg/cgGL.h>
|
---|
[2858] | 8 |
|
---|
[2859] | 9 |
|
---|
[2858] | 10 | namespace CHCDemoEngine
|
---|
| 11 | {
|
---|
| 12 |
|
---|
| 13 | class FrameBufferObject;
|
---|
[2860] | 14 | class Vector3;
|
---|
| 15 | class Camera;
|
---|
[2861] | 16 | class Matrix4x4;
|
---|
[2858] | 17 |
|
---|
[2859] | 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
|
---|
[2858] | 20 | */
|
---|
[2859] | 21 | class SsaoShader
|
---|
[2858] | 22 | {
|
---|
| 23 | public:
|
---|
[2859] | 24 | /** constructor for a deferred shader taking the requested output image size,
|
---|
[2861] | 25 | the current camera, and a scaling factor.
|
---|
[2860] | 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.
|
---|
[2858] | 30 | */
|
---|
[2861] | 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
|
---|
[2858] | 38 | */
|
---|
[2861] | 39 | void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor);
|
---|
[2859] | 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 |
|
---|
[2861] | 46 | ~SsaoShader();
|
---|
[2859] | 47 |
|
---|
| 48 | protected:
|
---|
| 49 |
|
---|
[2863] | 50 | void ComputeSsao(FrameBufferObject *fbo, float expFactor);
|
---|
[2859] | 51 |
|
---|
[2868] | 52 | void FirstPass(FrameBufferObject *fbo);
|
---|
| 53 |
|
---|
[2865] | 54 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
[2859] | 55 |
|
---|
[2861] | 56 | void CreateNoiseTex2D();
|
---|
| 57 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2859] | 58 |
|
---|
[2861] | 59 |
|
---|
[2859] | 60 | ////////////
|
---|
| 61 |
|
---|
| 62 | int mWidth;
|
---|
| 63 | int mHeight;
|
---|
| 64 |
|
---|
| 65 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
| 66 | float mScaleFactor;
|
---|
[2860] | 67 |
|
---|
| 68 | Camera *mCamera;
|
---|
| 69 |
|
---|
[2861] | 70 | FrameBufferObject *mOldFbo;
|
---|
| 71 | FrameBufferObject *mNewFbo;
|
---|
[2868] | 72 | FrameBufferObject *mFbo3;
|
---|
[2858] | 73 | };
|
---|
| 74 |
|
---|
| 75 | } // namespace
|
---|
[2859] | 76 | #endif // _SsaoShader_H__ |
---|