#ifndef _ShadowMap_H__ #define _ShadowMap_H__ #include "common.h" #include "glInterface.h" #include "AxisAlignedBox3.h" #include "Matrix4x4.h" #include #include namespace CHCDemoEngine { class FrameBufferObject; class RenderTraverser; class Vector3; class Camera; class Light; /** This class implements a the computation of single shadow map */ class ShadowMap { public: /** Constructor taking the scene boundig box and the current camera. The shadow map has resolution size * size. */ ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam); ~ShadowMap(); /** Computes the shadow map */ void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView); /** Returns computed shadow color texture. */ unsigned int GetShadowColorTexture() const; unsigned int GetDepthTexture() const; /** Returns computed texture matrix. It must be applied on the the world space positions. The texture matrix can be directly applied if the world space position is available (deferred shading), otherwise it must be multiplied with the inverse model matrix. */ void GetTextureMatrix(Matrix4x4 &m) const; /** Return shadow size. */ int GetSize() const { return mSize; } Camera *GetShadowCamera() const { return mShadowCam; } static void DrawPolys(); protected: /** Calculates the intersection of the frustum with the box, returns resultin polyhedron as array of polygons. */ Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const; bool CalcLightProjection(Matrix4x4 &lightProj); Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView, const AxisAlignedBox3 &bounds, const VertexArray &pts); void IncludeLightVolume(const Polyhedron &polyhedron, VertexArray &frustumPoints, const Vector3 lightDir, const AxisAlignedBox3 &sceneBox); float ComputeN(const AxisAlignedBox3 &extremalPoints) const; Vector3 GetNearCameraPointE(const VertexArray &pts) const; Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const; ////////////// /// the scene bounding box AxisAlignedBox3 mSceneBox; /// fbo storing the shadow texture FrameBufferObject *mFbo; /// size of the shadow map int mSize; Camera *mShadowCam; /// the texture matrix Matrix4x4 mTextureMatrix; /// the used light Light *mLight; /// the scene camera Camera *mCamera; Matrix4x4 mLightProjView; }; } // namespace #endif // _ShadowMapping_H__