Jump to content
Posted 04 February 2013 - 02:43 AM
Posted 04 February 2013 - 03:37 AM
What the exporter does is give you a number of submeshes. Now a single object (or mesh) is build up from a number of submeshes.
Think of it like a human body, both the head and the arms are part of it, yet completely different.
Change your code layout (vertex and index buffer for each object) to a vertex buffer and an array of submeshes.
Each submesh contains an index buffer and a material pointer.
During the rendering, simply loop over the submesh array and bind the material and draw the submesh.
If you want to know witch triangle you are processing, you could use PrimitiveID (http://msdn.microsoft.com/en-us/library/windows/desktop/bb205118(v=vs.85).aspx ) and pass it to your pixel shader.
Posted 04 February 2013 - 04:01 AM
It's far more efficient to order on material in the render call then it is to do this in the pixel shader. For meshes in an object that share the material you only upload that material once and then draw them, with the pixel shader approach you need to upload all of the materials for all draw calls of that object. Sometimes a submesh can also need a different shader to be rendered with, if you do that decision in the pixelshader you need to make that choice for each pixel which isn't great for performance.
Posted 04 February 2013 - 05:01 AM
Posted 04 February 2013 - 09:08 AM
Im using directx 10. Do i just loop and call ID3D10Device::DrawIndexed() for each index array? Is this efficient or is there a better way?
yes, that will work. If you sort the submeshes based on material, this will be as efficient as it gets.
Posted 06 February 2013 - 08:19 AM
thanks, works great.