Jump to content

  • Log In with Google      Sign In   
  • Create Account


Per face materials


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 NightcrawlerEX   Members   -  Reputation: 108

Like
0Likes
Like

Posted 04 February 2013 - 02:43 AM

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

Sponsor:

#2 Yourself   Crossbones+   -  Reputation: 1047

Like
1Likes
Like

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.



#3 NightCreature83   Crossbones+   -  Reputation: 2674

Like
2Likes
Like

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.


Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#4 NightcrawlerEX   Members   -  Reputation: 108

Like
0Likes
Like

Posted 04 February 2013 - 05:01 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?

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

#5 Yourself   Crossbones+   -  Reputation: 1047

Like
1Likes
Like

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.



#6 NightcrawlerEX   Members   -  Reputation: 108

Like
0Likes
Like

Posted 06 February 2013 - 08:19 AM

thanks, works great.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS