Wwise SDK 2024.1.1
|
Raytracing is a technique for efficiently evaluating nth-order reflection and diffraction. The basic idea is to randomly cast rays from the listener and follow their paths through a series of reflections and diffraction. The technique is inspired by graphic rendering techniques. Maximum Reflection order [1-4] and diffraction order [1-8] values are defined in the AkSpatialAudioInitSettings
structure of AkSpatialAudio.h
. Refer to AkSpatialAudioInitSettings for more details.
In order to tweak spatial audio CPU performance and quality, the raytracing engine uses several parameters. For a detailed description of the spatial audio settings, see AkSpatialAudioInitSettings().
Tweaking the number of primary rays can be tricky as it depends on the complexity of the scene (for example, the number of triangles and diffraction edges) and the number of emitters. When CPU Limit Mode is active, the raytracing engine automatically adapts the number of primary rays to ensure CPU usage remains around the target value defined by the user. Although this mode minimizes peaks in CPU usage it cannot completely remove short and sudden peaks. Setting a high target value increases quality (number of reflection and diffraction paths found) at the cost of performance. While setting a low target value increases performance at the cost of quality. When CPU Limit Mode is active, the number of primary rays is capped at the user-defined number of primary rays (see AkSpatialAudioInitSettings). When the number of primary rays drops to 0, the raytracing engine stops scanning the environment. However, the existing sound propagation paths are still validated and updated. As a consequence, the raytracing engine still consumes CPU. Note that CPU Limit Mode doesn't have a significant effect on portal ray tracing. Portal ray tracing increases the CPU load and might therefore force the CPU Limit Mode to temporarily reduce the number of primary rays.
Reflection path validation can become expensive when the total number of rays and/or emitters is high. However, in most cases, a few reflection paths are relevant to the perception of early reflections. Path sorting is an experimental feature that attempts to validate a user-specified number of reflection paths (see AkSpatialAudioInitSettings()). Path sorting can significantly reduce the CPU load.
In the first phase, path sorting estimates the cost (length and diffraction) of each potential reflection path based on the results of the raytracing. The paths are then processed in ascending order until a maximum of n (the user-specified number of reflection paths) paths are validated. To reduce flickering (switching between paths), the previous paths are also validated. In the second phase, the best n paths are selected from the current and previous validated paths based on their final real costs.
The selection of the n best reflection paths is global to all emitters. This means that, depending on the user-specified number of paths and the number of emitters, some emitters might not have any associated reflection paths. The cost in the first phase is an estimate of the real cost, so in some cases the selected paths are not the best overall paths, and some flickering might still occur.
Load balancing provides a way to flatten CPU peaks by distributing spatial audio task computation over several frames. Spatial audio executes different types of tasks, such as ray casting and path validation, to compute the sound propagation paths (reflections and diffraction). Whenever one of these tasks needs to be performed, it is placed in a priority queue for further processing instead of being executed immediately. The tasks in the queue are then executed over the number of frames specified in the load balancing spread setting.
There are several ways to tweak spatial audio performance: you can apply a CPU limit, change the order of reflection, enable or disable diffraction and diffraction on reflections, and adjust the motion threshold setting. You can combine load balancing with the other settings to achieve the desired balance between quality and performance.
Although load balancing can be used in any scenario, it is most appropriate for scenes that involve multiple active emitters. Load balancing behavior is controlled through the AkSpatialAudioInitSettings::uLoadBalancingSpread setting (see AkSpatialAudioInitSettings). A spread of 1 frame is equivalent to disabling the feature, because every task is executed immediately. Higher values increase CPU performance, but can lead to less accurate results. For example, a spread of 4 frames for a frame buffer of 1024 samples (around 21ms at 48kHz) executes the tasks over a period of 84 ms. Spread values under 10 should not noticeably affect quality.
The following example compares the performance in the same scene with three different spread values: 1 (disable), 4, and 10. The scene has 944 triangles and 649 diffraction edges. The number of emitters is 4. Reflection order is set to 4 and diffraction is enabled.
The following table shows the effect of different load balancing values on the scene.
Spread | Average CPU % | Max CPU % |
---|---|---|
Disabled | 4.8 | 52.76 |
4 | 3.16 | 23.26 |
10 | 1.71 | 10.22 |
Does load balancing cause delays?
Not exactly. It can introduce a "delay" in updating path information, but does not add latency to the audio signal. For instance, the same rays might be used until the next update. The paths are still computed at each frame, but are not validated at each frame. This means that some paths might be less accurate. For instance, specular reflection positions might be slightly inaccurate.
Does the load balancing improve the average CPU performance?
Although load balancing primarily focuses on decreasing CPU peaks, it can also decrease CPU averages because it prevents the same type of task from appearing in the queue multiple times. If a task is in the queue, it must be executed before another task of the same type can be added to the queue.
Does load balancing improve CPU performance when there is only one emitter?
Not significantly. Path validation is the most CPU-intensive spatial audio task. Given that one path validation task is executed for each emitter, load balancing is more appropriate for situations that involve several emitters. However, it can slightly improve single-emitter scenarios by preventing redundant computations.
Whenever a spatial audio task needs to be performed, it is placed in a priority queue for further processing instead of being executed immediately. If the task is already in the queue, it is not placed in the queue again. This prevents redundant computation and reduces CPU consumption. At each frame, the number of tasks to process (N) is computed based on the number of elements in the queue and the load balancing spread settings. The first N priority tasks are pulled from the queue and executed.
In general, task priority is determined by the time at which the task was created (inserted): older tasks are executed first. For some tasks, such as the path validation tasks, the priority might be different. Whenever an emitter becomes active, the path validation task priority is increased to force the validation of the new paths. This is important to prevent delays in path creation.
There are a few limitations when defining geometries for the raytracing engine. The limitations concern both the performance and the quality of the results.
When a triangle is smaller than the sampling density, the raytracing engine is less likely to find it.
The geometry's visible angle alpha is the angle at which the geometry is seen from the point of view of the listener. Depending on the number of primary rays, the average angle (gamma) between two rays varies. The relation between alpha and gamma influences the probability of finding an intersection (a reflection or a diffraction) with the object. If gamma is smaller than alpha, the probability of finding an intersection is high. If gamma is bigger than alpha, the probability of finding an intersection is low.
The number of triangles contained in the geometry is directly related to the CPU usage of the engine: the more triangles, the higher the CPU usage. This is due to the fact that more intersection tests are required on the object. Usually, sound propagation does not require highly detailed geometry. Reducing the number of triangles can help increase the performance without sacrificing quality.
Some geometry shapes are more difficult to process than others. Usually, geometries like planes and boxes are simple to process and give the best results in terms of sound propagation. Spheres and cylinders are more prone to errors. This is due to the curvature introduced by the sphere and the cylinder. Some diffraction edges may not be found, which would cause some diffraction paths to be missed. The algorithm implements several heuristics to overcome this issue in most cases. Increasing the number of primary rays or simplifying the geometry can solve the issue as well.
The following table provides information you can use to tweak parameters for different use cases.
Symptoms | Possible solutions |
---|---|
Spatial Audio - General CPU issues |
|
Spatial Audio - Raytracing CPU is high |
|
Spatial Audio - Path Validation CPU is high and there is only one emitter |
|
Spatial Audio - Path Validation CPU is high and there are multiple emitters |
|
Spatial Audio - CPU is high (path validation and ray tracing are both involved) and there is only one emitter |
|
Questions? Problems? Need more info? Contact us, and we can help!
Visit our Support pageRegister your project and we'll help you get started with no strings attached!
Get started with Wwise