How do I disable an object when it's hidden behind the terrain

Godot Version

4.5

Question

Hey there! I am trying to figure out how to completely disable a scene object (like a tree) when its hidden behind the terrain but its still technically in the 3D cameras view. My tree has a GD script that checks the distance from the player and replaces the mesh with a 2D imposter when far away, as well as a basic wind shader.
How do i completely disable all of it so it displays no mesh and runs no code/shader when its hidden behind a hill or a mountain etc?

In case it is relevant, I am using the addon Terrain3D for my landscape

Here is an example of what im thinking:

^^

Godot handles occlusion culling, but for big open scenes like this it’s probably not worth it. If your script is only to replace with an imposter- keep in mind Godot also handles LOD generation and replacement, you could use visibility ranges to show a very specific LOD or group of objects LOD, such as replacing a forest of individual trees with one backdrop mesh. You do not need to script this.

Godot has an automatic LOD system:

And a manual LOD system:

So you don’t need any code to swap the mesh for an impostor.

If you still want to add occlusion culling here’s the documentation page for it:

And how to setup Terrain3D to use it:

aah thanks so much for the advice! I removed the imposter script and stuck to occlusion culling and LODs. Apoligies for the late reply, life suttenly took me by storm ^^

@gertkeno If you want, I would love to learn some pointers on how to get multiple trees to share one backdrop mesh!

Sure, I’m actually surprised there isn’t better info/visual examples of using this visibility_parent property.

The close-up trees have their visibility parent set to the next HLOD, in this silly example it’s a Sprite3D for a bill-board tree.

The billboard has at least it’s Visibility Range Begin set to a higher than zero value, moving the camera far enough back only shows the billboard. Setting the margin values and Fade Mode can smoothly transition from the HLODs, but I don’t think a Sprite3D likes this fade in-out much.

Yoo that is so cool! Yeah I wasn’t able to find much on it either, so I really appreciate the tips. You are a damn hero!
I got it implemented and it has already upped the performance