Sign in to follow this  
NightcrawlerEX

Per face materials

Recommended Posts

NightcrawlerEX    108
Hi all,

I have been looking through a directx x file exporter and have realised that it exports materials in a way different than i am used to. I am used to assigning a 1 material per object and when it comes to the shader, just passing in the material to be used.

The way this exporter does it is by first outputting each material to be used, then outputting a set of per face indices to the relevant materials.

I was wondering if anyone knew how to go about this, or possibly a link to some texts regarding this?

Also is there a way to tell which face you are working on during the pixel shader? This would be good for many reasons but i dont think this is likely

[EDIT] so far my train of though is sorting all the faces per material into seperate objects

Share this post


Link to post
Share on other sites
Yourself    1961

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.

Share this post


Link to post
Share on other sites
NightCreature83    5002

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.

Share this post


Link to post
Share on other sites
NightcrawlerEX    108
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?

Also the primative id semantic seems cool. Seems usefull for a number of effects

Share this post


Link to post
Share on other sites
Yourself    1961

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.

Share this post


Link to post
Share on other sites

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