Engine and materials question

Started by
0 comments, last by jollyjeffers 15 years, 9 months ago
Hello there, I'd like to ask the more knowledgeable among you which would be the best approach in the situation that I'm facing. My "mesh" class right now has an array of a generic "Material" type (it's in C#). Upon loading the .X file, it creates enough positions in the array for each subset in the mesh that it encounters. The actual pairing between subset and related material resources is done by reading an xml file which pairs the mesh and textures. The effect to use, right now, it's hard coded and depends on the class of the entity. Right now I only have one effect per mesh.. and actually the material array just only had one slot. So, from the way that you designed your engine, it is a common situation to have multiple effects per mesh? If so how would you organize your mesh class? I'm thinking for example about appying Specular Normal / Parallax Mapping and then a Shadow Map shader for example (although the latter would be applied to all the objects in the scene and just to a single one). But more complex meshes could have different effects. For example in a spaceship case there would be a shader for the surface material and one for the engine exhaust... am I right?
--Avengers UTD Chronicles - My game development blog
Advertisement
Myself I've always favoured a central respository of resources for situations like this. Having each mesh actually own its own resources strikes me as inefficient and not conducive towards cached/optimal state changes.

Instead, having some sort of reference counted repository to store the actual effect instance and then have each mesh hold just the handle/pointer/reference.

This way you can start to hide this problem of multiple effects per mesh - this central repository knows which effect a given technique comes from and can handle any awkward mappings that become necessary. Your mesh code can then remain clean and concise, which is just A Good Thing™ [smile]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement