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

Revision 2917, 2.3 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 CalcLightProjection(Matrix4x4 &lightProj);
67        Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView, const AxisAlignedBox3 &bounds);
68
69        void IncludeLightVolume(const Polyhedron &polyhedron,
70                                    VertexArray &frustumPoints,
71                                                        const Vector3 lightDir,
72                                                        const AxisAlignedBox3 &sceneBox);
73
74        float ComputeN() const;
75
76
77        //////////////
78
79        /// the scene bounding box
80        AxisAlignedBox3 mSceneBox;
81        /// fbo storing the shadow texture
82        FrameBufferObject *mFbo;
83        /// size of the shadow map
84        int mSize;
85
86        Camera *mShadowCam;
87        /// the texture matrix
88        Matrix4x4 mTextureMatrix;
89        /// the used light
90        Light *mLight;
91        /// the scene camera
92        Camera *mCamera;
93
94        Matrix4x4 mLightProjView;
95};
96
97} // namespace
98#endif // _ShadowMapping_H__
Note: See TracBrowser for help on using the repository browser.