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

Revision 2963, 3.4 KB checked in by mattausch, 16 years ago (diff)

debug version trying to find out how to speed up app

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 DirectionalLight;
22
23/** This class implements a the computation of single shadow map using
24        LispSM (light space perspective shadow mapping)
25*/
26class ShadowMap
27{
28
29public:
30        /** Constructor taking the scene boundig box and the current camera.
31                The shadow map has resolution size squared.
32        */
33        ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
34
35        ~ShadowMap();
36        /** Computes the shadow map
37        */
38        void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView);
39        /** Returns computed shadow color texture.
40        */
41        unsigned int GetShadowColorTexture() const;
42        /** Returns the depth texture used for shadow comparison.
43        */
44        unsigned int GetDepthTexture() const;
45        /** Returns computed texture matrix. It must be applied on the
46                the world space positions.
47               
48                The texture     matrix can be directly applied if the world space position
49                is available (deferred shading), otherwise it must be multiplied with
50                the inverse model matrix.
51        */
52        void GetTextureMatrix(Matrix4x4 &m) const;
53        /** Return shadow size.
54        */
55        int GetSize() const { return mSize; }
56        /** Returns the camera used for light view rendering.
57        */
58        Camera *GetShadowCamera() const { return mShadowCam; }
59        /** Renders the scene from shadow view using conventional shading.
60        */
61        void RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView);
62        /** Draws LispSM intersection body B and the used light frustrum
63        */
64        static void VisualizeFrustra();
65
66
67protected:
68
69
70        /** Calculates the intersection of the frustum with the box,
71                returns resultin polyhedron as array of polygons.
72        */
73        Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
74       
75        bool CalcLightProjection(Matrix4x4 &lightProj);
76
77        Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView,
78                                          const AxisAlignedBox3 &bounds,
79                                                                  const VertexArray &pts);
80
81        void IncludeLightVolume(const Polyhedron &polyhedron,
82                                    VertexArray &frustumPoints,
83                                                        const Vector3 lightDir,
84                                                        const AxisAlignedBox3 &sceneBox);
85
86        float ComputeN(const AxisAlignedBox3 &extremalPoints) const;
87
88        float ComputeNOpt(const Matrix4x4 &lightSpace,
89                              const AxisAlignedBox3 &extremalPoints,
90                                          const VertexArray &body) const;
91
92        Vector3 GetNearCameraPointE(const VertexArray &pts) const;
93
94        Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const;
95
96
97        /** Internal shador render method.
98        */
99        void _Render(RenderTraverser *renderer);
100
101        Vector3 GetLightSpaceZ0(const Matrix4x4 &lightSpace,
102                                    const Vector3 &e,
103                                                        const float maxZ,
104                                                        const Vector3 &eyeDir) const;
105
106
107
108        //////////////
109
110        /// the scene bounding box
111        AxisAlignedBox3 mSceneBox;
112        /// fbo storing the shadow texture
113        FrameBufferObject *mFbo;
114        /// size of the shadow map
115        int mSize;
116
117        Camera *mShadowCam;
118        /// the texture matrix
119        Matrix4x4 mTextureMatrix;
120        /// the used light
121        DirectionalLight *mLight;
122        /// the scene camera
123        Camera *mCamera;
124
125        Matrix4x4 mLightProjView;
126};
127
128} // namespace
129#endif // _ShadowMapping_H__
Note: See TracBrowser for help on using the repository browser.