[2894] | 1 | #ifndef _ShadowMap_H__
|
---|
| 2 | #define _ShadowMap_H__
|
---|
[2891] | 3 |
|
---|
| 4 | #include "common.h"
|
---|
| 5 | #include "glInterface.h"
|
---|
| 6 | #include "AxisAlignedBox3.h"
|
---|
| 7 | #include "Matrix4x4.h"
|
---|
[2913] | 8 |
|
---|
[2891] | 9 | #include <Cg/cg.h>
|
---|
| 10 | #include <Cg/cgGL.h>
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | namespace CHCDemoEngine
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | class FrameBufferObject;
|
---|
| 18 | class RenderTraverser;
|
---|
| 19 | class Vector3;
|
---|
| 20 | class Camera;
|
---|
| 21 | class Light;
|
---|
| 22 |
|
---|
[2894] | 23 | /** This class implements a the computation of single shadow map
|
---|
[2891] | 24 | */
|
---|
[2894] | 25 | class ShadowMap
|
---|
[2891] | 26 | {
|
---|
[2894] | 27 |
|
---|
[2891] | 28 | public:
|
---|
[2894] | 29 | /** Constructor taking the scene boundig box and the current camera.
|
---|
| 30 | The shadow map has resolution size * size.
|
---|
[2891] | 31 | */
|
---|
[2897] | 32 | ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
|
---|
[2891] | 33 |
|
---|
[2894] | 34 | ~ShadowMap();
|
---|
| 35 | /** Computes the shadow map
|
---|
[2891] | 36 | */
|
---|
[2911] | 37 | void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView);
|
---|
[2894] | 38 | /** Returns computed shadow texture.
|
---|
[2891] | 39 | */
|
---|
[2894] | 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;
|
---|
[2895] | 49 | /** Return shadow size.
|
---|
| 50 | */
|
---|
| 51 | int GetSize() const { return mSize; }
|
---|
[2891] | 52 |
|
---|
[2897] | 53 | Camera *GetShadowCamera() const { return mShadowCam; }
|
---|
| 54 |
|
---|
| 55 |
|
---|
[2911] | 56 | static void DrawPolys();
|
---|
| 57 |
|
---|
| 58 |
|
---|
[2894] | 59 | protected:
|
---|
[2891] | 60 |
|
---|
[2913] | 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;
|
---|
[2911] | 65 |
|
---|
| 66 |
|
---|
[2913] | 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 |
|
---|
[2894] | 77 | /// the scene bounding box
|
---|
| 78 | AxisAlignedBox3 mSceneBox;
|
---|
| 79 | /// fbo storing the shadow texture
|
---|
[2891] | 80 | FrameBufferObject *mFbo;
|
---|
[2894] | 81 | /// size of the shadow map
|
---|
[2891] | 82 | int mSize;
|
---|
| 83 |
|
---|
| 84 | Camera *mShadowCam;
|
---|
[2894] | 85 | /// the texture matrix
|
---|
| 86 | Matrix4x4 mTextureMatrix;
|
---|
| 87 | /// the used light
|
---|
[2891] | 88 | Light *mLight;
|
---|
[2894] | 89 | /// the scene camera
|
---|
| 90 | Camera *mCamera;
|
---|
[2911] | 91 |
|
---|
| 92 | Matrix4x4 mLightProjView;
|
---|
[2891] | 93 | };
|
---|
| 94 |
|
---|
| 95 | } // namespace
|
---|
[2894] | 96 | #endif // _ShadowMapping_H__ |
---|