primitivebatch and world matrix

May 15, 2011 at 2:53 AM

Hi, I m back with another touchy question.

 I m passing a world matrix to each of my draw calls, because my vertice coordinates are relative to the current chunk I m drawing, like this :


How could i still use the batching ?   

My solution would be to rewrite my IVertexType to use yet another vector3 for the origin and calculate the worldmatrix inside the effect, so getting rid of the effect parameter.

Do you see another way ?  

May 17, 2011 at 7:38 AM

If you're using the PrimitiveBatch class to render a chunk's blocks, I'd recommend against that. Reason being that the PrimitiveBatch will send each and every vertex over the bus, whereas most chunks in this type of engine will stay the same over long periods of time and would be ideally suited for static vertex buffers.

I have done some benchmarks with my PrimitiveBatch which are pretty telling: DynamicVertexBuffer versus DrawUserPrimitives, Round 2.

I'd probably store the vertices with their final, absolute world coordinates in the vertex buffers. If you generated each chunk with coordinates around {0,0,0} and moved it into place via your world matrix, I think the chunk borders wouldn't match exactly (different rounding errors) and single-pixel gaps might occur, forcing you to create skirts around the chunks.