Sign in to follow this  

Drawing vertices with different materials

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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:

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
endfor
endfor


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.

Share this post


Link to post
Share on other sites

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this