| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #ifndef __ShadowCameraSetupPlaneOptimal_H__ |
|---|
| 30 | #define __ShadowCameraSetupPlaneOptimal_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.h" |
|---|
| 33 | #include "OgreShadowCameraSetup.h" |
|---|
| 34 | |
|---|
| 35 | namespace Ogre { |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | /** Implements the plane optimal shadow camera algorithm. |
|---|
| 39 | @remarks |
|---|
| 40 | Given a plane of interest, it is possible to set up the shadow camera |
|---|
| 41 | matrix such that the mapping between screen and shadow map is the identity |
|---|
| 42 | (when restricted to pixels that view the plane of interest). Therefore, |
|---|
| 43 | if the shadow map resolution matches the screen space resolution (of the |
|---|
| 44 | seen planar receiver), we can get pixel perfect shadowing on the plane. |
|---|
| 45 | Off the plane, the shadowing is not guaranteed to be perfect and will |
|---|
| 46 | likely exhibit the usual sampling artifacts associated with shadow mapping. |
|---|
| 47 | @note Important: this routine requires double-precision calculations. When you |
|---|
| 48 | are running under Direct3D, you must ensure that you set the floating |
|---|
| 49 | point mode to 'Consistent' rather than 'Fastest' to ensure this precision. |
|---|
| 50 | This does allegedly come with some performance cost but when measuring |
|---|
| 51 | it appears to be negligible in modern systems for normal usage. |
|---|
| 52 | @note Second important note: this projection also only works for lights with |
|---|
| 53 | a finite position. Therefore you cannot use it for directional lights |
|---|
| 54 | at this time. |
|---|
| 55 | */ |
|---|
| 56 | class _OgreExport PlaneOptimalShadowCameraSetup : public ShadowCameraSetup |
|---|
| 57 | { |
|---|
| 58 | private: |
|---|
| 59 | MovablePlane* m_plane; ///< pointer to plane of interest |
|---|
| 60 | private: |
|---|
| 61 | PlaneOptimalShadowCameraSetup() {} ///< Default constructor is private |
|---|
| 62 | |
|---|
| 63 | /// helper function computing projection matrix given constraints |
|---|
| 64 | Matrix4 computeConstrainedProjection( const Vector4& pinhole, |
|---|
| 65 | const std::vector<Vector4>& fpoint, |
|---|
| 66 | const std::vector<Vector2>& constraint) const; |
|---|
| 67 | |
|---|
| 68 | public: |
|---|
| 69 | /// Constructor -- requires a plane of interest |
|---|
| 70 | PlaneOptimalShadowCameraSetup(MovablePlane *plane); |
|---|
| 71 | /// Destructor |
|---|
| 72 | virtual ~PlaneOptimalShadowCameraSetup(); |
|---|
| 73 | |
|---|
| 74 | /// Returns shadow camera configured to get 1-1 homography between screen and shadow map when restricted to plane |
|---|
| 75 | virtual void getShadowCamera (const SceneManager *sm, const Camera *cam, |
|---|
| 76 | const Viewport *vp, const Light *light, Camera *texCam) const; |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | #endif |
|---|