[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:
|
---|
[2874] | 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);
|
---|
[2874] | 32 | /** The algorithm renders the scene given an fbo consists of 1 color buffer,
|
---|
[2861] | 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
|
---|
[2858] | 36 | */
|
---|
[2861] | 37 | void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor);
|
---|
[2859] | 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 |
|
---|
[2861] | 44 | ~SsaoShader();
|
---|
[2859] | 45 |
|
---|
[2875] | 46 | void SetUseGlobIllum(bool useGlobIllum);
|
---|
| 47 | void SetUseTemporalCoherence(bool temporal);
|
---|
[2874] | 48 |
|
---|
[2875] | 49 |
|
---|
[2859] | 50 | protected:
|
---|
| 51 |
|
---|
[2874] | 52 | void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2859] | 53 |
|
---|
[2874] | 54 | void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2873] | 55 |
|
---|
[2868] | 56 | void FirstPass(FrameBufferObject *fbo);
|
---|
| 57 |
|
---|
[2880] | 58 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 59 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 60 |
|
---|
[2865] | 61 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
[2859] | 62 |
|
---|
[2861] | 63 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2859] | 64 |
|
---|
[2861] | 65 |
|
---|
[2859] | 66 | ////////////
|
---|
| 67 |
|
---|
| 68 | int mWidth;
|
---|
| 69 | int mHeight;
|
---|
| 70 |
|
---|
| 71 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
| 72 | float mScaleFactor;
|
---|
[2860] | 73 |
|
---|
| 74 | Camera *mCamera;
|
---|
| 75 |
|
---|
[2861] | 76 | FrameBufferObject *mOldFbo;
|
---|
| 77 | FrameBufferObject *mNewFbo;
|
---|
[2879] | 78 | //FrameBufferObject *mFbo;
|
---|
[2875] | 79 |
|
---|
| 80 | bool mUseGlobIllum;
|
---|
| 81 | bool mUseTemporalCoherence;
|
---|
[2858] | 82 | };
|
---|
| 83 |
|
---|
| 84 | } // namespace
|
---|
[2859] | 85 | #endif // _SsaoShader_H__ |
---|