III.5.3 Tracing of rays
In the interactive illustration below, you can investigate how rays reflect from surfaces. Similarly, you can see the effect of receiver size in the number of rays that are detected to be audible for the receiver.

- Change the 'Receiver radius' and the 'Number of rays' to see that a larger listener will detect more rays.
- In the 'Concert hall' model all the surfaces are specularly reflective with an exception of the backwalls that are diffusive. The 'Audience diffusion' can be changed with the slider.
- Movement of the source will trigger a completely new uniform emission of rays discarding the current ones.


Time:
Number of rays: Receiver radius: Audience diffusion:
Maximum reflection order: Visualization: All paths Audible paths | Show: Full ray paths

Algorithmic outline of a ray-tracer can be very simple as written out below.

Algorithm: Main function of a ray-tracer

The pseudo-code above creates a given number of rays and for each of them performs a given number of reflections. For each ray path segment an intersection with the listener is also computed. If there is such an intersection, the ray passes through the listener volume and must be recorded for the resulting response. Computationally the most heavy part here is the search for the closest intersection point.

Algorithm: Search the closest intersection point between a given line and the room geometry

This algorithm loops through all the surfaces in the geometry and computes intersection between the given line segment and the surface. If there is such an intersection, then it is compared against the minimum distance that has been found so far. If the distance is shorter, then the current surface and intersection point are recorded as the closest one so far. In the end, those variables will have the information of the closest reflection event and those are returned to the caller of the function. This search can be accelerated by the use of some spatial data structure that aims to minimize the number of required intersection computations. Those structures can be thought of as directories that are able to tell what are the possible surfaces that may give the shortest reflection distance and will skip all the other surfaces.