Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering Multiple Materials on the same Mesh?

Started by golgoth13 Jan 8, 2009 at 2:08 PM 5 replies 5.8k views
Original Post
golgoth13
golgoth13
Hi there, I want to introduce what we know as Clusters in some 3D packages in my 3D engine. The main purpose here is to assign multiple materials on the same mesh. My question is: how do I organize the data and how do I send it to OpenGL?Create a polygon list for each material? Draw the entire mesh then draw over with the polygon list and his associate material? Or maybe, instead of creating a polygon list for each material is there a way to tell OpenGL: draw this list of faces but omit those ones? Some kind of a mask, an array matching a face list, of 0 and -1 for instance… where -1 mean not to draw this face. I m curious… any constructive inputs would be appreciated!
emeyex
emeyex
If the vertex format/layout is the same across all vertices for all the materials, then you can use one vertex buffer for all the verts, but separate index buffers (one for each material). If the vertex layouts are different (i.e., one material requires vertex color, another requires tangents, etc.), then you'll want separate vertex buffers as well (so you'd have 1 VB and 1 IB per material).

So you'll end up slicing and dicing the mesh in some way shape or form; when you draw, you draw only the polygons affected by the current material.

I use DirectX these days but the ideas are pretty much identical, use VBOs and whatever the equivalent of index buffers are.
Lord_Evil
Lord_Evil
With a deferrred renderer that would be pretty easy, IMHO. You could use a "material texture" on the mesh and thus render each pixel's material id to the g-buffer. This way you wouldn't be limited to one material per polygon and splitting the mesh.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
golgoth13
golgoth13
thx for your inputs guys,

I ve read the thread on deferred rendering:

http://www.gamedev.net/community/forums/topic.asp?topic_id=424468

Maybe I ve missed something but while deferred rendering is compared to a forward rendering, I didn’t understand how the deferred renderer worked, did I missed the definition?
emeyex
emeyex
Deferred rendering is an altogether separate topic, and while a perfectly valid technique under the right circumstances, is probably overkill if you are currently using a forward renderer (which you probably are) and all you want is to add support for multiple materials to your meshes.

Briefly, deferred rendering means you render geometric properties and material info to render targets without performing any lighting (for example, render normals to your render target), then, in later passes, render light volumes projected into screen space, accessing the previous pass's render targets to perform the lighting. If none of this sounds familiar or like something you feel like tackling, I would recommend sticking with my first post.
golgoth13
golgoth13
actually, I have use this technique for cinematic in post production but I had no clue it was already popular for real time... as a matter of fact, I m really interested in this topic, that said, I have no clue how it does make multi materials easier to manage, can you elaborate on this?

Any good references on the deferred rendering would be more than welcome as well. I m definitely going to give this deferred rendering a try.

Thx for the insight.
emeyex
emeyex
Look up these terms on google:

deferred renderer
light-indexed deferred renderer
light pre-pass renderer

Lots of good info there.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.