#ifndef _SsaoShader_H__ #define _SsaoShader_H__ #include "common.h" #include "glInterface.h" #include #include namespace CHCDemoEngine { class FrameBufferObject; class Vector3; class Camera; class Matrix4x4; /** This class implements a deferred shading algorithm that takes a frame buffer object as input and outputs an image in the given size */ class SsaoShader { public: /** Constructor for a deferred shader taking the requested output image size, the current camera, and a scaling factor. The parameter scaleFactor must be reciprocal value of the scale factor used for creating the positions texture. It is used recover the exact scene size that was scaled in order to improve floating point precision. */ SsaoShader(int w, int h, Camera *cam, float scaleFactor); /** The algorithm renders the scene given an fbo consists of 1 color buffer, 1 position buffer, and 1 normal buffer. We also need the projection view matrix of the last frame for reprojection, and a smoothing factor for temporal coherence */ void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor); /** Initialises the deferred shader and loads the required shaders: This function has to be called only once. */ static void Init(CGcontext context); ~SsaoShader(); void SetUseGlobIllum(bool useGlobIllum); void SetUseTemporalCoherence(bool temporal); enum SAMPLING_METHOD {POISSON, GAUSS}; void SetSamplingMethod(int s) { mSampling = s;} protected: void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix); void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix); void FirstPass(FrameBufferObject *fbo); void CombineSsao(FrameBufferObject *fbo); void CombineIllum(FrameBufferObject *fbo); void AntiAliasing(FrameBufferObject *fbo); void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); //////////// int mWidth; int mHeight; /// this is just a scale factor for the scene depth in order to get better float precision in the shader float mScaleFactor; Camera *mCamera; FrameBufferObject *mOldFbo; FrameBufferObject *mNewFbo; //FrameBufferObject *mFbo; bool mUseGlobIllum; bool mUseTemporalCoherence; int mSampling; }; } // namespace #endif // _SsaoShader_H__