Coverage Report

Created: 2025-09-04 07:15

/src/ogre/OgreMain/include/OgreShadowCameraSetupPSSM.h
Line
Count
Source (jump to first uncovered line)
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-2014 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
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 LiSPSMShadowCameraSetup
57
    {
58
        using LiSPSMShadowCameraSetup::setOptimalAdjustFactor;
59
    public:
60
        typedef std::vector<Real> SplitPointList;
61
        typedef std::vector<Real> OptimalAdjustFactorList;
62
63
    private:
64
        uint mSplitCount;
65
        SplitPointList mSplitPoints;
66
        OptimalAdjustFactorList mOptimalAdjustFactors;
67
        Real mSplitPadding;
68
69
        mutable size_t mCurrentIteration;
70
71
    public:
72
        /// @deprecated use create()
73
        PSSMShadowCameraSetup();
74
        virtual ~PSSMShadowCameraSetup();
75
76
        /// Constructor, defaults to 3 splits
77
        static ShadowCameraSetupPtr create()
78
0
        {
79
0
            return std::make_shared<PSSMShadowCameraSetup>();
80
0
        }
81
82
        /** Calculate a new splitting scheme.
83
        @param splitCount The number of splits to use
84
        @param nearDist The near plane to use for the first split
85
        @param farDist The far plane to use for the last split
86
        @param lambda Factor to use to reduce the split size 
87
        */
88
        void calculateSplitPoints(uint splitCount, Real nearDist, Real farDist, Real lambda = 0.95f);
89
90
        /** Manually configure a new splitting scheme.
91
        @param newSplitPoints A list which is splitCount + 1 entries long, containing the
92
            split points. The first value is the near point, the last value is the
93
            far point, and each value in between is both a far point of the previous
94
            split, and a near point for the next one.
95
        */
96
        void setSplitPoints(const SplitPointList& newSplitPoints);
97
98
        /** Set the LiSPSM optimal adjust factor for a given split (call after
99
            configuring splits).
100
        */
101
        void setOptimalAdjustFactor(size_t splitIndex, Real factor);
102
103
        /** Set the padding factor to apply to the near & far distances when matching up
104
            splits to one another, to avoid 'cracks'.
105
        */
106
0
        void setSplitPadding(Real pad) { mSplitPadding = pad; }
107
108
        /** Get the padding factor to apply to the near & far distances when matching up
109
            splits to one another, to avoid 'cracks'.
110
        */
111
0
        Real getSplitPadding() const { return mSplitPadding; }
112
        /// Get the number of splits. 
113
0
        uint getSplitCount() const { return mSplitCount; }
114
115
        /// Returns a LiSPSM shadow camera with PSSM splits base on iteration.
116
        void getShadowCamera(const Ogre::SceneManager *sm, const Ogre::Camera *cam,
117
            const Ogre::Viewport *vp, const Ogre::Light *light, Ogre::Camera *texCam, size_t iteration) const override;
118
119
        /// Returns the calculated split points.
120
        inline const SplitPointList& getSplitPoints() const
121
0
        { return mSplitPoints; }
122
123
        /// Returns the optimal adjust factor for a given split.
124
        inline Real getOptimalAdjustFactor(size_t splitIndex) const
125
0
        { return mOptimalAdjustFactors[splitIndex]; }
126
127
        /// Overridden, recommended internal use only since depends on current iteration
128
        Real getOptimalAdjustFactor() const override;
129
130
    };
131
    /** @} */
132
    /** @} */
133
}
134
135
#include "OgreHeaderSuffix.h"
136
137
#endif