Download

How to configure Foliage clusters ?

With RenderDoc and PIX I noticed how the foliage in unreal is rendered in clusters with a couple of instances. There’s 2 issues with this :

  1. Consecutive draw calls using the same vertex buffer which could’ve been merged into the same draw call. I know it uses an instance buffer, but if the entire buffer would’ve been bound all data could be fetched with SV_InstanceID anyway.
  2. The instances are sort of in view, but many times quite a number of them, ranging from 10% up to 50% of the instances are not in view. This basically tells me that the culling is not per object. Looking in the source it has a sort of octree spatialization but I can’t figure out where to change its smallest unit so that objects outside the frustum are never rendered.

I’ve since discovered some details : Draw calls happen on a per cluster basis, so if you’ve got 3 clusters visible, you get 3 draw calls, regardless of the number of instances it contains. It’s sort of like DrawInstances(10-20), DrawInstances(50-75), DrawInstances(81-82). That’s just how the code is written.
For objects out of view, well the culling is per cluster and I think it’s a bit badly written because even when looking down where only 1 cluster should be “visible” I get hundreds of drawcalls. I still don’t know how to configure the granularity of a cluster but I found there’s at least 2 variables related to this (don’t recall exact names) : foliage.splitfactor, foliage.MinVertices