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

Revision 2928, 2.6 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 color texture.
39        */
40        unsigned int GetShadowColorTexture() const;
41       
42        unsigned int GetDepthTexture() const;
43
44        /** Returns computed texture matrix. It must be applied on the
45                the world space positions.
46               
47                The texture     matrix can be directly applied if the world space position
48                is available (deferred shading), otherwise it must be multiplied with
49                the inverse model matrix.
50        */
51        void GetTextureMatrix(Matrix4x4 &m) const;
52        /** Return shadow size.
53        */
54        int GetSize() const { return mSize; }
55
56        Camera *GetShadowCamera() const { return mShadowCam; }
57
58
59        static void DrawPolys();
60
61
62protected:
63
64        /** Calculates the intersection of the frustum with the box,
65                returns resultin polyhedron as array of polygons.
66        */
67        Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
68       
69        bool CalcLightProjection(Matrix4x4 &lightProj);
70
71        Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView,
72                                          const AxisAlignedBox3 &bounds,
73                                                                  const VertexArray &pts);
74
75        void IncludeLightVolume(const Polyhedron &polyhedron,
76                                    VertexArray &frustumPoints,
77                                                        const Vector3 lightDir,
78                                                        const AxisAlignedBox3 &sceneBox);
79
80        float ComputeN(const AxisAlignedBox3 &extremalPoints) const;
81
82        Vector3 GetNearCameraPointE(const VertexArray &pts) const;
83
84        Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const;
85
86
87
88
89        //////////////
90
91        /// the scene bounding box
92        AxisAlignedBox3 mSceneBox;
93        /// fbo storing the shadow texture
94        FrameBufferObject *mFbo;
95        /// size of the shadow map
96        int mSize;
97
98        Camera *mShadowCam;
99        /// the texture matrix
100        Matrix4x4 mTextureMatrix;
101        /// the used light
102        Light *mLight;
103        /// the scene camera
104        Camera *mCamera;
105
106        Matrix4x4 mLightProjView;
107};
108
109} // namespace
110#endif // _ShadowMapping_H__
Note: See TracBrowser for help on using the repository browser.