@@ -198,6 +198,7 @@ namespace cage
198198 LightComponent lightComponent;
199199 ShadowmapComponent shadowmapComponent;
200200 uint32 cascade = 0 ;
201+ bool doesRendering = true ;
201202 };
202203
203204 struct RenderPipelineImpl : public RenderPipelineConfig
@@ -1364,7 +1365,8 @@ namespace cage
13641365
13651366 // ensure that shadowmaps are rendered before the camera
13661367 for (auto &shm : data->shadowmaps )
1367- queue->enqueue (std::move (shm->renderQueue ));
1368+ if (shm->renderQueue )
1369+ queue->enqueue (std::move (shm->renderQueue ));
13681370
13691371 queue->enqueue (std::move (renderQueue));
13701372 return queue;
@@ -1552,6 +1554,20 @@ namespace cage
15521554 static constexpr Mat4 bias = Mat4 (0.5 , 0 , 0 , 0 , 0 , 0.5 , 0 , 0 , 0 , 0 , 0.5 , 0 , 0.5 , 0.5 , 0.5 , 1 );
15531555 shadowmap->shadowUni .shadowMat [shadowmap->cascade ] = bias * viewProj;
15541556 shadowmap->shadowUni .cascadesDepths [shadowmap->cascade ] = splitFar;
1557+
1558+ // progressive rendering
1559+ Holder<UniShadowedLight> cache = provisionalGraphics->cpuBuffer <UniShadowedLight>(Stringizer () + name + " _cache_" + shadowmap->cascade );
1560+ if ((frameIndex % sc.cascadesCount ) == shadowmap->cascade )
1561+ {
1562+ // render the cascade
1563+ *cache = shadowmap->shadowUni ;
1564+ }
1565+ else
1566+ {
1567+ // reuse from earlier
1568+ shadowmap->shadowUni = *cache;
1569+ shadowmap->doesRendering = false ;
1570+ }
15551571 }
15561572
15571573 void initializeShadowmapSingle ()
@@ -1586,19 +1602,20 @@ namespace cage
15861602 {
15871603 case LightTypeEnum::Directional:
15881604 {
1605+ CAGE_ASSERT (sc.cascadesCount > 0 && sc.cascadesCount <= CAGE_SHADER_MAX_SHADOWMAPSCASCADES);
15891606 Holder<ProvisionalTexture> tex;
15901607 {
1591- const String name = Stringizer () + this ->name + " _shadowmap_" + e->id () + " _cascades_" + sc.resolution ;
1608+ const String name = Stringizer () + this ->name + " _shadowmap_" + e->id () + " _cascades_" + sc.resolution + " _ " + sc. cascadesCount ;
15921609 tex = provisionalGraphics->texture (name, GL_TEXTURE_2D_ARRAY,
1593- [resolution = sc.resolution ](Texture *t)
1610+ [resolution = sc.resolution , cascadesCount = sc. cascadesCount ](Texture *t)
15941611 {
1595- t->initialize (Vec3i (resolution, resolution, CAGE_SHADER_MAX_SHADOWMAPSCASCADES ), 1 , GL_DEPTH_COMPONENT24);
1612+ t->initialize (Vec3i (resolution, resolution, cascadesCount ), 1 , GL_DEPTH_COMPONENT24);
15961613 t->filters (GL_LINEAR, GL_LINEAR, 16 );
15971614 t->wraps (GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
15981615 });
15991616 }
16001617 ShadowmapData *first = nullptr ;
1601- for (uint32 cascade = 0 ; cascade < CAGE_SHADER_MAX_SHADOWMAPSCASCADES ; cascade++)
1618+ for (uint32 cascade = 0 ; cascade < sc. cascadesCount ; cascade++)
16021619 {
16031620 auto data = createShadowmapPipeline (e, lc, sc);
16041621 data->shadowmap ->cascade = cascade;
@@ -1611,7 +1628,8 @@ namespace cage
16111628 first->shadowUni .cascadesDepths [cascade] = data->shadowmap ->shadowUni .cascadesDepths [cascade];
16121629 first->shadowUni .shadowMat [cascade] = data->shadowmap ->shadowUni .shadowMat [cascade];
16131630 }
1614- outputTasks.push_back (tasksRunAsync<RenderPipelineImpl>(" render shadowmap cascade" , [](RenderPipelineImpl &impl, uint32) { impl.taskShadowmap (); }, std::move (data)));
1631+ if (data->shadowmap ->doesRendering )
1632+ outputTasks.push_back (tasksRunAsync<RenderPipelineImpl>(" render shadowmap cascade" , [](RenderPipelineImpl &impl, uint32) { impl.taskShadowmap (); }, std::move (data)));
16151633 }
16161634 break ;
16171635 }
0 commit comments