Create occluder instances on RenderingServer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ninfur

Does anyone know how to properly setup occluder instances on the RenderingServer? The interface seems pretty barren at the moment, but I’ve been trying to set it up similar to a normal visual instance, with no luck.

So far I have tried something like this:

RenderingServer.viewport_set_use_occlusion_culling(get_viewport(), true)

var occluder_instance: RID = RenderingServer.occluder_create()
RenderingServer.instance_set_scenario(occluder_instance, scenario)
#RenderingServer.instance_set_transform(occluder_instance, transform)

var vertices: PackedVector3Array = PackedVector3Array()
vertices.append(Vector3(0, 0, 0))
vertices.append(Vector3(10, 0, 0))
vertices.append(Vector3(10, 10, 0))

var indices: PackedInt32Array = PackedInt32Array()

RenderingServer.occluder_set_mesh(occluder_instance, vertices, indices)
  • Occlusion culling is also enabled in project settings, which should make the first line unnecessary.
  • I’m unsure if the instance_set_* functions work on occluder instances, but I’m assuming the scenario must be set somehow.
  • A reference to occluder_instance is being kept to ensure it doesn’t get freed.
  • The occluder is not visible using get_viewport().debug_draw = Viewport.DEBUG_DRAW_OCCLUDERS
:bust_in_silhouette: Reply From: Ninfur

Figured out why it didn’t work. The occluder instance must be added to a visual instance, which then has the scenario and transform.

So all that was missing was putting this at the end:

var instance = RenderingServer.instance_create2(occluder_instance, scenario)