summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShadowMap.h
blob: c5ba2eaa9d85a678fd18d50268de679537487eee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/****************************************************************************
**
** Copyright (C) 2008-2012 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#ifndef QT3DS_RENDER_SHADOW_MAP_H
#define QT3DS_RENDER_SHADOW_MAP_H
#include "Qt3DSRenderContextCore.h"
#include "foundation/Qt3DSAtomic.h"
#include "foundation/Qt3DSMat44.h"
#include "foundation/Qt3DSVec3.h"
#include "foundation/Qt3DSFlags.h"
#include "foundation/StringTable.h"
#include "render/Qt3DSRenderBaseTypes.h"
#include "render/Qt3DSRenderTexture2D.h"
#ifdef _INTEGRITYPLATFORM
#include "render/Qt3DSRenderTextureCube.h"
#endif

namespace qt3ds {
namespace render {

    struct SLayerRenderData;

    struct ShadowMapModes
    {
        enum Enum {
            SSM, ///< standard shadow mapping
            VSM, ///< variance shadow mapping
            CUBE, ///< cubemap omnidirectional shadows
        };
    };

    struct ShadowFilterValues
    {
        enum Enum {
            NONE = 1 << 0, ///< hard shadows
            PCF = 1 << 1, ///< Percentage close filtering
            BLUR = 1 << 2, ///< Gausian Blur
        };
    };

    struct SShadowMapEntry
    {
        SShadowMapEntry()
            : m_LightIndex(QT3DS_MAX_U32)
            , m_ShadowMapMode(ShadowMapModes::SSM)
            , m_ShadowFilterFlags(ShadowFilterValues::NONE)
        {
        }

        SShadowMapEntry(QT3DSU32 index, ShadowMapModes::Enum mode, ShadowFilterValues::Enum filter,
                        NVRenderTexture2D &depthMap, NVRenderTexture2D &depthCopy,
                        NVRenderTexture2D &depthTemp)
            : m_LightIndex(index)
            , m_ShadowMapMode(mode)
            , m_ShadowFilterFlags(filter)
            , m_DepthMap(depthMap)
            , m_DepthCopy(depthCopy)
            , m_DepthCube(NULL)
            , m_CubeCopy(NULL)
            , m_DepthRender(depthTemp)
        {
        }

        SShadowMapEntry(QT3DSU32 index, ShadowMapModes::Enum mode, ShadowFilterValues::Enum filter,
                        NVRenderTextureCube &depthCube, NVRenderTextureCube &cubeTmp,
                        NVRenderTexture2D &depthTemp)
            : m_LightIndex(index)
            , m_ShadowMapMode(mode)
            , m_ShadowFilterFlags(filter)
            , m_DepthMap(NULL)
            , m_DepthCopy(NULL)
            , m_DepthCube(depthCube)
            , m_CubeCopy(cubeTmp)
            , m_DepthRender(depthTemp)
        {
        }

        QT3DSU32 m_LightIndex; ///< the light index it belongs to
        ShadowMapModes::Enum m_ShadowMapMode; ///< shadow map method
        ShadowFilterValues::Enum m_ShadowFilterFlags; ///< shadow filter mode

        // PKC : Adding the DepthRender buffer allows us to have a depth+stencil format when filling
        // the shadow maps (depth+stencil is necessary), but use a more compact format for the
        // actual
        // shadow map used at shade time.  See if it's worth adding.
        NVScopedRefCounted<NVRenderTexture2D> m_DepthMap; ///< shadow map texture
        NVScopedRefCounted<NVRenderTexture2D>
            m_DepthCopy; ///< shadow map buffer used during blur passes
        NVScopedRefCounted<NVRenderTextureCube> m_DepthCube; ///< shadow cube map
        NVScopedRefCounted<NVRenderTextureCube>
            m_CubeCopy; ///< cube map buffer used during the blur passes
        NVScopedRefCounted<NVRenderTexture2D>
            m_DepthRender; ///< shadow depth+stencil map used during rendering

        QT3DSMat44 m_LightVP; ///< light view projection matrix
        QT3DSMat44 m_LightCubeView[6]; ///< light cubemap view matrices
        QT3DSMat44 m_LightView; ///< light view transform
    };

    class Qt3DSShadowMap : public NVRefCounted
    {
        typedef nvvector<SShadowMapEntry> TShadowMapEntryList;

    public:
        IQt3DSRenderContext &m_Context;
        volatile QT3DSI32 mRefCount;

    public:
        Qt3DSShadowMap(IQt3DSRenderContext &inContext);
        ~Qt3DSShadowMap();

        QT3DS_IMPLEMENT_REF_COUNT_ADDREF_RELEASE(m_Context.GetAllocator())

        /*
         * @brief Add a shadow map entry
         *		  This creates a new shadow map if it does not exist or changed
         *
         * @param[in] index		shadow map entry index
         * @param[in] width		shadow map width
         * @param[in] height	shadow map height
         * @param[in] format	shadow map format
         * @param[in] samples	shadow map sample count
         * @param[in] mode		shadow map mode like SSM, VCM
         * @param[in] filter	soft shadow map mode filter like PCF
         *
         * @ return no return
         */
        void AddShadowMapEntry(QT3DSU32 index, QT3DSU32 width, QT3DSU32 height,
                               NVRenderTextureFormats::Enum format, QT3DSU32 samples,
                               ShadowMapModes::Enum mode, ShadowFilterValues::Enum filter);

        /*
         * @brief Get a shadow map entry
         *
         * @param[in] index		shadow map entry index
         *
         * @ return shadow map entry or NULL
         */
        SShadowMapEntry *GetShadowMapEntry(QT3DSU32 index);

        /*
         * @brief Get shadow map entry count
         *
         * @ return count of shadow map entries
         */
        QT3DSU32 GetShadowMapEntryCount() { return m_ShadowMapList.size(); }

        static Qt3DSShadowMap *Create(IQt3DSRenderContext &inContext);

    private:
        TShadowMapEntryList m_ShadowMapList; ///< List of shadow map entries
    };
}
}

#endif