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.