Source Occlusion
The atmokySpatializer plug-in has an occlusion
parameter, which can be
used to simulate the occlusion of a sound source by an obstacle. The occlusion
parameter is a value between 0 and 1, where 0 means no occlusion and 1 means
full occlusion.
To set the occlusion value of a source automatically you can use the
Atmoky Occlusion Probe Group
component, which controls the Occlusion of either
the GameObject it is attached to, or the AtmokySource specified in its
Override Source
property.
Tag occluders
- Add the
Atmoky Occluder
script to every game object that should occlude audio sources and set theirOcclusion
value, which defines how strongly this object occludes audio sources. - (Optional) Choose an occlusion layer for the occluder. Working with occlusion layers can massively reduce the number of objects that need to be considered during raycasting, which improves performance.
Add occlusion probe group
- Add the
Atmoky Occlusion Probe Group
script to the audio source. - Add or delete occlusion probes in the inspector
- Adjust the position of the occlusion probe in the Scene View by selecting the occlusion probe tool and dragging the handles.
- (Optional) Turn on non-allocating raycasting for better performance. If turned on, be sure to adjust the maximum number of hits that the raycasting command should consider to your usecase. Less means better performance, but can potentially lead to some occluders not being considered if configured too low.
- (Optional) Adjust the occlusion layers considered for raycasting. Per default, all occlusion layers are considered. You can configure the raycasting to exclude certain layers, which can drastically improve performance when there are many objects in the scene.
- (Optional) Set the
Reference Object
to a different object than the Audio Listener. TheReference Object
is the object that defines the position of the target of the raycasts, which defaults to the currently activeAudio Listener
. You might want to change that to theMain Camera
or any other object that should be used as the target of the raycasts.
For every Occlusion Probe, a ray is cast from the probe to the Reference Object
,
which defaults to the active Audio Listener
.
All occluders that are hit by this ray add to the occlusion value of the probe
(which is also displayed for every probe in the inspector). Per default, the
final occlusion value of the source is then calculated by averaging the
occlusion values of all probes. You can change this behaviour by changing the
Occlusion Sensitivity
parameter: setting it to min will take the minimum
occlusion value of all probes, setting in to mean will take the mean occlusion
value of all probes, and setting it to max will take the maximum occlusion value
of all probes. All other values will interpolate between the min, mean, and max.
This way you can adjust how rapidly the occlusion value changes when one or more
probes are occluded and thus implement different occlusion behaviours.
When the game object with the ProbeGroup component is selected, all rays are visualized in the Scene View when in play mode. The color of the rays represents the occlusion value of the probe: green means no occlusion, red means full occlusion.
In Edit-Mode, all computations use the SceneView camera instead of the Reference Object
per default. This way you can adjust the occlusion probes without having to enter
play mode. You can turn off this behaviour by unchecking Use Editor Camera in Editor
in the Atmoky Occlusion Probe Group
component. The Scene View camera position in Unity
is updated quite sparsely, so occlusion values might not be updated as frequently as expected.