可见范围(HLOD)

网格的细节级别(LOD)遮挡剔除 一起,可见范围是提高大型复杂 3D 场景性能的另一个工具。

你会在这个页面中学习到:

  • 可见范围可以做什么以及它们在哪些场景中有用。

  • 如何在 Godot 中设置可见范围(手动 LOD)。

  • 如何调整可见范围以获得最佳性能及质量。

参见

如果你只需要网格在距离上变得不那么详细,但并没有手动创建 LOD 网格,请考虑依赖自动 网格的细节级别(LOD)

请注意,即使在同一网格上,依然可以同时使用自动网格 LOD 和可见范围。

它的运作方式

可见范围可与继承自 GeometryInstance3D 的任何节点一起使用。这意味着它们不仅可以与 MeshInstance3D 和 MultiMeshInstance3D 一起使用以实现艺术家控制的 HLOD,还可以与 GPUParticles3D、CPUParticles3D、Label3D、Sprite3D、AnimatedSprite3D 和 CSGShape3D 一起使用。

由于可见范围是在每个节点的基础上配置的,因此可以使用不同的节点类型作为 LOD 系统的一部分。例如,可以在近距离时显示代表一棵树的 MeshInstance3D,并在远处将其替换为 Sprite3D 顶替物,以提高性能。

HLOD 相对于传统 LOD 系统的优势在于其层次性质。单个较大的网格可以替换多个较小的网格,因此可以减少远处的绘制调用数量,但可以在近距离时保留剔除机会。例如,可以设置一组房屋,在近距离时它们使用单独的 MeshInstance3D 节点(每个房屋一个),但会变成表现一组不太详细的房屋的单个 MeshInstance3D(或使用 MultiMeshInstance3D)。

最后,当相机太近或太远时,可见范围也可用于使某些对象完全淡入淡出。这可以用于游戏玩法目的,也可以用来减少视觉混乱。例如,当 Label3D 节点离玩家太远而不可读或与玩家相关时,可以使用可见范围对其进行淡出。

设置可见范围

这是配置基本 LOD 系统的快速入门指南。遵循本指南,该 LOD 系统将在近距离时显示 SphereMesh,在相机足够远时显示 BoxMesh。还可以通过 Begin MarginEnd Margin 属性配置较小的滞后边距(hysteresis margin)。当相机在 LOD 过渡的“边缘”移动时,这可以防止 LOD 来回快速出现和消失。

选择 MeshInstance3D 节点后,可以在 GeometryInstance3D 检查器的 Visibility Range (可见范围) 部分中找到可见范围属性。

  • 添加一个 Node3D 节点,用于将两个 MeshInstance3D 节点分组到一起。

  • 添加第一个 MeshInstance3D 节点作为 Node3D 的子节点。将新的 SphereMesh 分配给其 Mesh 属性。

  • 将第一个 MeshInstance3D 的可见范围 End 设置为 10.0 ,将 End Margin 设置为 1.0

  • 添加第二个 MeshInstance3D 节点作为 Node3D 的子节点。将新的 BoxMesh 分配给其 Mesh 属性。

  • 将第二个 MeshInstance3D 的可见范围 Begin 设置为 10.0 ,将 Begin Margin 设置为 1.0

  • 将相机移开并返回到物体。注意当相机移开时,对象如何从球体(即 SphereMesh)过渡到盒子(即 BoxMesh)。

可见范围属性

在继承自 GeometryInstance3D 的任何节点的检查器中,你都可以在 GeometryInstance3D 的 Visibility Range 部分中调整以下属性:

  • Begin(开始): 当相机比该值(以 3D 单位)更接近实例的 原点 时,实例将被隐藏。

  • Begin Margin(开始边距): 用于特写过渡的滞后(hysteresis)或 Alpha 淡入淡出过渡距离(以 3D 单位表示)。此属性的行为取决于 Fade Mode (淡入淡出模式)。

  • End(结束): 当相机距离实例的 原点 远超过此值(以 3D 单位表示)时,实例将被隐藏。

  • End Margin(结束边距): 用于远距离过渡的滞后或 alpha 淡入淡出过渡距离(以 3D 单位表示)。此属性的行为取决于 Fade Mode (淡入淡出模式)。

  • Fade Mode(淡入淡出模式): 控制如何执行 LOD 级别之间的过渡。详情请参阅下文。

淡入淡出模式

备注

仅当 Visibility Range > Begin MarginVisibility Range > End Margin 大于 0.0 时,所选的淡入淡出模式才会产生可见的影响。

在检查器的 Visibility Range 部分中,有 3 种淡入淡出模式可供选择:

  • Disabled(禁用): 使用滞后(hysteresis)在 LOD 级别之间即时切换。这可以防止当玩家在 LOD 过渡点向前和向后移动时,LOD 级别快速来回切换的情况。滞后距离(hystereis distance)由 Visibility Range > Begin MarginVisibility Range > End Margin 确定。此模式可提供最佳性能,因为它不会强制渲染在淡入淡出过渡期间变得透明。

  • Self(自身): 使用 Alpha 混合在 LOD 级别之间平滑地淡入淡出。当达到其自身可见范围的极限时,节点将自行淡出。淡入淡出过渡距离由 Visibility Range > Begin MarginVisibility Range > End Margin 确定。此模式在淡入淡出过渡期间,强制对对象进行透明渲染,因此会对性能产生一定影响。

  • Dependencies: Uses alpha blending to smoothly fade between LOD levels. The node will fade-in its dependencies when reaching the limits of its own visibility range. The fade transition distance is determined by Visibility Range > Begin Margin and Visibility Range > End Margin. This mode forces transparent rendering on the object during its fade transition, so it has a performance impact. This mode is intended for hierarchical LOD systems using Visibility parent. It acts the same as Self if visibility ranges are used to perform non-hierarchical LOD.

Visibility parent

The Visibility Parent property makes it easier to set up HLOD. It allows automatically hiding child nodes if its parent is visible given its current visibility range properties.

备注

The target of Visibility Parent must inherit from GeometryInstance3D.

Despite its name, the Visibility Parent property can point to a node that is not a parent of the node in the scene tree. However, it is impossible to point Visibility Parent towards a child node, as this creates a dependency cycle which is not supported. You will get an error message in the Output panel if a dependency cycle occurs.

Given the following scene tree (where all nodes inherit from GeometryInstance3D):

  1. ┖╴BatchOfHouses
  2. ┠╴House1
  3. ┠╴House2
  4. ┠╴House3
  5. ┖╴House4

In this example, BatchOfHouses is a large mesh designed to represent all child nodes when viewed at a distance. House1 to House4 are smaller MeshInstance3Ds representing individual houses. To configure HLOD in this example, we only need to configure two things:

  • Set Visibility Range Begin to a number greater than 0.0 so that BatchOfHouses only appears when far away enough from the camera. Below this distance, we want House1 to House4 to be displayed instead.

  • On House1 to House4, assign the Visibility Parent property to BatchOfHouses.

This makes it easier to perform further adjustments, as you don’t need to adjust the Visibility Range Begin of BatchOfHouses and Visibility Range End of House1 to House4.

Fade mode is automatically handled by the Visibility Parent property, so that the child nodes only become hidden once the parent node is fully faded out. This is done to minimize visible pop-in. Depending on your HLOD setup, you may want to try both the Self and Dependencies fade modes.

备注

Nodes hidden via the Visible property are essentially removed from the visibility dependency tree, so dependent instances will not take the hidden node or its ancestors into account.

In practice, this means that if the target of the Visibility Parent node is hidden by setting its Visible property to false, the node will not be hidden according to the Visibility Range Begin value specified in the visibility parent.

配置建议

在距离较远时使用更简单的材质以提高性能

想要进一步提高性能的话,一种方法是对远处的 LOD 网格使用更简单的材质。虽然使用 LOD 网格会减少需要渲染的顶点数量,但材质的每像素着色负载保持不变。然而,在复杂的 3D 场景中,每像素着色负载通常是 GPU 的瓶颈。减少 GPU 着色负载的其中一种方法,就是在不会产生太大视觉差异时使用更简单的材质。

这样做时应仔细衡量性能增益,因为增加场景中 独特 材质的数量本身就会产生性能成本。尽管如此,对远处的 LOD 网格使用更简单的材质仍然可以带来净性能增益,因为这样做所需的每像素计算更少。

例如,在远处的 LOD 网格使用的材质上,可以禁用性能成本昂贵的材质功能,如:

  • 法线贴图(尤其是在移动平台上)

  • Rim(边缘)

  • Clearcoat(清漆)

  • Anisotropy(各向异性)

  • 高度

  • Subsurface Scattering(次表面散射)

  • 背光照明

  • Refraction(折射)

  • 邻近淡出

为 LOD 过渡使用抖动

Godot 目前仅支持可见范围内基于alpha值的淡入淡出,但你可以以为不同 LOD 等级使用不同的材质来使用颜色抖动。

在进行LOD过渡时,相比使用 Alpha 混合,颜色抖动有两个优点:

  • 抖动透明的渲染速度比 Alpha 混合更快,性能更高。

  • 在LOD转换期间不会由于 透明度排序问题 而发生视觉故障。

颜色抖动的缺点是LOD淡入淡出过渡时会出现噪点。但在使用较大的视口分辨率或者启用时间抗锯齿(TAA)时可能不会很明显。

另外,由于 BaseMaterial3D 的距离淡入淡出只支持近距离淡出 或者 远距离淡入淡出,该设置最好只使用两个LOD作为设定的一部分。

  • 确保两个 MeshInstance3D 上的 Begin MarginEnd Margin 属性都设置为 “0.0”,因为此处不需要延迟或者alpha淡入淡出。

  • 在两个 MeshInstance3D 节点上,在减少 Begin所需的淡入淡出过渡距离的同时,增加 End 相同的距离是想要看见抖动过渡所必需的。

  • 打开近距离显示的 MeshInstance3D 的材质编辑面板,将 距离淡入淡出(Distance fade) ** 模式设置为 **物体抖动。将 Min Distance 属性设置为与可见范围 End 相同的值,将 最大距离 设置为相同的值 减去 淡入淡出过渡距离。

  • 在远距离显示的 MeshInstance3D 的属性面板里编辑材质,将 距离淡入淡出(Distance fade) ** 模式设置为 **物体抖动。将 Min Distance 属性设置为与可见范围 Begin 相同的值,将 Max Distance 设置为相同的值 加上 淡入淡出过渡距离。

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.