How do we know if a ray intersected a triangle in one in a million 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!!
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 -&gt; left arm hit -&gt; hand hit -&gt; 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.