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.
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.
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.
|III.4 From specular reflection paths to an impulse response (previous)||III Modeling Techniques based on Geometrical Acoustics (up)||III.5.2 Main differences to the image source method (next)|