Can you static batch unity grass? Or override it's billboard shader to do so? [URP]

Hey there. The question here is exactly as it sounds. Apart from occlusion culling and frustum culling, can unity grass be static batched? Is there any way to override it's shader to do so if not?

I'm using unity 2019.4.26 LTS and URP of that specific version.

Somewhat, yes. Terrain grass isn’t rendered in the same manner as Renderers are, so it doesn’t pass through the same render loop that performs static/dynamic batching. Instead, it’s kind of black box and I assume the rendering is done alongside of the actual terrain, and OC is also processed there.

So “static batching” is done through detail patches by the terrain, where grass/details are divided into a grid, then merged together to create one mesh for each cell. Internally, the terrain creates a texture atlas for all details, and uses 1 material. Which is similar to static batching. For each cell, a draw call will be issued.

You can configured the size of these cells/patches in the terrain’s settings:
7145519--854945--upload_2021-5-16_14-15-7.png

If the terrain is 512x512, and the patch resolution is 32, a total of 1024 patches will be created. Smaller patches mean more draw calls, but more accurate culling. Larger patches, fewer draw calls, but culling will be less accurate (potentially uploading vertices to the CPU which won’t end up being visible).

A patch is also limited to 65k vertices, so if you have a lot of grass, or detailed meshes, the console will spew warnings that the patch size needs to be reduced. At which point you’ll also noticed strips of grass will go missing, since the patch mesh generation cuts off after 65k vertices.

You can change the patch resolution without loosing any details already placed, unlike the Detail Resolution value. It’s a bit of balancing act, you can check the number of draw calls issued for grass/detail rendering in the Frame Debugger:

1 Like

Ah that is about what I wanted to know! Thank you!