# How much do linetraces cost on performance?

Quick question.

Like the title says. How much do they cost?

I have a few in my project, and i plan to add some more. Linetraces are extremely useful. Especially those that fire on tick, every frame.

I want to have as many as possible.

17 cents.

Seriously though, it really depends what you mean by a lot. Tens, probably ok. Thousands, you need to find another way.

2 Likes

Tens are probably ok you say. Well thats good enough for me atm.

Thank you!

The cost of a line trace depends not only on â€śis it a line trace,â€ť but also on how long the line is (10 units is much cheaper than 10000 units!) and how many objects â€ścouldâ€ť be hit (approximately, how many objects are in the axis-aligned bounding box of the line.)

So, long, diagonal, lines, across a battlefield: More expensive.
Short, straight down, lines, to find whether you have ground contact: Less expensive.
But, a long trace from the camera, to the sun, if the sun is above (and not on the horizon,) could be totally fine because thereâ€™s nothing to test against in the AABB.

In my head, I would estimate the cheapest line trace at 1 microsecond, and the most expensive reasonable line trace at 10 microsecond. If I want to spend 1 ms per frame on just line traces, then I can do 100 big traces, or 1000 small traces. Iâ€™m probably off by some factor, though, because I havenâ€™t measured these things for many years, and, again, very long, very diagonal, traces through cluttered environments, are massively more expensive!

4 Likes

That makes perfekt sense. Fortunately most traces that I plan to do are wery short ones.

But I have to ask one thing. what is AABB?

Axis-Aligned Bounding Box.

Btw: I wonder if thereâ€™s a good reading list for â€śgeneral game development conceptsâ€ť with the basics of 3D math, rendering, and physics somewhere. Thereâ€™s just tons of things that are not generally taught in computer science (unless you opt in,) thatâ€™s very helpful to know.

To start, I can recommend the Real-time Collision Detection book: Amazon.com
But thereâ€™s so much more â€¦

1 Like

Great rule of thumb

1 Like