Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

OccluderInstance3D

繼承: VisualInstance3D < Node3D < Node < Object

為 3D 節點提供遮擋剔除,可以提高封閉區域的性能。

說明

Occlusion culling can improve rendering performance in closed/semi-open areas by hiding geometry that is occluded by other objects.

The occlusion culling system is mostly static. OccluderInstance3Ds can be moved or hidden at run-time, but doing so will trigger a background recomputation that can take several frames. It is recommended to only move OccluderInstance3Ds sporadically (e.g. for procedural generation purposes), rather than doing so every frame.

The occlusion culling system works by rendering the occluders on the CPU in parallel using Embree, drawing the result to a low-resolution buffer then using this to cull 3D nodes individually. In the 3D editor, you can preview the occlusion culling buffer by choosing Perspective > Display Advanced... > Occlusion Culling Buffer in the top-left corner of the 3D viewport. The occlusion culling buffer quality can be adjusted in the Project Settings.

Baking: Select an OccluderInstance3D node, then use the Bake Occluders button at the top of the 3D editor. Only opaque materials will be taken into account; transparent materials (alpha-blended or alpha-tested) will be ignored by the occluder generation.

Note: Occlusion culling is only effective if ProjectSettings.rendering/occlusion_culling/use_occlusion_culling is true. Enabling occlusion culling has a cost on the CPU. Only enable occlusion culling if you actually plan to use it. Large open scenes with few or no objects blocking the view will generally not benefit much from occlusion culling. Large open scenes generally benefit more from mesh LOD and visibility ranges (GeometryInstance3D.visibility_range_begin and GeometryInstance3D.visibility_range_end) compared to occlusion culling.

Note: Due to memory constraints, occlusion culling is not supported by default in Web export templates. It can be enabled by compiling custom Web export templates with module_raycast_enabled=yes.

教學

屬性

int

bake_mask

4294967295

float

bake_simplification_distance

0.1

Occluder3D

occluder

方法

bool

get_bake_mask_value(layer_number: int) const

void

set_bake_mask_value(layer_number: int, value: bool)


屬性說明

int bake_mask = 4294967295 🔗

  • void set_bake_mask(value: int)

  • int get_bake_mask()

烘焙遮擋物時要考慮的可視層。只有其 VisualInstance3D.layers 與該 bake_mask 配對的 MeshInstance3D,才會被包含在生成的遮擋物網格中。預設情況下,所有具有不透明材質的對象,都將被考慮用於遮擋物烘焙。

為了提高性能並避免偽影,建議將動態物件、小物件和固定裝置從烘焙過程中排除,方法是將它們移動到一個單獨的可視層,並在 bake_mask 中排除該層。


float bake_simplification_distance = 0.1 🔗

  • void set_bake_simplification_distance(value: float)

  • float get_bake_simplification_distance()

用於簡化生成的遮擋物多邊形的簡化距離(單位為 3D 單位)。更高的值會導致遮擋物網格的細節更少,這會提高性能但會降低剔除精度。

遮擋物幾何體是在 CPU 上算繪的,因此保持其幾何體盡可能簡單很重要。由於緩衝區以低解析度算繪,因此細節較少的遮擋網格通常仍能正常工作。預設值相當激進,因此如果遇到誤報(即使相機可見的物件也被遮擋),可能必須降低該屬性。0.01 的值將保守地起作用,並將保持幾何體感知在遮擋剔除緩衝區中不受影響。根據場景的不同,與完全禁用簡化相比,0.01 的值仍能顯著簡化網格。

將該屬性設定為 0.0 將會完全禁用簡化,但仍會合並位置完全相同的頂點。網格也將被重新索引以減少頂點和索引的數量。

注意:這在底層使用了 meshoptimizer 庫,類似於 LOD 生成。


Occluder3D occluder 🔗

這個 OccluderInstance3D 的遮擋器資源。要生成遮擋器資源,你可以先選中 OccluderInstance3D 節點,然後使用編輯器頂部的烘焙遮擋器按鈕。

你還可以通過在“屬性檢視器”中為 occluder 屬性新增新的 PolygonOccluder3D 資源來繪製自己的 2D 遮擋器多邊形。

另外,你也可以選擇要使用的基本遮擋器:QuadOccluder3DBoxOccluder3DSphereOccluder3D


方法說明

bool get_bake_mask_value(layer_number: int) const 🔗

返回是否啟用了 bake_mask 的指定層,該層由給定的一個介於 1 和 32 之間的 layer_number 指定。


void set_bake_mask_value(layer_number: int, value: bool) 🔗

基於 value,啟用或禁用 bake_mask 中的指定層,該層由給定的一個介於 1 和 32 之間的 layer_number 指定。