DrawProcedural examples for deferred shading?

I am trying to render an enormous amount of movable meshes, and I figured the most optimized way of doing this would be to:

  • Process all the mesh data and send it to a shader via StructuredBuffers
  • Do a Graphics.DrawProcedural of all vertices using that material/shader
  • On update, simply update the StructuredBuffer containing the transform matrixes of every individual object, and let the shader handle positioning all the vertices to match the movement.

Right now, most of it is working decently well, and I can render a massive fully-destructible city in only 6 draw calls:

This method makes the difference between 1 fps and 140 fps for 1000 buildings each containing 100 fragments.

However… after 2 days I have not been able to figure out how to do a decently lit/shaded deferred shader that works with DrawProcedural.

I do have a custom deferred shader that works well when using the usual vertex shader input structure, but as soon as I try to convert this to StructuredBuffers of positions, normals, uvs, etc…, all lighting is lost. Is there any working example of this?

Is your procedural results of the meshes the same amount of triangles as the original house or are you producing more?

It is the same amount of triangles as the original meshes, just way less draw calls

I was thinking you could “cheat”

do this rendering with DrawMeshInstancedIndirect. Pass a “dummy mesh” with the same vertex count and then replace the vertex position, normal etc in the vertex shader.

You still get all the instance info from the compute buffer and can read your procedural mesh data from another structuredbuffer.

 v2f vertex_shader (uint id : SV_VertexID, uint inst : SV_InstanceID)
{
      vertex_position =  float4(points[id].vertex,1.0f);
}

where points is a structured buffer with all your changed meshes.