版本
menu_open
Wwise SDK 2023.1.2
使用 Geometry API 模拟衍射和透射

简介

我们可以使用传给 Wwise Spatial Audio 的几何构造来模拟声音的衍射和透射。如此一来,便可完全替代游戏引擎在声障计算中使用的射线投射法。

在发声体和听者之间有物体阻挡时,Spatial Audio 会沿着物体边缘(如有)计算路径,并计算这些边缘周围声波弯曲产生的衍射系数。同时,相应地修改发声体的视入射角,并将衍射值发送给 Wwise,以便控制对声音的最终影响。通常,衍射会造成低通滤波。

此外,Spatial Audio 还会计算声音穿透几何构造的路径。在传播过程中穿透障碍物的声音需要应用透射损失系数。该系数取决于通过 API 指派给几何构造的表面属性。通常情况下,会使用低通滤波器和音量衰减来对透射损失进行建模。

下图为 Wwise 中 3D Game Object Viewer 的截图。它显示了声音在薄壁边缘周围的衍射路径以及透射损失为 100% 的透射路径。

警告: 虽然我们可以使用几何衍射和透射来完全替代游戏引擎在声障计算中使用的射线投射法,但要注意,随着几何构造越来越复杂,占用资源也会逐渐增加。因此,传给 Spatial Audio 的几何构造应尽量简单。另外,为了降低 Geometric Diffraction 的计算复杂度,最好结合运用 Room 和 Portal 抽象概念,这样会更加高效(参见“ 使用房间和门户 ”部分)。

几何衍射可用来影响发声体和听者之间的直达声音传播路径。在结合使用 Reflect 时,还可用来影响早期反射路径。

针对衍射设置几何构造

对于传给 Spatial Audio 的每项几何构造集,都要明确声明是否要将其用于计算衍射路径。为此,可使用 AkGeometryParams::EnableDiffraction 标记。此标记方便生成衍射计算所需的边缘数据,其在直达路径的几何衍射和反射路径的衍射中均有应用。

另外,还要考虑是否允许网格的边界边缘衍射声音。对于给定网格,边界边缘被定义为多重三角网格边界上仅与一个三角形相连的边缘。边缘数量越多,衍射计算的复杂度越大。因此,在网格包含不会衍射声音的边界边缘时,应禁用相应选项。

最后还要注意,指派给声学表面的声学材质不会对衍射产生任何影响,因为边缘材料并不吸收能量。边缘只会造成声波弯曲。

针对透射设置几何构造

在针对声音透射设置几何构造时不用执行额外的步骤,不过可能要针对各种几何构造类型调节透射损失系数。比如,混凝土结构可能会阻挡几乎所有的声音透射,而胶合板材质的几何构造则可能只会阻挡很少一部分声音。

AkGeometryParams::Triangles 数组中的每个 AkTriangle 都包含对 AkGeometryParams::Surfaces 数组的索引 AkTriangle::surfaceAkAcousticSurface::transmissionLoss 字段用于描述要将多少透射损失应用于穿透对应三角形的声音。该字段的取值范围为 0 ~ 1。透射损失会换算为百分比并用来评估 Wwise 曲线。对于具有给定透射损失的声音,最终应用的音量衰减和滤波器值取决于工程中定义的曲线。在默认情况下,使用工程 Occlusion 曲线。自定义透射曲线可在添加到声音的 Attenuation ShareSet 中创建。另外,您还可以将透射损失作为内置参数来加以应用,并将其映射至 RTPC。

直达路径的几何衍射

Refer to the Geometric Diffraction demo and its code in the Integration Demo 示例 (in SDK/samples/IntegrationDemo) for an example of using geometry for the purpose of geometric diffraction of the direct path. Look for Spatial Audio Demos > Geometry Demo.

针对衍射和透射设置声音

在 Wwise 设计工具的 Positioning 选项卡中,确保选中 Enable Diffraction and Transmission。此复选框用来启用与衍射和透射相关的 Spatial Audio 功能,包括:

  • 在适用情况下通过几何构造或 Portal 来计算声音的衍射路径。只要游戏对象当前播放的声音启用了衍射和透射,Spatial Audio 就会针对其执行路径计算。若同一游戏对象在播放多个启用了衍射的声音,则仅执行一次路径计算。
  • 计算声音穿透几何构造或在两个 Room 之间的透射路径。最终透射损失系数总是取透射路径当中出现的最大透射损失值,无论其来自 Room 的 AkRoomParams::transmissionLoss 还是与三角形关联的 AkAcousticSurface::TransmissionLoss
  • 在设定了 Spatial Audio 的初始化设置 AkSpatialAudioInitSettings::bCalcEmitterVirtualPosition 的情况下,针对衍射路径生成虚拟位置并将其发送到声音引擎来渲染声音。
  • 根据衍射系数和透射损失系数应用曲线。

在默认情况下,工程 Obstruction 曲线用于衍射,工程 Occlusion 曲线用于透射。若游戏还通过 AK::SoundEngine::SetObjectObstructionAndOcclusion 设定了声障值或声笼值,则会添加这些值。

可通过向声音添加 Attenuation ShareSet 来创建自定义衍射和透射曲线。使用 Attenuation Editor 创建自定义 Volume、LPF 和 HPF 曲线并在监控过程中进行微调。有关详细信息,请参阅 Wwise Help 的应用衰减章节。

Wwise 中的直达路径衍射和透射

通过适当设置性能分析设置和视图选项,可以在 3D Game Object Viewer 中查看衍射和透射设置(见下图)。

在此,将针对各条衍射边缘显示计算得出的发声体与听者之间路径的衍射系数。您可以通过将所绑定的 Game Parameter 添加到 Game Sync Monitor 来分析内置游戏参数值,并在 Profiler 的 Obs/Occ 选项卡中分析 Obstruction 和 Diffraction。

在 Game Object 3D Viewer 中,会在对应透射路径的旁边显示计算得出的透射损失系数。若透射损失源自于几何构造,则指示碰撞点及相应的透射损失百分比。若透射损失源自于 Room,则显示透射损失百分比并在下方附加 (Room) 文本。

跟 Portal 一样,在发声体位于听者视线之内时,Diffraction 值为 0。在穿过阴影区的过程中,该值不断增大(参见“衍射 ”部分)。有关阴影区衍射的更多详细信息以及如何使用曲线和 Built-in Diffraction Game Parameter 的论述,请参阅“Room 和 Portal”的 衍射 部分。

直达路径衍射与 Spatial Audio Room 和 Portal 的相互影响

在使用 Spatial Audio Room 和 Portal(参见“ 使用房间和门户 ”部分)时,Portal 也会对相邻房间内直达声音的衍射建模。这两个系统互为补充,对于与听者不在同一房间的发声体,确保不会搜索几何构造驱动的衍射路径。Room 和 Portal 比几何构造的计算效率高很多。为了降低计算复杂度,最好结合使用两个系统。

早期反射的几何衍射

Refer to the Reflect Diffraction demo and its code in the Integration Demo 示例 (in SDK/samples/IntegrationDemo) for an example of using geometry for the purpose of geometric diffraction of Early Reflections. Look for Spatial Audio Demos > Reflect Demo.

如上文所述,早期反射可能会在边缘附近发生衍射。在发声体连通 Reflect 的情况下,Spatial Audio 支持对这一现象建模。

在解释如何建模之前,我们需要先定义可视区衍射。

在下图中,发声体位于听者视线之内,但听者并不在镜面反射路径上。因此,它在可视区。如“衍射 ”中所述,可视区也会出现衍射。不过,在 Wwise Spatial Audio 中,无论是 Room 和 Portal 还是直达路径模型的 Geometric Diffraction,都不考虑可视区的衍射,因为其相较于实际直达路径可以忽略不计。然而,对于反射来说,可视区衍射会产生很大影响。若没有衍射,则只有反射区能听到早期反射(纯镜面反射)。一旦听者进入可视区,反射就会不起作用。在启用衍射后,边缘会衍射反射波。这样在进入和离开反射区时虽然有滤波和衰减,但听者仍可感知到反射。

In the reflection zone, there is no diffracted path and, therefore, no diffraction value is calculated, because the specular reflection is assumed to take over. 在反射区和可视区之间的边界处,给定边缘的可视区衍射计算值为 0;在可视区和阴影区之间的边界处,该值为 100。

对于高阶早期反射,同时存在可视区和阴影区衍射。

针对适用的声音启用反射

在 Wwise 设计工具中,针对所有需要反射的声音将所需的早期反射发送设置为带有 Reflect 的辅助总线。有关更多详细信息,请参阅 Wwise 工程设置 。在此,既不需要针对衍射反射专门设置并启用衍射,也不需要为几何构造启用衍射。

Reflect 中的设置

在 Reflect 中,受衍射影响的反射将呈现为镜像声源。您可以根据衍射状况使用以下三条曲线来设计衍射对反射的影响:Diffraction Attenuation(衍射衰减)、Diffraction LPF(衍射 LPF)和 Diffraction HPF(衍射 HPF)。有关更多详细信息,请参阅 Reflect 文档

结合 Room 和 Portal 使用几何构造 API

我们可以结合 Wwise Spatial Audio 中的 Room 和 Portal 使用几何构造 API 来构建反射和衍射模型。为此,可将 Room 和 Portal 网络视为对周围几何构造的上层抽象(或者说细节程度较低)。适当地结合 Room 和 Portal 使用上层几何构造,可以让声学环境的模拟具有一定细节并且高效。

通过 Portal 模拟几何衍射

若发声体正在播放声音且正确设置了几何衍射(参见 针对衍射和透射设置声音 部分),但其与听者不在同一 Room,则按照以下方式计算几何路径:

  • 使用 Room 和 Portal 网络来计算从发声体到听者的声音传播路径。
  • 对于每一条路径,使用几何衍射算法来计算发声体和最靠近发声体的 Portal 之间的路径段(将该 Portal 视为听者)。除非从听者的角度来看发声体位于某个 Portal 正后方,否则只计算一条几何路径(检测到的最短路径)。计算发声体和 Portal 之间的其他路径只会造成虚声源位置重复,因此是不必要的。
  • 在两个 Portal 之间不存在直接视线时,同样使用几何衍射来计算两者之间的路径段。每次在场景中添加/移除几何构造或 Portal 时都会执行这些计算,并会在需要时重复使用。一般情况下,只会使用两个 Portal 之间的最短路径。不过,若听者位于其中一个 Portal 正后方,则会使用多条路径,以此避免在听者从某一 Room 慢慢进入另一 Room 时通过 Portal 听到的声音出现间断。
  • 对于每一条路径,使用几何衍射算法来计算听者和最靠近听者的 Portal 之间的路径段(将该 Portal 视为发声体)。
  • 将以上路径合并成结果路径,并在必要时细分或附加路径。

通过 Portal 模拟反射

Reflections can pass through portals and can reflect off of walls on either or both sides of the portal. Reflections can pass through more than one portal, possibly reflecting on surfaces between them if the reflection order is high enough (refer to AkSpatialAudioInitSettings::uMaxReflectionOrder). To ensure smooth reflections through portals, we recommend that you set AkSpatialAudioInitSettings::uDiffractionOnReflectionsOrder to at least 2, but be aware that increasing this setting also increases CPU usage.

Because the portal itself describes an acoustic opening, it is not necessary to also "cut holes" in the triangle geometry to allow a sound to pass through, which would greatly increase the number of triangles. A portal box represents negative space, so remember that any geometry that intersects a portal is effectively ignored, for example in a room where the geometry is described by a box, with two triangles for each of the six sides. To ensure that sound can propagate outside the box, add a portal that intersects one of the walls along the portal's z-axis.

警告: For reflections to be accurately calculated on each side of a portal, set AkGeometryInstanceParams::RoomID to an invalid AkRoomID. Unlike diffraction, reflection paths through portals are not calculated independently for each room and then later combined. Instead, reflections are calculated exactly as if the emitter and listener were in the same room, and the portal is treated as a hole in the geometry.

有关如何使用几何构造设定 Room 之间 Portal 朝向的技巧

下图举例展示了 Portal 朝向的正确设定。

  • Geometry cut-outs allow reflection and diffraction paths to pass through the portal.
  • A rectangular opening is subtracted from any geometry overlapped by the portal.
  • Geometry cut-outs are drawn in the Game Object 3D Viewer with a dark green outline.
  • For correct cut-out detection, the planes intersected by the portal must be non-intersecting (but not necessarily parallel), and they both must span the entire width (X) and height (Y) of the portal.
  • 两个平面之间以及由 Portal 连通的两个 Room 之间允许存在间隙。不过,只有在游戏对象之前处于其中一个相邻 Room 的情况下才允许其进入 Portal。
  • 在游戏对象慢慢穿过 Portal 时,仅将传给 AK::SpatialAudio::SetGameObjectInRoom 的 Room 几何包含关系检测结果用作提示信息。The exact room is determined by projecting the game object's position onto the portal's Z-axis, and then testing if the game object is in the front-half or back-half of the portal, corresponding to the front and back rooms respectively.
  • The portal does not need to be perfectly aligned and centered between the two rooms.
  • The transition point between two rooms is the center of the cut-out. When there is a gap between the two planes, the transition point is the center of the area between the two cut-outs.

  • 确保 Portal 在 Z 轴上足够深入,以便在两个 Room 之间平滑过渡。
  • 若两个 Room 之间的过渡太过突然,一般沿 Z 轴将 Portal 延长便可解决。

Tagging Geometry for Specific Rooms (Diffraction Only).

警告: AkGeometryInstanceParams::RoomID is deprecated and the parameter will be removed in a future version. We recommend that you do not use RoomID, and instead leave it set to the default value (-1).

As an optimization, assign AkGeometryInstanceParams::RoomID if all of the following conditions apply:

  • Geometry is physically located in one room exclusively.
  • Portals are used primarily for diffraction and sound propagation of reverb.
  • Having accurate reflections pass through portals is not required.
  • The Room referenced by AkGeometryInstanceParams::RoomID is not a Reverb Zone, nor is it a parent room of a Reverb Zone. In this case, AkGeometryInstanceParams::RoomID is ignored. For more information about Reverb Zones, refer to Using Reverb Zones.

To limit the search space for ray-triangle intersection tests, you can manually assign geometry to specific rooms. 为此,请将 AkGeometryInstanceParams::RoomID 设为特定 Room 的 ID。这样可以告知 Spatial Audio,该 Room 内的 Geometry Instance 只能通过 Portal 从另一 Room 看到,无法直接看到。Because a single Geometry Instance can only be associated with one room ID, a room cannot have geometry that is visible in multiple rooms unless AkGeometryInstanceParams::RoomID is invalid. Also note that if any geometry set is associated with a particular room ID, then that room can no longer "see" geometry that is not explicitly associated with that room. After you assign a Geometry Instance to a room, Spatial Audio only looks for geometry that is specifically associated with that room ID when it simulates reflection and diffraction in that room.


此页面对您是否有帮助?

需要技术支持?

仍有疑问?或者问题?需要更多信息?欢迎联系我们,我们可以提供帮助!

查看我们的“技术支持”页面

介绍一下自己的项目。我们会竭力为您提供帮助。

来注册自己的项目,我们帮您快速入门,不带任何附加条件!

开始 Wwise 之旅