Optimize Spline debug rendering far from camera

This commit is contained in:
Wojtek Figat
2025-07-14 21:09:28 +02:00
parent eda7f7e90f
commit 20f1e67700

View File

@@ -6,6 +6,7 @@
#include "Engine/Core/Math/BoundingFrustum.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Scripting/ManagedCLR/MCore.h"
#include "Engine/Engine/Units.h"
Spline::Spline(const SpawnParams& params)
: Actor(params)
@@ -506,16 +507,33 @@ namespace
return;
Spline::Keyframe* prev = spline->Curve.GetKeyframes().Get();
Vector3 prevPos = transform.LocalToWorld(prev->Value.Translation);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(prevPos, NodeSizeByDistance(prevPos, scaleByDistance)), color, 0.0f, depthTest);
for (int32 i = 1; i < count; i++)
float distance = Vector3::Distance(prevPos, DebugDraw::GetViewPos());
if (distance < METERS_TO_UNITS(800)) // 800m
{
Spline::Keyframe* next = prev + 1;
Vector3 nextPos = transform.LocalToWorld(next->Value.Translation);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(nextPos, NodeSizeByDistance(nextPos, scaleByDistance)), color, 0.0f, depthTest);
const float d = (next->Time - prev->Time) / 3.0f;
DEBUG_DRAW_BEZIER(prevPos, prevPos + prev->TangentOut.Translation * d, nextPos + next->TangentIn.Translation * d, nextPos, color, 0.0f, depthTest);
prev = next;
prevPos = nextPos;
// Bezier curve
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(prevPos, NodeSizeByDistance(prevPos, scaleByDistance)), color, 0.0f, depthTest);
for (int32 i = 1; i < count; i++)
{
Spline::Keyframe* next = prev + 1;
Vector3 nextPos = transform.LocalToWorld(next->Value.Translation);
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(nextPos, NodeSizeByDistance(nextPos, scaleByDistance)), color, 0.0f, depthTest);
const float d = (next->Time - prev->Time) / 3.0f;
DEBUG_DRAW_BEZIER(prevPos, prevPos + prev->TangentOut.Translation * d, nextPos + next->TangentIn.Translation * d, nextPos, color, 0.0f, depthTest);
prev = next;
prevPos = nextPos;
}
}
else
{
// Simplified
for (int32 i = 1; i < count; i++)
{
Spline::Keyframe* next = prev + 1;
Vector3 nextPos = transform.LocalToWorld(next->Value.Translation);
DEBUG_DRAW_LINE(prevPos, nextPos, color, 0.0f, depthTest);
prev = next;
prevPos = nextPos;
}
}
}
}