@@ -90,40 +90,39 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::update(FEngine& engine, FVie
90
90
}
91
91
92
92
void ShadowMapManager::reset () noexcept {
93
- mCascadeShadowMaps . clear () ;
94
- mSpotShadowMaps . clear () ;
93
+ mDirectionalShadowMapCount = 0 ;
94
+ mSpotShadowMapCount = 0 ;
95
95
}
96
96
97
97
void ShadowMapManager::setDirectionalShadowMap (size_t lightIndex,
98
98
LightManager::ShadowOptions const * options) noexcept {
99
99
assert_invariant (options->shadowCascades <= CONFIG_MAX_SHADOW_CASCADES);
100
+
101
+ // this updates getCascadedShadowMap()
102
+ mDirectionalShadowMapCount = options->shadowCascades ;
103
+ utils::Slice<ShadowMap> cascadedShadowMap = getCascadedShadowMap ();
100
104
for (size_t c = 0 ; c < options->shadowCascades ; c++) {
101
- const size_t i = c;
102
- assert_invariant (i < CONFIG_MAX_SHADOW_CASCADES);
103
- auto * pShadowMap = getShadowMap (i);
104
- pShadowMap->initialize (lightIndex, ShadowType::DIRECTIONAL, i, 0 , options);
105
- mCascadeShadowMaps .push_back (pShadowMap);
105
+ ShadowMap& shadowMap = cascadedShadowMap[c];
106
+ shadowMap.initialize (lightIndex, ShadowType::DIRECTIONAL, c, 0 , options);
106
107
}
107
108
}
108
109
109
110
void ShadowMapManager::addShadowMap (size_t lightIndex, bool spotlight,
110
111
LightManager::ShadowOptions const * options) noexcept {
111
112
if (spotlight) {
112
- const size_t c = mSpotShadowMaps . size () ;
113
+ const size_t c = mSpotShadowMapCount ++ ;
113
114
const size_t i = c + CONFIG_MAX_SHADOW_CASCADES;
114
115
assert_invariant (i < CONFIG_MAX_SHADOWMAPS);
115
- auto * pShadowMap = getShadowMap (i);
116
- pShadowMap->initialize (lightIndex, ShadowType::SPOT, i, 0 , options);
117
- mSpotShadowMaps .push_back (pShadowMap);
116
+ auto & shadowMap = getShadowMap (i);
117
+ shadowMap.initialize (lightIndex, ShadowType::SPOT, i, 0 , options);
118
118
} else {
119
119
// point-light, generate 6 independent shadowmaps
120
120
for (size_t face = 0 ; face < 6 ; face++) {
121
- const size_t c = mSpotShadowMaps . size () ;
121
+ const size_t c = mSpotShadowMapCount ++ ;
122
122
const size_t i = c + CONFIG_MAX_SHADOW_CASCADES;
123
123
assert_invariant (i < CONFIG_MAX_SHADOWMAPS);
124
- auto * pShadowMap = getShadowMap (i);
125
- pShadowMap->initialize (lightIndex, ShadowType::POINT, i, face, options);
126
- mSpotShadowMaps .push_back (pShadowMap);
124
+ auto & shadowMap = getShadowMap (i);
125
+ shadowMap.initialize (lightIndex, ShadowType::POINT, i, face, options);
127
126
}
128
127
}
129
128
}
@@ -179,11 +178,11 @@ FrameGraphId<FrameGraphTexture> ShadowMapManager::render(FEngine& engine, FrameG
179
178
// Directional, cascaded shadow maps
180
179
auto const directionalShadowCastersRange = view.getVisibleDirectionalShadowCasters ();
181
180
if (!directionalShadowCastersRange.empty ()) {
182
- for (auto * pShadowMap : mCascadeShadowMaps ) {
181
+ for (auto & shadowMap : getCascadedShadowMap () ) {
183
182
// for the directional light, we already know if it has visible shadows.
184
- if (pShadowMap-> hasVisibleShadows ()) {
183
+ if (shadowMap. hasVisibleShadows ()) {
185
184
passList.push_back ({
186
- {}, pShadowMap , directionalShadowCastersRange,
185
+ {}, &shadowMap , directionalShadowCastersRange,
187
186
VISIBLE_DIR_SHADOW_RENDERABLE });
188
187
}
189
188
}
@@ -192,10 +191,10 @@ FrameGraphId<FrameGraphTexture> ShadowMapManager::render(FEngine& engine, FrameG
192
191
// Point lights and Spotlight shadow maps
193
192
auto const spotShadowCastersRange = view.getVisibleSpotShadowCasters ();
194
193
if (!spotShadowCastersRange.empty ()) {
195
- for (auto * pShadowMap : mSpotShadowMaps ) {
196
- assert_invariant (!pShadowMap-> isDirectionalShadow ());
194
+ for (auto & shadowMap : getSpotShadowMaps () ) {
195
+ assert_invariant (!shadowMap. isDirectionalShadow ());
197
196
passList.push_back ({
198
- {}, pShadowMap , spotShadowCastersRange,
197
+ {}, &shadowMap , spotShadowCastersRange,
199
198
VISIBLE_DYN_SHADOW_RENDERABLE });
200
199
}
201
200
}
@@ -517,10 +516,11 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::updateCascadeShadowMaps(FEng
517
516
};
518
517
519
518
bool hasVisibleShadows = false ;
520
- if (!mCascadeShadowMaps .empty ()) {
519
+ utils::Slice<ShadowMap> cascadedShadowMaps = getCascadedShadowMap ();
520
+ if (!cascadedShadowMaps.empty ()) {
521
521
// Even if we have more than one cascade, we cull directional shadow casters against the
522
522
// entire camera frustum, as if we only had a single cascade.
523
- ShadowMap& shadowMap = * mCascadeShadowMaps [0 ];
523
+ ShadowMap& shadowMap = cascadedShadowMaps [0 ];
524
524
525
525
const auto direction = options.transform * lightData.elementAt <FScene::DIRECTION>(0 );
526
526
@@ -558,7 +558,7 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::updateCascadeShadowMaps(FEng
558
558
vsFar = std::max (vsFar, sceneInfo.vsNearFar .y );
559
559
}
560
560
561
- const size_t cascadeCount = mCascadeShadowMaps .size ();
561
+ const size_t cascadeCount = cascadedShadowMaps .size ();
562
562
563
563
// We divide the camera frustum into N cascades. This gives us N + 1 split positions.
564
564
// The first split position is the near plane; the last split position is the far plane.
@@ -592,11 +592,9 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::updateCascadeShadowMaps(FEng
592
592
// note: normalBias is set to zero for VSM
593
593
const float normalBias = shadowMapInfo.vsm ? 0 .0f : 0 .5f * lcm.getShadowNormalBias (0 );
594
594
595
- for (size_t i = 0 , c = mCascadeShadowMaps .size (); i < c; i++) {
596
- assert_invariant (mCascadeShadowMaps [i]);
597
-
595
+ for (size_t i = 0 , c = cascadedShadowMaps.size (); i < c; i++) {
598
596
// Compute the frustum for the directional light.
599
- ShadowMap& shadowMap = * mCascadeShadowMaps [i];
597
+ ShadowMap& shadowMap = cascadedShadowMaps [i];
600
598
assert_invariant (shadowMap.getLightIndex () == 0 );
601
599
602
600
sceneInfo.csNearFar = { csSplitPosition[i], csSplitPosition[i + 1 ] };
@@ -643,7 +641,7 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::updateCascadeShadowMaps(FEng
643
641
}
644
642
645
643
uint32_t cascades = 0 ;
646
- cascades |= uint32_t (mCascadeShadowMaps .size ());
644
+ cascades |= uint32_t (cascadedShadowMaps .size ());
647
645
cascades |= cascadeHasVisibleShadows << 8u ;
648
646
649
647
mShadowMappingUniforms .directionalShadows = directionalShadowsMask;
@@ -852,16 +850,17 @@ ShadowMapManager::ShadowTechnique ShadowMapManager::updateSpotShadowMaps(FEngine
852
850
lightData.data <FScene::SHADOW_INFO>());
853
851
854
852
ShadowTechnique shadowTechnique{};
855
- if (!mSpotShadowMaps .empty ()) {
853
+ utils::Slice<ShadowMap> const spotShadowMaps = getSpotShadowMaps ();
854
+ if (!spotShadowMaps.empty ()) {
856
855
shadowTechnique |= ShadowTechnique::SHADOW_MAP;
857
- for (auto const * pShadowMap : mSpotShadowMaps ) {
858
- const size_t lightIndex = pShadowMap-> getLightIndex ();
856
+ for (ShadowMap const & shadowMap : spotShadowMaps ) {
857
+ const size_t lightIndex = shadowMap. getLightIndex ();
859
858
// gather the per-light (not per shadow map) information. For point lights we will
860
859
// "see" 6 shadowmaps (one per face), we must use the first face one, the shader
861
860
// knows how to find the entry for other faces (they're guaranteed to be sequential).
862
- if (pShadowMap-> getFace () == 0 ) {
861
+ if (shadowMap. getFace () == 0 ) {
863
862
shadowInfo[lightIndex].castsShadows = true ; // FIXME: is that set correctly?
864
- shadowInfo[lightIndex].index = pShadowMap-> getShadowIndex ();
863
+ shadowInfo[lightIndex].index = shadowMap. getShadowIndex ();
865
864
}
866
865
}
867
866
}
@@ -891,18 +890,18 @@ void ShadowMapManager::calculateTextureRequirements(FEngine& engine, FView& view
891
890
uint8_t layer = 0 ;
892
891
uint32_t maxDimension = 0 ;
893
892
bool elvsm = false ;
894
- for (auto * pShadowMap : mCascadeShadowMaps ) {
893
+ for (ShadowMap& shadowMap : getCascadedShadowMap () ) {
895
894
// Shadow map size should be the same for all cascades.
896
- auto const & options = pShadowMap-> getShadowOptions ();
895
+ auto const & options = shadowMap. getShadowOptions ();
897
896
maxDimension = std::max (maxDimension, options->mapSize );
898
897
elvsm = elvsm || options->vsm .elvsm ;
899
- pShadowMap-> setLayer (layer++);
898
+ shadowMap. setLayer (layer++);
900
899
}
901
- for (auto & pShadowMap : mSpotShadowMaps ) {
902
- auto const & options = pShadowMap-> getShadowOptions ();
900
+ for (ShadowMap& shadowMap : getSpotShadowMaps () ) {
901
+ auto const & options = shadowMap. getShadowOptions ();
903
902
maxDimension = std::max (maxDimension, options->mapSize );
904
903
elvsm = elvsm || options->vsm .elvsm ;
905
- pShadowMap-> setLayer (layer++);
904
+ shadowMap. setLayer (layer++);
906
905
}
907
906
908
907
const uint8_t layersNeeded = layer;
0 commit comments