[2894] | 1 | #ifndef _ShadowMap_H__
|
---|
| 2 | #define _ShadowMap_H__
|
---|
[2891] | 3 |
|
---|
| 4 | #include "common.h"
|
---|
| 5 | #include "AxisAlignedBox3.h"
|
---|
| 6 | #include "Matrix4x4.h"
|
---|
[2913] | 7 |
|
---|
[2891] | 8 |
|
---|
| 9 |
|
---|
| 10 | namespace CHCDemoEngine
|
---|
| 11 | {
|
---|
| 12 |
|
---|
| 13 | class FrameBufferObject;
|
---|
| 14 | class RenderTraverser;
|
---|
| 15 | class Vector3;
|
---|
| 16 | class Camera;
|
---|
[2952] | 17 | class DirectionalLight;
|
---|
[2891] | 18 |
|
---|
[2963] | 19 | /** This class implements a the computation of single shadow map using
|
---|
| 20 | LispSM (light space perspective shadow mapping)
|
---|
[2891] | 21 | */
|
---|
[2894] | 22 | class ShadowMap
|
---|
[2891] | 23 | {
|
---|
[2894] | 24 |
|
---|
[2891] | 25 | public:
|
---|
[2894] | 26 | /** Constructor taking the scene boundig box and the current camera.
|
---|
[2963] | 27 | The shadow map has resolution size squared.
|
---|
[2891] | 28 | */
|
---|
[2952] | 29 | ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
|
---|
[2891] | 30 |
|
---|
[2894] | 31 | ~ShadowMap();
|
---|
| 32 | /** Computes the shadow map
|
---|
[2891] | 33 | */
|
---|
[2911] | 34 | void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView);
|
---|
[2928] | 35 | /** Returns computed shadow color texture.
|
---|
[2891] | 36 | */
|
---|
[2928] | 37 | unsigned int GetShadowColorTexture() const;
|
---|
[2963] | 38 | /** Returns the depth texture used for shadow comparison.
|
---|
| 39 | */
|
---|
[2928] | 40 | unsigned int GetDepthTexture() const;
|
---|
[2894] | 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; }
|
---|
[2963] | 52 | /** Returns the camera used for light view rendering.
|
---|
| 53 | */
|
---|
[2897] | 54 | Camera *GetShadowCamera() const { return mShadowCam; }
|
---|
[2963] | 55 | /** Renders the scene from shadow view using conventional shading.
|
---|
| 56 | */
|
---|
[2931] | 57 | void RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView);
|
---|
[2963] | 58 | /** Draws LispSM intersection body B and the used light frustrum
|
---|
| 59 | */
|
---|
| 60 | static void VisualizeFrustra();
|
---|
[2897] | 61 |
|
---|
[2911] | 62 |
|
---|
[2894] | 63 | protected:
|
---|
[2891] | 64 |
|
---|
[2931] | 65 |
|
---|
[2913] | 66 | /** Calculates the intersection of the frustum with the box,
|
---|
| 67 | returns resultin polyhedron as array of polygons.
|
---|
| 68 | */
|
---|
| 69 | Polyhedron *CalcClippedFrustum(const AxisAlignedBox3 &box) const;
|
---|
[2915] | 70 |
|
---|
[2913] | 71 | bool CalcLightProjection(Matrix4x4 &lightProj);
|
---|
| 72 |
|
---|
[2920] | 73 | Matrix4x4 CalcLispSMTransform(const Matrix4x4 &lightProjView,
|
---|
| 74 | const AxisAlignedBox3 &bounds,
|
---|
| 75 | const VertexArray &pts);
|
---|
| 76 |
|
---|
[2913] | 77 | void IncludeLightVolume(const Polyhedron &polyhedron,
|
---|
| 78 | VertexArray &frustumPoints,
|
---|
| 79 | const Vector3 lightDir,
|
---|
| 80 | const AxisAlignedBox3 &sceneBox);
|
---|
| 81 |
|
---|
[2920] | 82 | float ComputeN(const AxisAlignedBox3 &extremalPoints) const;
|
---|
[2913] | 83 |
|
---|
[2944] | 84 | float ComputeNOpt(const Matrix4x4 &lightSpace,
|
---|
| 85 | const AxisAlignedBox3 &extremalPoints,
|
---|
| 86 | const VertexArray &body) const;
|
---|
| 87 |
|
---|
[2920] | 88 | Vector3 GetNearCameraPointE(const VertexArray &pts) const;
|
---|
[2916] | 89 |
|
---|
[2920] | 90 | Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const;
|
---|
| 91 |
|
---|
| 92 |
|
---|
[2942] | 93 | /** Internal shador render method.
|
---|
| 94 | */
|
---|
| 95 | void _Render(RenderTraverser *renderer);
|
---|
[2920] | 96 |
|
---|
[2944] | 97 | Vector3 GetLightSpaceZ0(const Matrix4x4 &lightSpace,
|
---|
| 98 | const Vector3 &e,
|
---|
| 99 | const float maxZ,
|
---|
| 100 | const Vector3 &eyeDir) const;
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 |
|
---|
[2913] | 104 | //////////////
|
---|
| 105 |
|
---|
[2894] | 106 | /// the scene bounding box
|
---|
| 107 | AxisAlignedBox3 mSceneBox;
|
---|
| 108 | /// fbo storing the shadow texture
|
---|
[2891] | 109 | FrameBufferObject *mFbo;
|
---|
[2894] | 110 | /// size of the shadow map
|
---|
[2891] | 111 | int mSize;
|
---|
[3034] | 112 | /// the shadow view
|
---|
[2891] | 113 | Camera *mShadowCam;
|
---|
[2894] | 114 | /// the texture matrix
|
---|
| 115 | Matrix4x4 mTextureMatrix;
|
---|
| 116 | /// the used light
|
---|
[2952] | 117 | DirectionalLight *mLight;
|
---|
[2894] | 118 | /// the scene camera
|
---|
| 119 | Camera *mCamera;
|
---|
[2911] | 120 |
|
---|
| 121 | Matrix4x4 mLightProjView;
|
---|
[2891] | 122 | };
|
---|
| 123 |
|
---|
| 124 | } // namespace
|
---|
[2894] | 125 | #endif // _ShadowMapping_H__ |
---|