Graphics.DrawMeshInstancedIndirect and frustum culling

Hi, have been testing some forest rendering with DrawMeshInstancedIndirect with good result, but need to do frustum culling to make it perform as good as possible with shadows.

I take it you could use a compute shader to calculate the visible objects. Not that familiar with how to go about that though. Anyone have an example of working with result buffers from compute shaders or if you have done frustum culling that would be really appreciated.

Cheers

Any update on this? Been scouring the forums for an answer looking for examples and have come up with nothing. I don’t have the slightest on how to frustum cull in a compute shader. I know how to pass positions just fine but fail to see how the hell I get the view bounds in a compute form. It’s probably simple and I’m overlooking something. Any help at all would be appreciated.

I would be very happy as well if somebody could give some insights for this. (Bump)

Here is what I came up with. Doesn’t do LOD selection currently as the file says. Needs more work to make it perform better, rename the FrustumCullingAndLod.cs to .compute. Also check GitHub - ellioman/Indirect-Rendering-With-Compute-Shaders: An example of drawing numerous instances using Unity3D, compute shaders and Graphics.DrawMeshInstancedIndirect with Frustum & Occlusion culling and LOD'ing. which has more features.

3348270–261779–GPURenderManager.cs (6.1 KB)
3348270–261780–FrustumCullingAndLOD.cs (1.2 KB)

1 Like

@stationTime : thanks for the details.

I implemented my own version of this over the weekend and I wish I had these lines of code to kickstart me before that :). I solved this in a similar way to the Github repro you mentioned - the main difference with your code being the camera frustum planes are also being calculated in the GPU. I believe this could increase frustum calculation performance, but the downside is that you have to send a bunch of extra parameters to the GPU per instance (i.e. bounds extents, bounds center, camera pos, camera mvp, etc.).

Did you test which way is better in terms of general performance?

Hi LouskRad, sorry I didn’t reply sooner, just got back from the holidays. No I haven’t done more performance tests but would be interested to hear if you do any tests. The sending of paramaters to the GPU is pretty expensive so not sure what would be faster. Currently not working on this but have been keeping an eye on the Github repo,