diff --git a/engine/src/render/cascaded_shadow_maps/plugin.cpp b/engine/src/render/cascaded_shadow_maps/plugin.cpp index 53d2848fad..c6bf5c9eb6 100644 --- a/engine/src/render/cascaded_shadow_maps/plugin.cpp +++ b/engine/src/render/cascaded_shadow_maps/plugin.cpp @@ -27,10 +27,14 @@ void cubos::engine::cascadedShadowMapsPlugin(Cubos& cubos) cubos.system("create cascaded shadow maps") .tagged(createCascadedShadowMapsTag) - .call([](const Window& window, Query query, + .call([](const Window& window, Query query, Query cameras) { - for (auto [caster] : query) + for (auto [caster, active] : query) { + if (!active.active) + { + continue; + } // Remove shadow maps for cameras that no longer exist std::vector removedCameras; for (auto& [cameraEntity, shadowMap] : caster.shadowMaps) diff --git a/engine/src/render/cascaded_shadow_maps_rasterizer/plugin.cpp b/engine/src/render/cascaded_shadow_maps_rasterizer/plugin.cpp index e829636847..b0c873e9cb 100644 --- a/engine/src/render/cascaded_shadow_maps_rasterizer/plugin.cpp +++ b/engine/src/render/cascaded_shadow_maps_rasterizer/plugin.cpp @@ -134,20 +134,24 @@ void cubos::engine::cascadedShadowMapsRasterizerPlugin(Cubos& cubos) .after(createGBufferTag) .call( [](State& state, const Window& window, const RenderMeshPool& pool, - Query lights, + Query lights, Query cameras, Query meshes) { auto& rd = window->renderDevice(); - for (auto [cameraEntity, cameraLocalToWorld, camera, active, drawsTo, gBuffer] : cameras) + for (auto [cameraEntity, cameraLocalToWorld, camera, CameraActive, drawsTo, gBuffer] : cameras) { - if (!active.active) + if (!CameraActive.active) { continue; } - for (auto [caster, light, localToWorld] : lights) + for (auto [caster, light, localToWorld, lightActive] : lights) { + if (!lightActive.active) + { + continue; + } auto& shadowMap = caster.shadowMaps.at(cameraEntity); // Check if we need to recreate the framebuffer. if (shadowMap->previousCascades != shadowMap->cascades) diff --git a/engine/src/render/deferred_shading/plugin.cpp b/engine/src/render/deferred_shading/plugin.cpp index 04539858bc..a6432e5b70 100644 --- a/engine/src/render/deferred_shading/plugin.cpp +++ b/engine/src/render/deferred_shading/plugin.cpp @@ -207,10 +207,10 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos) .tagged(deferredShadingTag) .call([](State& state, const Window& window, const RenderEnvironment& environment, const ShadowAtlas& shadowAtlas, - Query> + Query> directionalLights, - Query pointLights, - Query> spotLights, + Query pointLights, + Query> spotLights, Query targets, Query cameras) { auto& rd = window->renderDevice(); @@ -218,9 +218,9 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos) for (auto [targetEnt, hdr, gBuffer, ssao, deferredShading] : targets) { // Find the cameras that draw to the GBuffer. - for (auto [cameraEntity, localToWorld, camera, active, drawsTo] : cameras.pin(1, targetEnt)) + for (auto [cameraEntity, localToWorld, camera, cameraActive, drawsTo] : cameras.pin(1, targetEnt)) { - if (!active.active) + if (!cameraActive.active) { continue; } @@ -257,8 +257,13 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos) int directionalLightIndex = 0; Texture2DArray directionalShadowMap = nullptr; - for (auto [lightLocalToWorld, light, caster] : directionalLights) + for (auto [lightLocalToWorld, light, lightActive, caster] : directionalLights) { + if (!lightActive.active) + { + continue; + } + auto& perLight = perScene.directionalLights[perScene.numDirectionalLights++]; perLight.direction = glm::normalize(lightLocalToWorld.mat * glm::vec4(0.0F, 0.0F, 1.0F, 0.0F)); perLight.color = glm::vec4(light.color, 1.0F); @@ -338,8 +343,13 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos) directionalLightIndex++; } - for (auto [lightLocalToWorld, light] : pointLights) + for (auto [lightLocalToWorld, light, lightActive] : pointLights) { + if (!lightActive.active) + { + continue; + } + auto& perLight = perScene.pointLights[perScene.numPointLights++]; perLight.position = lightLocalToWorld.mat * glm::vec4(0.0F, 0.0F, 0.0F, 1.0F); perLight.color = glm::vec4(light.color, 1.0F); @@ -347,8 +357,13 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos) perLight.range = light.range; } - for (auto [lightLocalToWorld, light, caster] : spotLights) + for (auto [lightLocalToWorld, light, lightActive, caster] : spotLights) { + if (!lightActive.active) + { + continue; + } + auto& perLight = perScene.spotLights[perScene.numSpotLights++]; perLight.position = lightLocalToWorld.mat * glm::vec4(0.0F, 0.0F, 0.0F, 1.0F); perLight.direction = glm::normalize(lightLocalToWorld.mat * glm::vec4(0.0F, 0.0F, 1.0F, 0.0F)); diff --git a/engine/src/render/shadow_atlas/plugin.cpp b/engine/src/render/shadow_atlas/plugin.cpp index 36aec55a31..f8c8491f87 100644 --- a/engine/src/render/shadow_atlas/plugin.cpp +++ b/engine/src/render/shadow_atlas/plugin.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,7 @@ void cubos::engine::shadowAtlasPlugin(Cubos& cubos) cubos.system("reserve space for shadow casters") .tagged(reserveShadowCastersTag) - .call([](ShadowAtlas& atlas, Query casters) { + .call([](ShadowAtlas& atlas, Query casters) { atlas.slots.clear(); atlas.slotsMap.clear(); atlas.slots.push_back( @@ -46,8 +47,9 @@ void cubos::engine::shadowAtlasPlugin(Cubos& cubos) int id = 1; - for (auto [caster] : casters) + for (auto [caster, active] : casters) { + bool foundSlot = false; caster.baseSettings.id = id++; for (const auto& slot : atlas.slots) diff --git a/engine/src/render/shadow_atlas_rasterizer/plugin.cpp b/engine/src/render/shadow_atlas_rasterizer/plugin.cpp index 93597df459..be4e622772 100644 --- a/engine/src/render/shadow_atlas_rasterizer/plugin.cpp +++ b/engine/src/render/shadow_atlas_rasterizer/plugin.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -124,7 +125,7 @@ void cubos::engine::shadowAtlasRasterizerPlugin(Cubos& cubos) .tagged(drawToShadowAtlasTag) .call([](State& state, const Window& window, const RenderMeshPool& pool, ShadowAtlas& atlas, ShadowAtlasRasterizer& rasterizer, - Query lights, + Query lights, Query meshes) { auto& rd = window->renderDevice(); @@ -159,8 +160,13 @@ void cubos::engine::shadowAtlasRasterizerPlugin(Cubos& cubos) atlas.cleared = true; } - for (auto [caster, light, localToWorld] : lights) + for (auto [caster, light, localToWorld, active] : lights) { + if (!active.active) + { + continue; + } + // Get light viewport auto slot = atlas.slotsMap.at(caster.baseSettings.id); diff --git a/engine/src/render/ssao/plugin.cpp b/engine/src/render/ssao/plugin.cpp index 7fae9d8f32..ad7025c6fc 100644 --- a/engine/src/render/ssao/plugin.cpp +++ b/engine/src/render/ssao/plugin.cpp @@ -11,13 +11,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include