Add CustomScenes feature to draw a fixed set of scenes within SceneRenderTask

This commit is contained in:
Wojtek Figat
2023-11-21 12:24:55 +01:00
parent ce905fbe86
commit 0db259e300
2 changed files with 32 additions and 6 deletions

View File

@@ -8,11 +8,12 @@
#include "Engine/Core/Collections/Sorting.h" #include "Engine/Core/Collections/Sorting.h"
#include "Engine/Debug/DebugLog.h" #include "Engine/Debug/DebugLog.h"
#include "Engine/Level/Level.h" #include "Engine/Level/Level.h"
#include "Engine/Level/Scene/Scene.h"
#include "Engine/Level/Actors/Camera.h" #include "Engine/Level/Actors/Camera.h"
#include "Engine/Level/Actors/PostFxVolume.h"
#include "Engine/Renderer/Renderer.h" #include "Engine/Renderer/Renderer.h"
#include "Engine/Render2D/Render2D.h" #include "Engine/Render2D/Render2D.h"
#include "Engine/Engine/Engine.h" #include "Engine/Engine/Engine.h"
#include "Engine/Level/Actors/PostFxVolume.h"
#include "Engine/Profiler/Profiler.h" #include "Engine/Profiler/Profiler.h"
#include "Engine/Renderer/RenderList.h" #include "Engine/Renderer/RenderList.h"
#include "Engine/Threading/Threading.h" #include "Engine/Threading/Threading.h"
@@ -202,15 +203,21 @@ void SceneRenderTask::CollectPostFxVolumes(RenderContext& renderContext)
{ {
Level::CollectPostFxVolumes(renderContext); Level::CollectPostFxVolumes(renderContext);
} }
if (EnumHasAllFlags(ActorsSource , ActorsSources::CustomActors)) if (EnumHasAllFlags(ActorsSource, ActorsSources::CustomActors))
{ {
for (Actor* a : CustomActors) for (Actor* a : CustomActors)
{ {
auto* postFxVolume = dynamic_cast<PostFxVolume*>(a); auto* postFxVolume = dynamic_cast<PostFxVolume*>(a);
if (postFxVolume && a->GetIsActive()) if (postFxVolume && a->GetIsActive())
{
postFxVolume->Collect(renderContext); 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); ASSERT_LOW_LAYER(_customActorsScene);
_customActorsScene->Draw(renderContextBatch, (SceneRendering::DrawCategory)category); _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)) if (EnumHasAllFlags(ActorsSource, ActorsSources::Scenes))
{ {
Level::DrawActors(renderContextBatch, category); Level::DrawActors(renderContextBatch, category);

View File

@@ -21,6 +21,7 @@ class PostProcessEffect;
struct RenderContext; struct RenderContext;
class Camera; class Camera;
class Actor; class Actor;
class Scene;
/// <summary> /// <summary>
/// Allows to perform custom rendering using graphics pipeline. /// Allows to perform custom rendering using graphics pipeline.
@@ -174,6 +175,11 @@ API_ENUM(Attributes="Flags") enum class ActorsSources
/// </summary> /// </summary>
CustomActors = 2, CustomActors = 2,
/// <summary>
/// The scenes from the custom collection.
/// </summary>
CustomScenes = 4,
/// <summary> /// <summary>
/// The actors from the loaded scenes and custom collection. /// The actors from the loaded scenes and custom collection.
/// </summary> /// </summary>
@@ -267,9 +273,14 @@ public:
public: public:
/// <summary> /// <summary>
/// The custom set of actors to render. /// The custom set of actors to render. Used when ActorsSources::CustomActors flag is active.
/// </summary> /// </summary>
Array<Actor*> CustomActors; API_FIELD() Array<Actor*> CustomActors;
/// <summary>
/// The custom set of scenes to render. Used when ActorsSources::CustomScenes flag is active.
/// </summary>
API_FIELD() Array<Scene*> CustomScenes;
/// <summary> /// <summary>
/// Adds the custom actor to the rendering. /// Adds the custom actor to the rendering.