Using a clipping plane to hide grass under a block?

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

Is there a way to hide objects under another object? I have a multimesh with a shader creating moving grass, but it pokes through my farm plot blocks. You can see the effect here

I found some code to cull things behind a plane from this youtube video

Someone suggested using a viewport texture to draw shapes where the grass would get drawn too, but I wasn’t able to figure out how to do it. This plane culling thing seems like the most straight forward if I can get it to work. Right now, it’s either applied to the grass as a whole, or the plane depending on which object I put the shader code in. I’m thinking it needs to go in the grass shader, and pass in each object as it’s layed down. But I don’t know how to pass in multiple block positions as they are layed down, much less how to make it dependent on them.

shader_type spatial;

uniform vec4 portal_plane = vec4(1.0, 0.5, 0.0, 0.0);

bool portal_culls(vec3 vertex, mat4 cam) {
vec3 pos = (cam * vec4(vertex, 1.0)).xyz;
return !any(isnan(portal_plane))
&& portal_plane.x * pos.x
+ portal_plane.y * pos.y
+ portal_plane.z * pos.z
+ portal_plane.w < 0.0;
}

void fragment() {
if (portal_culls(VERTEX, CAMERA_MATRIX)) {
discard;
}
ALBEDO = vec3(1.0, 0.0, 0.0);
}