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) 2000-2013 Torus Knot Software Ltd |
---|
8 | Copyright (c) 2006 Matthias Fink, netAllied GmbH <matthias.fink@web.de> |
---|
9 | |
---|
10 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
11 | of this software and associated documentation files (the "Software"), to deal |
---|
12 | in the Software without restriction, including without limitation the rights |
---|
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
14 | copies of the Software, and to permit persons to whom the Software is |
---|
15 | furnished to do so, subject to the following conditions: |
---|
16 | |
---|
17 | The above copyright notice and this permission notice shall be included in |
---|
18 | all copies or substantial portions of the Software. |
---|
19 | |
---|
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
26 | THE SOFTWARE. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #ifndef __ShadowCameraSetupPSSM_H__ |
---|
30 | #define __ShadowCameraSetupPSSM_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | #include "OgreShadowCameraSetupLiSPSM.h" |
---|
34 | #include "OgreHeaderPrefix.h" |
---|
35 | |
---|
36 | namespace Ogre |
---|
37 | { |
---|
38 | |
---|
39 | /** \addtogroup Core |
---|
40 | * @{ |
---|
41 | */ |
---|
42 | /** \addtogroup Scene |
---|
43 | * @{ |
---|
44 | */ |
---|
45 | /** Parallel Split Shadow Map (PSSM) shadow camera setup. |
---|
46 | @remarks |
---|
47 | A PSSM shadow system uses multiple shadow maps per light and maps each |
---|
48 | texture into a region of space, progressing away from the camera. As such |
---|
49 | it is most appropriate for directional light setups. This particular version |
---|
50 | also uses LiSPSM projection for each split to maximise the quality. |
---|
51 | @note |
---|
52 | Because PSSM uses multiple shadow maps per light, you will need to increase |
---|
53 | the number of shadow textures available (via SceneManager) to match the |
---|
54 | number of shadow maps required (default is 3 per light). |
---|
55 | */ |
---|
56 | class _OgreExport PSSMShadowCameraSetup : public Ogre::LiSPSMShadowCameraSetup |
---|
57 | { |
---|
58 | public: |
---|
59 | typedef vector<Real>::type SplitPointList; |
---|
60 | typedef vector<Real>::type OptimalAdjustFactorList; |
---|
61 | |
---|
62 | protected: |
---|
63 | uint mSplitCount; |
---|
64 | SplitPointList mSplitPoints; |
---|
65 | OptimalAdjustFactorList mOptimalAdjustFactors; |
---|
66 | Real mSplitPadding; |
---|
67 | |
---|
68 | mutable size_t mCurrentIteration; |
---|
69 | |
---|
70 | public: |
---|
71 | /// Constructor, defaults to 3 splits |
---|
72 | PSSMShadowCameraSetup(); |
---|
73 | ~PSSMShadowCameraSetup(); |
---|
74 | |
---|
75 | /** Calculate a new splitting scheme. |
---|
76 | @param splitCount The number of splits to use |
---|
77 | @param nearDist The near plane to use for the first split |
---|
78 | @param farDist The far plane to use for the last split |
---|
79 | @param lambda Factor to use to reduce the split size |
---|
80 | */ |
---|
81 | void calculateSplitPoints(uint splitCount, Real nearDist, Real farDist, Real lambda = 0.95); |
---|
82 | |
---|
83 | /** Manually configure a new splitting scheme. |
---|
84 | @param newSplitPoints A list which is splitCount + 1 entries long, containing the |
---|
85 | split points. The first value is the near point, the last value is the |
---|
86 | far point, and each value in between is both a far point of the previous |
---|
87 | split, and a near point for the next one. |
---|
88 | */ |
---|
89 | void setSplitPoints(const SplitPointList& newSplitPoints); |
---|
90 | |
---|
91 | /** Set the LiSPSM optimal adjust factor for a given split (call after |
---|
92 | configuring splits). |
---|
93 | */ |
---|
94 | void setOptimalAdjustFactor(size_t splitIndex, Real factor); |
---|
95 | |
---|
96 | /** Set the padding factor to apply to the near & far distances when matching up |
---|
97 | splits to one another, to avoid 'cracks'. |
---|
98 | */ |
---|
99 | void setSplitPadding(Real pad) { mSplitPadding = pad; } |
---|
100 | |
---|
101 | /** Get the padding factor to apply to the near & far distances when matching up |
---|
102 | splits to one another, to avoid 'cracks'. |
---|
103 | */ |
---|
104 | Real getSplitPadding() const { return mSplitPadding; } |
---|
105 | /// Get the number of splits. |
---|
106 | uint getSplitCount() const { return mSplitCount; } |
---|
107 | |
---|
108 | /// Returns a LiSPSM shadow camera with PSSM splits base on iteration. |
---|
109 | virtual void getShadowCamera(const Ogre::SceneManager *sm, const Ogre::Camera *cam, |
---|
110 | const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration) const; |
---|
111 | |
---|
112 | /// Returns the calculated split points. |
---|
113 | inline const SplitPointList& getSplitPoints() const |
---|
114 | { return mSplitPoints; } |
---|
115 | |
---|
116 | /// Returns the optimal adjust factor for a given split. |
---|
117 | inline Real getOptimalAdjustFactor(size_t splitIndex) const |
---|
118 | { return mOptimalAdjustFactors[splitIndex]; } |
---|
119 | |
---|
120 | /// Overridden, recommended internal use only since depends on current iteration |
---|
121 | Real getOptimalAdjustFactor() const; |
---|
122 | |
---|
123 | }; |
---|
124 | /** @} */ |
---|
125 | /** @} */ |
---|
126 | } |
---|
127 | |
---|
128 | #include "OgreHeaderSuffix.h" |
---|
129 | |
---|
130 | #endif |
---|