DrawInstanced / ComputeBuffer / Bounds / Culling

I have an object made from sections that are drawn using DrawInstanced, with identical matrices. These instances are offset in a vertex shader by positions stored in a compute buffer. The positions are calculated by a compute shader. The objects get culled from the frustum if the root transform of the object goes out of view, even if objects transformed into the frustum by the vertex shader are still in view. I do not wish to transfer the position data back to the CPU in order to set bounds within the Unity engine; is there a way to do it GPU side?

if you know the potential bounds area for all of the offset instances you could do this with instancedIndirect. Then you can provide a joint bound for the instances and read the actual instanced from a computebuffer.

Nice, I’ll look it up, thanks!

You just need a setup function in the shader where you assign the object2world and world2object matrix with data from the structuredbuffer

1 Like