Drawing vertices with different materials
Hello,
I'm working on the scene management and rendering loop of my little DirectX10 engine and I've noticed a little problem. I need to draw a group of vertices with an effect, a group of vertices with another effect and so on, but I don't know how I could do this in a rendering loop with the IaSetVertexBuffers function and the Draw or DrawIndexed one. All the graphics engines usually load the vertices and indices before the rendering loop to not slow down the rendering, but how could I do this with these two functions?
I tried to do something like:
(before the render loop):
for every geometry
load the vertices with IaSetVertexBuffers
(in the render loop):
directx device -> Draw()
...but obviously it renders every mesh with the same material.
How could I solve this issue?
Thank you in advance.
Normaly you sets the vertex buffer of a mesh, then you render all materials of it for all instances of it, using the index buffer to mask out the faces with the material.
Pseudo code:
If you have alpha blended materials, then you need to sort them: first render all non-alphablended materials (using the code above), then sort the objects back-to-front and render each objects alpha materials of its own (you can sort them too, if there are objects with self-alphablended-parts).
You can use GPU instancing here, if you want to render multiple objects with the same mesh.
Pseudo code:
for all visible meshes setVertexBuffer(current mesh vertex buffer); for all materials in current mesh setMaterial(current material); setIndexBuffer(current mesh index buffer for current material); for all visible objects with current mesh setWorldMatrix(current objects world matrix); renderIndexed(); endfor endforendfor
If you have alpha blended materials, then you need to sort them: first render all non-alphablended materials (using the code above), then sort the objects back-to-front and render each objects alpha materials of its own (you can sort them too, if there are objects with self-alphablended-parts).
You can use GPU instancing here, if you want to render multiple objects with the same mesh.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement