How expensive is raycasting?

Not quite, it is that too, but more.

here’s the most common type:

If you ever played a game with more than a handful number of objects - you probably witnessed a spatial index being used.

How can you tell where the user clicks in a top-down game? Well, if it’s a flat-plane game - that’s easy, but if there is any kind of verticality in the level - it requires ray-casting against level geometry, which can be quite large.

Have you seen how in most modern games character’s feet don’t penetrate the ground and align to the surface? That requires at least 1 ray-cast per foot to achieve, typically 2. Ray-casting is everywhere, and if it was done in a naive way in production - it would not meet the performance budgets of many games. As such, spatial indices are part of most rendering engines as well as most game engines.

When you come to the world of physics - spatial index becomes not only “nice”, but essential, without a spatial index you would basically have to check if each object interacts with each other object in the scene, that would become impractical very quickly and you would have to say goodbye to any kind of simulation with more than 50 objects in it or so.

Special abilities in many games are implemented using spatial queries, like “damage in square zone over here” or “apply effect to characters in a cone over there”. When you have lots of characters and lots of abilities being used - you want to quickly figure out which ones are affected. Same kind of story.

So: spatial indices. It’s spatial indices all the way down. :turtle:

5 Likes