diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs index 80bbe2214..8c1ccb1b5 100644 --- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs +++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs @@ -183,10 +183,10 @@ namespace FlaxEditor.Viewport _editor = editor; // Prepare rendering task - Task.ActorsSource = ActorsSources.ScenesAndCustomActors; + Task.ActorsSource = ActorsSources.Scenes; Task.ViewFlags = ViewFlags.DefaultEditor; - Task.Begin += RenderTaskOnBegin; - Task.CollectDrawCalls += RenderTaskOnCollectDrawCalls; + Task.Begin += OnBegin; + Task.CollectDrawCalls += OnCollectDrawCalls; Task.PostRender += OnPostRender; // Render task after the main game task so streaming and render state data will use main game task instead of editor preview @@ -390,7 +390,7 @@ namespace FlaxEditor.Viewport Editor.Instance.SceneEditing.Spawn(actor); } - private void RenderTaskOnBegin(RenderTask task, GPUContext context) + private void OnBegin(RenderTask task, GPUContext context) { _debugDrawData.Clear(); @@ -406,7 +406,7 @@ namespace FlaxEditor.Viewport } } - private void RenderTaskOnCollectDrawCalls(RenderContext renderContext) + private void OnCollectDrawCalls(RenderContext renderContext) { if (_previewStaticModel) { diff --git a/Source/Engine/Graphics/RenderTask.cpp b/Source/Engine/Graphics/RenderTask.cpp index 405e0fe45..9cd99b504 100644 --- a/Source/Engine/Graphics/RenderTask.cpp +++ b/Source/Engine/Graphics/RenderTask.cpp @@ -222,6 +222,11 @@ SceneRenderTask::~SceneRenderTask() Buffers->DeleteObjectNow(); } +void SceneRenderTask::CameraCut() +{ + IsCameraCut = true; +} + void SceneRenderTask::CollectPostFxVolumes(RenderContext& renderContext) { if ((ActorsSource & ActorsSources::Scenes) != 0) diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h index 265905e2a..3f4a9f58c 100644 --- a/Source/Engine/Graphics/RenderTask.h +++ b/Source/Engine/Graphics/RenderTask.h @@ -236,10 +236,7 @@ public: /// /// Marks the next rendered frame as camera cut. Used to clear the temporal effects history and prevent visual artifacts blended from the previous frames. /// - API_FUNCTION() void CameraCut() - { - IsCameraCut = true; - } + API_FUNCTION() void CameraCut(); /// /// The output texture (can be null if using rendering to window swap chain). Can be sued to redirect the default scene rendering output to a texture. diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp index 6ba0ee8fa..49aa59999 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp @@ -245,7 +245,7 @@ bool ParticleEmitterGraphCPUExecutor::ComputeBounds(ParticleEmitter* emitter, Pa _emitter = emitter; _effect = effect; _deltaTime = 0.0f; - _viewTask = PARTICLE_EMITTER_GET_VIEW_TASK(effect); + _viewTask = effect->GetRenderTask(); _callStack.Clear(); // Find the maximum radius of the particle light @@ -351,7 +351,7 @@ void ParticleEmitterGraphCPUExecutor::Draw(ParticleEmitter* emitter, ParticleEff _emitter = emitter; _effect = effect; _deltaTime = 0.0f; - _viewTask = PARTICLE_EMITTER_GET_VIEW_TASK(effect); + _viewTask = effect->GetRenderTask(); _callStack.Clear(); // Draw lights @@ -411,7 +411,7 @@ void ParticleEmitterGraphCPUExecutor::Update(ParticleEmitter* emitter, ParticleE _effect = effect; _particleIndex = 0; _deltaTime = dt; - _viewTask = PARTICLE_EMITTER_GET_VIEW_TASK(effect); + _viewTask = effect->GetRenderTask(); _callStack.Clear(); auto& cpu = data.Buffer->CPU; @@ -557,7 +557,7 @@ int32 ParticleEmitterGraphCPUExecutor::UpdateSpawn(ParticleEmitter* emitter, Par _effect = effect; _particleIndex = 0; _deltaTime = dt; - _viewTask = PARTICLE_EMITTER_GET_VIEW_TASK(effect); + _viewTask = effect->GetRenderTask(); _callStack.Clear(); // Spawn particles diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h index 42aca7dbb..33423e9d7 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h @@ -27,11 +27,6 @@ class ParticleEmitterGraphCPUExecutor; #define PARTICLE_EMITTER_MAX_CALL_STACK 100 -// Gets the render task for the given effect update -#define PARTICLE_EMITTER_GET_VIEW_TASK(effect) \ - (SceneRenderTask*)((effect)->CustomViewRenderTask && (effect)->CustomViewRenderTask->LastUsedFrame != 0 ? (effect)->CustomViewRenderTask.Get() : \ - (MainRenderTask::Instance && MainRenderTask::Instance->LastUsedFrame != 0 ? MainRenderTask::Instance : nullptr)) - class ParticleEmitterGraphCPUBox : public VisjectGraphBox { public: diff --git a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp index cd16a9c52..3d49efec0 100644 --- a/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp +++ b/Source/Engine/Particles/Graph/GPU/GPUParticles.cpp @@ -144,7 +144,7 @@ void GPUParticles::Execute(GPUContext* context, ParticleEmitter* emitter, Partic } // Skip if can - SceneRenderTask* viewTask = PARTICLE_EMITTER_GET_VIEW_TASK(effect); + SceneRenderTask* viewTask = effect->GetRenderTask(); const int32 threads = data.Buffer->GPU.ParticlesCountMax + data.GPU.SpawnCount; if (data.GPU.DeltaTime <= 0.0f || threads == 0 || !_mainCS) return; diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 61f0ba8ae..40594904d 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -339,6 +339,39 @@ void ParticleEffect::Sync() } } +SceneRenderTask* ParticleEffect::GetRenderTask() const +{ + const uint64 minFrame = Engine::FrameCount - 2; + + // Custom task + const auto customViewRenderTask = CustomViewRenderTask.Get(); + if (customViewRenderTask && customViewRenderTask->Enabled && customViewRenderTask->LastUsedFrame >= minFrame) + return customViewRenderTask; + + // Main task + const auto mainRenderTask = MainRenderTask::Instance; + if (mainRenderTask && mainRenderTask->Enabled && mainRenderTask->LastUsedFrame >= minFrame) + return mainRenderTask; + + // Editor viewport +#if USE_EDITOR + for (auto task : RenderTask::Tasks) + { + if (task->LastUsedFrame >= minFrame && task->Enabled) + { + if (const auto sceneRenderTask = Cast(task)) + { + if (sceneRenderTask->ActorsSource == ActorsSources::Scenes) + { + return sceneRenderTask; + } + } + } + } +#endif + return nullptr; +} + #if USE_EDITOR Array ParticleEffect::GetParametersOverrides() diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 65004278c..f6dc3788a 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -356,6 +356,11 @@ public: /// void Sync(); + /// + /// Gets the render task to use for particles simulation (eg. depth buffer collisions or view information). + /// + SceneRenderTask* GetRenderTask() const; + #if USE_EDITOR protected: // Exposed parameters overrides for Editor Undo.