From cbcfa4013b5da2b5288f8fda5f05ceb7210b79b3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 4 May 2026 17:29:58 +0200 Subject: [PATCH] Add `Graphics::MotionVectors::MinObjectScreenSize` to skip too small objects from drawing motion vectors --- Source/Engine/Graphics/Graphics.cpp | 1 + Source/Engine/Graphics/Graphics.h | 9 +++++++++ Source/Engine/Renderer/RenderList.cpp | 8 ++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Graphics/Graphics.cpp b/Source/Engine/Graphics/Graphics.cpp index f3395c02d..ba3f24dc7 100644 --- a/Source/Engine/Graphics/Graphics.cpp +++ b/Source/Engine/Graphics/Graphics.cpp @@ -32,6 +32,7 @@ bool Graphics::SpreadWorkload = true; #if !BUILD_RELEASE || USE_EDITOR float Graphics::TestValue = 0.0f; #endif +float Graphics::MotionVectors::MinObjectScreenSize = 0.02f; float Graphics::Shadows::MinObjectPixelSize = 2.0f; bool Graphics::PostProcessing::ColorGradingVolumeLUT = true; diff --git a/Source/Engine/Graphics/Graphics.h b/Source/Engine/Graphics/Graphics.h index aed1232f6..393fcd164 100644 --- a/Source/Engine/Graphics/Graphics.h +++ b/Source/Engine/Graphics/Graphics.h @@ -110,6 +110,15 @@ public: API_FIELD() static float MinObjectPixelSize; }; + // Motion Vectors rendering configuration. + API_CLASS(Static, Attributes="DebugCommand") class FLAXENGINE_API MotionVectors + { + DECLARE_SCRIPTING_TYPE_MINIMAL(MotionVectors); + + // The minimum screen size of objects to draw motion vectors. Improves performance by skipping too small objects (eg. sub-pixel) from rendering motion vectors. + API_FIELD() static float MinObjectScreenSize; + }; + // Post Processing effects rendering configuration. API_CLASS(Static, Attributes="DebugCommand") class FLAXENGINE_API PostProcessing { diff --git a/Source/Engine/Renderer/RenderList.cpp b/Source/Engine/Renderer/RenderList.cpp index 520548767..ee2a307b1 100644 --- a/Source/Engine/Renderer/RenderList.cpp +++ b/Source/Engine/Renderer/RenderList.cpp @@ -710,7 +710,9 @@ void RenderList::AddDrawCall(const RenderContext& renderContext, DrawPass drawMo { DrawCallsLists[(int32)DrawCallsListType::Distortion].Indices.Add(index); } - if ((drawModes & DrawPass::MotionVectors) != DrawPass::None && (staticFlags & StaticFlags::Transform) == StaticFlags::None) + if ((drawModes & DrawPass::MotionVectors) != DrawPass::None && + (staticFlags & StaticFlags::Transform) == StaticFlags::None && + RenderTools::ComputeBoundsScreenRadiusSquared(drawCall.ObjectPosition, drawCall.ObjectRadius, renderContext.View) > Math::Square(Graphics::MotionVectors::MinObjectScreenSize)) { DrawCallsLists[(int32)DrawCallsListType::MotionVectors].Indices.Add(index); } @@ -756,7 +758,9 @@ void RenderList::AddDrawCall(const RenderContextBatch& renderContextBatch, DrawP { DrawCallsLists[(int32)DrawCallsListType::Distortion].Indices.Add(index); } - if ((drawModes & DrawPass::MotionVectors) != DrawPass::None && (staticFlags & StaticFlags::Transform) == StaticFlags::None) + if ((drawModes & DrawPass::MotionVectors) != DrawPass::None && + (staticFlags & StaticFlags::Transform) == StaticFlags::None && + RenderTools::ComputeBoundsScreenRadiusSquared(bounds.Center, (float)bounds.Radius, mainRenderContext.View) > Math::Square(Graphics::MotionVectors::MinObjectScreenSize)) { DrawCallsLists[(int32)DrawCallsListType::MotionVectors].Indices.Add(index); }