Hi!
A common trick to render many billboards (if you don’t have geometry shaders available) is to send four vertices with identical position to the vertex shader and to expand the quad in view space, by offsetting each of the vertices using their texture coordinates. (The texture coordinate identifies in which corner to move the vertex.) This way, you don't need to calculate rotation matrices on the CPU (or the GPU). Thus you don't have to set additional effect constants and therefore you don't need to call Apply for every single billboard, but only if the texture changes. (So, batching, i.e. sorting per material, would be a good idea.)
Even better, you can render all billboards that share the same texture with a single draw call, by throwing all billboards into a single vertex buffer.
See here, for an example (Section 1.2).
Tsus,
I see now ; I would have an "artifically" large VB and alter the vertex position in the shader. Even though they are all the same mesh, I would do the location transform when loading up the VB rather than using a matrix to transform it at render time. Is the resultant call so quick that I dont need to bother about culling ? Or would you subdivide the IBs into sets based on your world graph so that you dont end up rendering invisible billboards ?
Thanks,
Using one large VB in a single draw call is definitely faster than drawing each quad individually. Though, sooner or later you will run into scalability problems, too. Thus, at some point culling is advisable. You could try it out and see, whether you can live without culling. (No point in optimizing things, if you don’t know how hard they hit the performance, right?) The actual performance depends on the size of the quads on the screen (and their overlap, i.e., increase in fillrate), the complexity of the shaders, the blending operations you apply, etc.
For the culling, two options come to my mind:
1. As you said, you can update your buffers (either having a static vertex buffer and a dynamic index buffer, or directly a dynamic vertex buffer) to draw only quads that are visible. The problem is you need dynamic resources even for objects that are actually static.
2. You can divide your scene into small static blocks (aligned in a grid or a grid hierarchy) and cull them conservatively. This means, you would render sometimes a few billboards that are not on the screen, since you only cull entire blocks. On the plus side, all static objects would reside in static buffers.
In the second approach you would need one draw call per block (for the static objects). Depending on your scene data structure, you may already have a space-partition of your scene. If your scene is already organized in a grid, you could cook up the vertex buffers for each grid cell individually.
Essentially, the grid size is a trade-off of the number of objects you can cull and the size of the batches. (The smaller the grid cells, the better you can cull. The larger the grid cells, the faster are the draw calls.) Billboards are usually pretty light-weight so it is no catastrophe if you miss a few in your culling.
Best regards!