source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h @ 2915

Revision 2915, 2.2 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef _ShadowMap_H__
2#define _ShadowMap_H__
3
4#include "common.h"
5#include "glInterface.h"
6#include "AxisAlignedBox3.h"
7#include "Matrix4x4.h"
8
9#include <Cg/cg.h>
10#include <Cg/cgGL.h>
11
12
13
14namespace CHCDemoEngine
15{
16
17class FrameBufferObject;
18class RenderTraverser;
19class Vector3;
20class Camera;
21class Light;
22
23/** This class implements a the computation of single shadow map
24*/
25class ShadowMap
26{
27
28public:
29        /** Constructor taking the scene boundig box and the current camera.
30                The shadow map has resolution size * size.
31        */
32        ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
33
34        ~ShadowMap();
35        /** Computes the shadow map
36        */
37        void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView);
38        /** Returns computed shadow texture.
39        */
40        unsigned int GetShadowTexture() const;
41        /** Returns computed texture matrix. It must be applied on the
42                the world space positions.
43               
44                The texture     matrix can be directly applied if the world space position
45                is available (deferred shading), otherwise it must be multiplied with
46                the inverse model matrix.
47        */
48        void GetTextureMatrix(Matrix4x4 &m) const;
49        /** Return shadow size.
50        */
51        int GetSize() const { return mSize; }
52
53        Camera *GetShadowCamera() const { return mShadowCam; }
54
55
56        static void DrawPolys();
57
58
59protected:
60
61        /** Calculates the intersection of the frustum with the box,
62                returns resultin polyhedron as array of polygons.
63        */
64        Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
65       
66        bool CalcLightProjectionLispSM(Matrix4x4 &lightProj);
67        bool CalcLightProjection(Matrix4x4 &lightProj);
68
69        void IncludeLightVolume(const Polyhedron &polyhedron,
70                                    VertexArray &frustumPoints,
71                                                        const Vector3 lightDir,
72                                                        const AxisAlignedBox3 &sceneBox);
73
74
75        //////////////
76
77        /// the scene bounding box
78        AxisAlignedBox3 mSceneBox;
79        /// fbo storing the shadow texture
80        FrameBufferObject *mFbo;
81        /// size of the shadow map
82        int mSize;
83
84        Camera *mShadowCam;
85        /// the texture matrix
86        Matrix4x4 mTextureMatrix;
87        /// the used light
88        Light *mLight;
89        /// the scene camera
90        Camera *mCamera;
91
92        Matrix4x4 mLightProjView;
93};
94
95} // namespace
96#endif // _ShadowMapping_H__
Note: See TracBrowser for help on using the repository browser.