From 0db259e300b8204130a1fe891d8e07cc6f01abde Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 21 Nov 2023 12:24:55 +0100 Subject: [PATCH] Add `CustomScenes` feature to draw a fixed set of scenes within `SceneRenderTask` --- Source/Engine/Graphics/RenderTask.cpp | 23 +++++++++++++++++++---- Source/Engine/Graphics/RenderTask.h | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Graphics/RenderTask.cpp b/Source/Engine/Graphics/RenderTask.cpp index 48e89f59e..8a10a0444 100644 --- a/Source/Engine/Graphics/RenderTask.cpp +++ b/Source/Engine/Graphics/RenderTask.cpp @@ -8,11 +8,12 @@ #include "Engine/Core/Collections/Sorting.h" #include "Engine/Debug/DebugLog.h" #include "Engine/Level/Level.h" +#include "Engine/Level/Scene/Scene.h" #include "Engine/Level/Actors/Camera.h" +#include "Engine/Level/Actors/PostFxVolume.h" #include "Engine/Renderer/Renderer.h" #include "Engine/Render2D/Render2D.h" #include "Engine/Engine/Engine.h" -#include "Engine/Level/Actors/PostFxVolume.h" #include "Engine/Profiler/Profiler.h" #include "Engine/Renderer/RenderList.h" #include "Engine/Threading/Threading.h" @@ -202,15 +203,21 @@ void SceneRenderTask::CollectPostFxVolumes(RenderContext& renderContext) { Level::CollectPostFxVolumes(renderContext); } - if (EnumHasAllFlags(ActorsSource , ActorsSources::CustomActors)) + if (EnumHasAllFlags(ActorsSource, ActorsSources::CustomActors)) { for (Actor* a : CustomActors) { auto* postFxVolume = dynamic_cast(a); if (postFxVolume && a->GetIsActive()) - { postFxVolume->Collect(renderContext); - } + } + } + if (EnumHasAllFlags(ActorsSource, ActorsSources::CustomScenes)) + { + for (Scene* scene : CustomScenes) + { + if (scene && scene->IsActiveInHierarchy()) + scene->Rendering.CollectPostFxVolumes(renderContext); } } } @@ -282,6 +289,14 @@ void SceneRenderTask::OnCollectDrawCalls(RenderContextBatch& renderContextBatch, ASSERT_LOW_LAYER(_customActorsScene); _customActorsScene->Draw(renderContextBatch, (SceneRendering::DrawCategory)category); } + if (EnumHasAllFlags(ActorsSource, ActorsSources::CustomScenes)) + { + for (Scene* scene : CustomScenes) + { + if (scene && scene->IsActiveInHierarchy()) + scene->Rendering.Draw(renderContextBatch, (SceneRendering::DrawCategory)category); + } + } if (EnumHasAllFlags(ActorsSource, ActorsSources::Scenes)) { Level::DrawActors(renderContextBatch, category); diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h index 9123751bc..864d95214 100644 --- a/Source/Engine/Graphics/RenderTask.h +++ b/Source/Engine/Graphics/RenderTask.h @@ -21,6 +21,7 @@ class PostProcessEffect; struct RenderContext; class Camera; class Actor; +class Scene; /// /// Allows to perform custom rendering using graphics pipeline. @@ -174,6 +175,11 @@ API_ENUM(Attributes="Flags") enum class ActorsSources /// CustomActors = 2, + /// + /// The scenes from the custom collection. + /// + CustomScenes = 4, + /// /// The actors from the loaded scenes and custom collection. /// @@ -267,9 +273,14 @@ public: public: /// - /// The custom set of actors to render. + /// The custom set of actors to render. Used when ActorsSources::CustomActors flag is active. /// - Array CustomActors; + API_FIELD() Array CustomActors; + + /// + /// The custom set of scenes to render. Used when ActorsSources::CustomScenes flag is active. + /// + API_FIELD() Array CustomScenes; /// /// Adds the custom actor to the rendering.