Sign in to follow this  
Endar

Multiple materials per mesh?

Recommended Posts

I'm in the middle of writing two classes, Mesh and Model. A Mesh will consist of geometry, and a Model will have 1 or more meshes. I haven't gotten around to starting the Model class yet, but I'm thinking about a Material class (simply a structure that consists of diffuse, ambient, specular, etc) and I'm wondering if I need to go that far. Also, if I do, should my Mesh have just a single material, or should the material be with the Model and not the Mesh?

Share this post


Link to post
Share on other sites
Depends on your situation I guess. Are you using shaders? Are you using deferred rendering?

I think it would not be bad to separate the Material from Model and Mesh. I would guess you want a material per mesh instead of per model. eg a character with a sword will want different material parameters for the sword as for the skin.

So it depends :) Tell us more about the use?

Share this post


Link to post
Share on other sites
In my game engine I have sparated everything out, that way I can re-use memory if two models use the same material. I don't need to have the same data saved twice. Each "Shape" object can contain one "Mesh", one "Material" and one "Texture". A 3D model will be made up of multiple "Shape" objects.

When I go and render, I send thing down the pipes by material and texture to minimize on swapping parameters in the video card.

Share this post


Link to post
Share on other sites
i would suggest that you make material the "parameters" to a shader exclusive of "texture". Also it is highly likely you need more than one texture per mesh so i would suggest a "sampler params" type of construct that pairs with a material.

this then allows you to sort/optimize using consistent blocks and those blocks are themselves self contained elements.

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