[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);
|
---|
[2928] | 38 | /** Returns computed shadow color texture.
|
---|
[2891] | 39 | */
|
---|
[2928] | 40 | unsigned int GetShadowColorTexture() const;
|
---|
| 41 |
|
---|
| 42 | unsigned int GetDepthTexture() const;
|
---|
| 43 |
|
---|
[2894] | 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;
|
---|
[2895] | 52 | /** Return shadow size.
|
---|
| 53 | */
|
---|
| 54 | int GetSize() const { return mSize; }
|
---|
[2891] | 55 |
|
---|
[2897] | 56 | Camera *GetShadowCamera() const { return mShadowCam; }
|
---|
| 57 |
|
---|
[2931] | 58 | void RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView);
|
---|
[2897] | 59 |
|
---|
[2931] | 60 |
|
---|
[2911] | 61 | static void DrawPolys();
|
---|
| 62 |
|
---|
| 63 |
|
---|
[2894] | 64 | protected:
|
---|
[2891] | 65 |
|
---|
[2931] | 66 |
|
---|
[2913] | 67 | /** Calculates the intersection of the frustum with the box,
|
---|
| 68 | returns resultin polyhedron as array of polygons.
|
---|
| 69 | */
|
---|
| 70 | Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
|
---|
[2915] | 71 |
|
---|
[2913] | 72 | bool CalcLightProjection(Matrix4x4 &lightProj);
|
---|
| 73 |
|
---|
[2920] | 74 | Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView,
|
---|
| 75 | const AxisAlignedBox3 &bounds,
|
---|
| 76 | const VertexArray &pts);
|
---|
| 77 |
|
---|
[2913] | 78 | void IncludeLightVolume(const Polyhedron &polyhedron,
|
---|
| 79 | VertexArray &frustumPoints,
|
---|
| 80 | const Vector3 lightDir,
|
---|
| 81 | const AxisAlignedBox3 &sceneBox);
|
---|
| 82 |
|
---|
[2920] | 83 | float ComputeN(const AxisAlignedBox3 &extremalPoints) const;
|
---|
[2913] | 84 |
|
---|
[2920] | 85 | Vector3 GetNearCameraPointE(const VertexArray &pts) const;
|
---|
[2916] | 86 |
|
---|
[2920] | 87 | Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const;
|
---|
| 88 |
|
---|
[2929] | 89 | static void DrawPoly(Polyhedron *poly, const Vector3 &color);
|
---|
[2920] | 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
[2913] | 93 | //////////////
|
---|
| 94 |
|
---|
[2894] | 95 | /// the scene bounding box
|
---|
| 96 | AxisAlignedBox3 mSceneBox;
|
---|
| 97 | /// fbo storing the shadow texture
|
---|
[2891] | 98 | FrameBufferObject *mFbo;
|
---|
[2894] | 99 | /// size of the shadow map
|
---|
[2891] | 100 | int mSize;
|
---|
| 101 |
|
---|
| 102 | Camera *mShadowCam;
|
---|
[2894] | 103 | /// the texture matrix
|
---|
| 104 | Matrix4x4 mTextureMatrix;
|
---|
| 105 | /// the used light
|
---|
[2891] | 106 | Light *mLight;
|
---|
[2894] | 107 | /// the scene camera
|
---|
| 108 | Camera *mCamera;
|
---|
[2911] | 109 |
|
---|
| 110 | Matrix4x4 mLightProjView;
|
---|
[2891] | 111 | };
|
---|
| 112 |
|
---|
| 113 | } // namespace
|
---|
[2894] | 114 | #endif // _ShadowMapping_H__ |
---|