How to prevent frustum culling when using a vertex shader?

Here’s the setup:

  • Unity 2019.3.6f1
  • I’m using GPU instancing to draw many things.
  • Each thing has it’s own size (not scale), but uses the same base mesh
  • Vertex shader slices the mesh to correct size (similar to a 2d 9-slice sprite but in 3d, so 27-slice)

This all works great - very few draw calls, very low memory usage (no per-instance mesh), etc.

Except for two issues:

  1. Frustum culling seems to go off the base mesh or maybe mesh bounds.
  2. Ditto for editor hit testing.

Not unexpected since I didn’t think it would run my vertex shader, but how do I work around it?

My first though was to set bounds on the Renderer - nope, it’s read only.

Setting it on the mesh doesn’t help because the size is per-instance and many instances use the same mesh.


Thanks for the answer @Bunny83. That’s what I suspected, but was hoping there was something I missed.

It’s unfortunate that furstum culling is so inflexable…if anyone from unity is listening, please support per-instance / renderer culling bounds.

Well in your specific case your only solution would be to simply prevent frustum culling by setting a very large Bounds for your mesh. Keep in mind that the Mesh.bounds is defined in local space. Since you do some sort of 26 slice you probably have one corner fixed?! and you are moving the opposite corner depending on your size. If that’s the case you could could just set the mesh bounds to a similar size but just increase your variable ends up to your expected max size. Of course this would almost in all cases disable frustum culling. However if one corner is fixed (in local space) you could still benefit from frustum culling in some cases. If your mesh can grow in any direction you would need to set the bounds to a large value in all directions. I’m not sure if you can use infinity for the bounds size / extent in order to get an infinitely large AABB so it will always overlap is the view frustum.