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