#ifndef _DeferredRenderer_H__ #define _DeferredRenderer_H__ #include "common.h" #include "glInterface.h" #include #include namespace CHCDemoEngine { class FrameBufferObject; class Vector3; class Camera; class Matrix4x4; class ShadowMap; /** This class implements a deferred shading algorithm that takes a frame buffer object as input and outputs an image in the given size */ class DeferredRenderer { 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. */ DeferredRenderer(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, const Matrix4x4 &projViewMatrix, float tempCohFactor, ShadowMap *shadowMap = NULL); /** Initialises the deferred shader and loads the required shaders: This function has to be called only once. */ static void Init(CGcontext context); ~DeferredRenderer(); void SetUseTemporalCoherence(bool temporal); enum SAMPLING_METHOD {POISSON, GAUSS}; enum SHADING_METHOD {DEFAULT, SSAO, GI}; void SetSamplingMethod(SAMPLING_METHOD s); void SetShadingMethod(SHADING_METHOD s); protected: void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix); void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix); void FirstPass(FrameBufferObject *fbo); void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap); void CombineSsao(FrameBufferObject *fbo); void CombineIllum(FrameBufferObject *fbo); void AntiAliasing(FrameBufferObject *fbo); /** Helper method that computes the view vectors in the corners of the current view frustum. */ 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 *mFbo; bool mUseTemporalCoherence; int mSamplingMethod; int mFboIndex; int mShadingMethod; bool mRegenerateSamples; }; } // namespace #endif // _SsaoShader_H__