3
$\begingroup$

I've taken a class about ray-plane intersection on this: https://www.khanacademy.org/computing/pixar/rendering/rendering-2/v/rendering-5

Suppose we shoot a ray at the scene and this scene contains millions of triangles. How can we know if the ray intersected one of the triangle? Do we just run a check on this millions of triangle if it intersects with the ray? That would be inefficient!!

$\endgroup$
3
$\begingroup$

If you want to know all triangles that are hit by the ray, you have to check all of them. However, that doesn't mean that you have to check each of them individually. Usually, you apply some sort of space partitioning to your scene and group related objects in a bounding volume hierarchy. Then it gets a lot more efficient because you can drop multiple triangles with a single check.

For example, consider a scene with a rectangular area. You might subdivide this area into a 10x10 grid. Now check which parts of the grid are hit by the ray. All objects located in grid cells that aren't hit by the ray can be discarded and you only need to check the remaining objects. Now let's say that one of the hit objects is a human. Before you test the individual triangles, you narrow down the affected area in multiple substeps by checking against its bounding volume hierarchy. The traversal of the hierarchy might look like this: upper body hit -> left arm hit -> hand hit -> thumb hit. So with 4 checks, you can discard all triangles of the humans' mesh that do not belong to the thumb.

In case you only want to find the first triangle that is hit by the ray, you can also sort all hit cells and objects by distance before performing detailed tests. Then you start your checks at the closest object and continue until you get the first hit.

$\endgroup$
  • $\begingroup$ May I ask if these methods also applies to secondary rays? $\endgroup$ – Spade 000 Nov 10 '20 at 8:33
  • $\begingroup$ @Spade000 yes, why shouldn't they? But you have to treat them like a new ray and retest all objects. $\endgroup$ – wychmaster Nov 10 '20 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.