III.5 Ray-tracing techniques

Ray-tracing is the most straightforward way to implement the main principle of GA as it uses rays to carry sound energy. In addition, ray-tracing is the most commonly used GA-based technique to model room acoustics. Ray-tracing is computationally lighter than the image-source method, especially at higher reflection orders, but it is less accurate in detection of specular reflection paths. At the same it is more general with regard to supported reflection models. In the following we start from those reflection models and then proceed to actual ray-tracing.

III.5.1 Reflection of rays
The image source technique is able to handle only ideal specular reflections as described earlier. In that sense it is a very limited model as in reality the reflections are often much more complex, especially, in a typical reflection some part of the sound energy gets diffused. Ray-tracing is a technique that can support any reflection model although here we limit ourselves to such a model in which a given fraction of energy is reflected in the specular direction, another fraction is diffused while the rest is absorbed by the reflector.

- Change the 'Absorption' coefficient to see how the rays are attenuated due to absorption.
- Change the 'Diffusion' to see how the reflection directions change between ideally specular and totally random.
- The ray split factor tells how many new rays are created in a reflection to represent the diffuse components.
- Change between different 'Emission distributions' to see how the regularity of the 'Uniform' can be broken.


Time:
Number of rays: Absorption: Diffusion: Ray split factor:
Ray emission distribution: Uniform Jittered Random | Show reflection | Visualization: Wavefronts Full ray paths Ray extensions

The implementation of specular reflections with rays is straightforward, and is based on the principle that the reflection angle of a ray should equal to the incident angle. Here we can see a straight analogy to light, as this is exactly the same as what happens when a ray of light is reflected from an ideal mirror.

Handling of diffuse reflections is a bit more complicated and there are several ways to carry those out. The most simple way to implement a diffuse reflection is to send a diffused ray to a completely random direction instead of using the specular reflection direction. If the reflector is of such material that produces reflections with both specular and diffuse components, then for each ray there is a need to determine whether a ray should be diffused or not. If the number of rays hitting the surface is sufficiently high, this will directly implement the energy division between the specular and diffuse parts.

Algorithm: Reflection of a ray from a surface

In the pseudo-code above, the determination of possible ray diffusion utilizes a rand function that returns a random number between zero and one. That is compared to the diffusion coefficient of the surface that is also in the same range. In the case of a diffuse reflection, a new direction for the ray is computed by perturbing the surface normal vector by a random vector. Note that there are several ways to determine the new direction. If a completely uniform distribution would be required then a bit different formulation would be required. Another variant to compute the new direction is to perturb the specular reflection director vector by a random vector whose magnitude is scaled by the diffusion coefficient. It is worth noting that there is no single truth on how the diffused directions should be selected based solely on the diffusion coefficient. The diffusion coefficient tells only what is the fraction of energy that is reflected in non-specular directions without telling anything of the distribution of these directions. The scattering coefficient is another related coefficient that describes uniformity of diffusion.

The diffusion model described above keeps the number of rays constant in reflections. That is computationally efficient, but physically more correct way would be to split a ray into several new rays in the case of a non-specular reflection.

Algorithm: Reflect a ray from a surface and spawn new rays to represent diffuse component of the reflection

In practice this approach, however, is challenging as the number of rays may increase rapidly. This could lead to similar exponentially growing workload as a function of the reflection order as in the image-source method. For this reason, this approach should be applied only with great care.

One option to handle diffuse reflections is to split the incoming ray into a specular ray and a diffuse ray, and send the diffuse ray directly towards the listener. The diffuse ray is terminate immediately after it hits any surface or a receiver, and it is not propagated any further. By this means it is possible to get a more realistic distribution of diffuse energy at the receiver while still keeping the ray count as low as possible when compared to the other two approaches described. Those easily suffer either from too few diffuse rays hitting the receiver or of being computationally too costly.

The final note regarding the illustration above is that there are several ways to distribute the emitted rays. One of the goals for such a distribution should be that the distribution is as even as possible such that the rays are as equally spaced as possible. This is trivial in the 2-D case as dividing a circle into sectors of the same angle is easy. However, making such an ideal distribution over a sphere in 3D is much more challenging [, and, actually, there is no exact solution to the problem beyond the Platonic Solids - out of those the dodecahedron has the most vertices, 20, meaning that distributing over 20 rays is always only approximately even]. However, in practice this is not a problem as there are numerous techniques to create random distributions where the ray spacing is sufficiently even.

Going into details of creating even ray distributions is out of the scope of this book, and it is sufficient to know that for all practical purposes totally random distribution of rays can give good enough results. However, if the number of rays is too low, then there is a need to use some additional guiding. This is illustrated above by the 'Jittered' option in which the perfectly even distribution is perturbed by small amounts to break the symmetry and still have almost even distribution as opposed to 'Random' option where there can be large gaps between some rays while some other rays are closely packed together. It is worth noting, that in creation of 3-D random distributions the naive solution of creating random vectors with an even distribution in azimuth and elevation angles is not optimal as it will result in much higher ray density at the poles of the sphere. Instead, the distribution of the elevation angles should be weighted to take this into account, and, for example, use of a Gaussian distribution for the elevation gives much even ray distribution.