DrawProcedural() in OnPostRender() drawing over transparent objects

I am using DrawProcedural() in the OnPostRender() function of a camera. This works well for opaque objects, as the depth test is accurate. Objects further away are occluded as expected.

However, this does not work for game objects with transparent textures. DrawProcedural() is drawing on top of them, regardless of distance. I tried using the OnRenderObject() function of the camera, but that did not work.

Is there a way to make a custom draw call work with transparent objects correctly?

Figured it out! At least for particle systems.

For DrawProcedural(), I moved drawing to the OnPostRender() function of the camera. This takes care of opaque objects. Then, I force render particle systems. ParticleSystemRenderer has an undocumented Render(Material material) function. Just pass it the shared material of the particle system and it should draw. Make sure to turn off the standard renderer on the particle system in the inspector, so it does not draw twice.

That works. Transparent particle systems will render on top of opaque objects drawn with DrawProcedural(). Other renderers might have an undocumented Render() function that can be used. I haven’t investigated this too much yet. Just make sure the transparent objects are rendered after opaque objects in OnPostRender().