[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 |
|
---|
[2887] | 49 | enum SAMPLING_METHOD {POISSON, GAUSS};
|
---|
[2875] | 50 |
|
---|
[2887] | 51 | void SetSamplingMethod(int s) { mSampling = s;}
|
---|
| 52 |
|
---|
| 53 |
|
---|
[2859] | 54 | protected:
|
---|
| 55 |
|
---|
[2874] | 56 | void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2859] | 57 |
|
---|
[2874] | 58 | void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix);
|
---|
[2873] | 59 |
|
---|
[2868] | 60 | void FirstPass(FrameBufferObject *fbo);
|
---|
| 61 |
|
---|
[2880] | 62 | void CombineSsao(FrameBufferObject *fbo);
|
---|
| 63 | void CombineIllum(FrameBufferObject *fbo);
|
---|
| 64 |
|
---|
[2865] | 65 | void AntiAliasing(FrameBufferObject *fbo);
|
---|
[2859] | 66 |
|
---|
[2861] | 67 | void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
|
---|
[2859] | 68 |
|
---|
[2861] | 69 |
|
---|
[2859] | 70 | ////////////
|
---|
| 71 |
|
---|
| 72 | int mWidth;
|
---|
| 73 | int mHeight;
|
---|
| 74 |
|
---|
| 75 | /// this is just a scale factor for the scene depth in order to get better float precision in the shader
|
---|
| 76 | float mScaleFactor;
|
---|
[2860] | 77 |
|
---|
| 78 | Camera *mCamera;
|
---|
| 79 |
|
---|
[2861] | 80 | FrameBufferObject *mOldFbo;
|
---|
| 81 | FrameBufferObject *mNewFbo;
|
---|
[2879] | 82 | //FrameBufferObject *mFbo;
|
---|
[2875] | 83 |
|
---|
| 84 | bool mUseGlobIllum;
|
---|
| 85 | bool mUseTemporalCoherence;
|
---|
[2887] | 86 |
|
---|
| 87 | int mSampling;
|
---|
[2858] | 88 | };
|
---|
| 89 |
|
---|
| 90 | } // namespace
|
---|
[2886] | 91 |
|
---|
[2859] | 92 | #endif // _SsaoShader_H__ |
---|