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. But I have no idea how to make it clip the grass only on the spots where I place obejcts.
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);
}