Fix particles view information in Editor when Game window is unused
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -222,6 +222,11 @@ SceneRenderTask::~SceneRenderTask()
|
||||
Buffers->DeleteObjectNow();
|
||||
}
|
||||
|
||||
void SceneRenderTask::CameraCut()
|
||||
{
|
||||
IsCameraCut = true;
|
||||
}
|
||||
|
||||
void SceneRenderTask::CollectPostFxVolumes(RenderContext& renderContext)
|
||||
{
|
||||
if ((ActorsSource & ActorsSources::Scenes) != 0)
|
||||
|
||||
@@ -236,10 +236,7 @@ public:
|
||||
/// <summary>
|
||||
/// Marks the next rendered frame as camera cut. Used to clear the temporal effects history and prevent visual artifacts blended from the previous frames.
|
||||
/// </summary>
|
||||
API_FUNCTION() void CameraCut()
|
||||
{
|
||||
IsCameraCut = true;
|
||||
}
|
||||
API_FUNCTION() void CameraCut();
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<SceneRenderTask>(task))
|
||||
{
|
||||
if (sceneRenderTask->ActorsSource == ActorsSources::Scenes)
|
||||
{
|
||||
return sceneRenderTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
Array<ParticleEffect::ParameterOverride> ParticleEffect::GetParametersOverrides()
|
||||
|
||||
@@ -356,6 +356,11 @@ public:
|
||||
/// </summary>
|
||||
void Sync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the render task to use for particles simulation (eg. depth buffer collisions or view information).
|
||||
/// </summary>
|
||||
SceneRenderTask* GetRenderTask() const;
|
||||
|
||||
#if USE_EDITOR
|
||||
protected:
|
||||
// Exposed parameters overrides for Editor Undo.
|
||||
|
||||
Reference in New Issue
Block a user