Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

可見範圍(HLOD)

與 doc_mesh_lod 和 doc_occlusion_culling 一起,可見範圍是提高大型複雜 3D 場景效能的另一個工具。

在本指南中,我們將學到:

  • 可見範圍可以做什麼以及它們在哪些場景中有用。

  • 如何在 Godot 中設定可見性範圍(手動 LOD)。

  • 如何調整可見範圍以獲得最佳性能和品質。

也參考

如果您只需要網格在距離上變得不那麼詳細,但沒有手動建立 LOD 網格,請考慮依賴自動 doc_mesh_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 屬性來配置較小的滯後裕度。當相機在 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”。

  • 將相機移開並返回物體。注意當相機移開時,物件如何從球體過渡到盒子。

訊號與屬性

在繼承自 GeometryInstance3D 的任何節點的屬性面板中,您可以在 GeometryInstance3D 的 Visibility Range 部分中調整下列屬性:

  • 開始: 當相機比該值(以 3D 單位)更接近實例的*原點*時,實例將被隱藏。

  • 開始邊距: 用於特寫過渡的滯後或 Alpha 淡入淡出過渡距離(以 3D 單位表示)。此屬性的行為取決於 淡入淡出模式

  • 結束: 當相機距離實例的*原點*遠超過此值(以 3D 單位表示)時,實例將被隱藏。

  • 結束邊距: 用於遠距離過渡的滯後或 alpha 淡入淡出過渡距離(以 3D 單位表示)。此屬性的行為取決於 淡入淡出模式

  • 淡入淡出模式: 控制如何執行 LOD 等級之間的過渡。詳情請參閱下文。

匯出模式

備註

僅當**可見性範圍 > 開始邊距**或**可見性範圍 > 結束邊距**大於「0.0」時,所選的淡入淡出模式才會產生可見影響。

在屬性面板的 Visibility Range 部分中,有 3 種淡入淡出模式可供選擇:

  • 停用: 使用遲滯在 LOD 等級之間即時切換。這可以防止當玩家在 LOD 過渡點向前和向後移動時 LOD 等級快速來回切換的情況。滯後距離由 可見性範圍 > 開始邊距可見性範圍 > 結束邊距 決定。此模式提供最佳效能,因為它不會強制渲染在淡入淡出過渡期間變得透明。

  • Self: Uses alpha blending to smoothly fade between LOD levels. The node will fade-out itself 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.

  • 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):

┖╴BatchOfHouses
    ┠╴House1
    ┠╴House2
    ┠╴House3
    ┖╴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 網格使用的材質上,您可以停用昂貴的材質功能,例如:

  • 法線貼圖(尤其是在行動平台上)

  • 邊緣

  • 清漆

  • 各向異性

  • 光照

  • 次表面散射

  • 背部照明

  • 折射

  • 鄰近淡出

使用 Weblate 來進行翻譯

Godot 目前僅支援可見範圍內基於 alpha 的淡入淡出。不過,您可以透過針對不同的 LOD 等級使用多種不同的材質來使用抖動。

對於 LOD 過渡,使用抖動比 Alpha 混合有兩個優點:

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

  • LOD 轉換期間不會因透明度排序問題 <doc_3d_rendering_limitations_transparency_sorting>` 而出現視覺故障。

抖動的缺點是在 LOD 淡入淡出過渡期間會出現「吵雜」圖案。在較高的視口解析度或啟用時間抗鋸齒時,這可能不會那麼明顯。

此外,由於 BaseMaterial3D 中的距離淡入淡出僅支援近距離淡出*或*遠距離淡入淡出,因此此設定最好只使用兩個 LOD 作為設定的一部分。

  • 確保兩個 MeshInstance3D 節點上的 Begin MarginEnd Margin 設定為“0.0”,因為此處不需要延遲或 alpha 淡入淡出。

  • 在兩個 MeshInstance3D 節點上,減少 **開始**所需的淡入淡出過渡距離,並*增加* **結束**相同的距離。這是抖動過渡實際可見所必需的。

  • 在近距離顯示的 MeshInstance3D 上,在屬性面板中編輯其材質。將其**距離淡入淡出**模式設定為**物件抖動**。將 Min Distance 設定為與可見範圍 End 相同的值。將**最大距離**設定為相同的值*減去*淡入淡出過渡距離。

  • 在遠處顯示的 MeshInstance3D 上,在屬性面板中編輯其材質。將其**距離淡入淡出**模式設定為**物件抖動**。將 Min Distance 設定為與可見範圍 Begin 相同的值。將**最大距離**設定為相同的值*加上*淡入淡出過渡距離。