• Create Account

# VBO and Multi-Material!?

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.

4 replies to this topic

### #1Neosettler  Members   -  Reputation: 150

Like
0Likes
Like

Posted 12 January 2013 - 01:51 PM

Greetings everyone,

I’ve been looking around and found many threads on this topic but none of them seems to tackle my concern specifically. So I’ll try to explain my approach in drawing geometries with multiple materials.

For simplicity sake, let’s focus on only one geometry.

Geometry:
-Meshes Array
-Vertices
-Vertices Attributes
-VBO

Mesh:
-Face Indices
-Material

This concept first appeared ideal for sharing the vertices between meshes but consider a geometry composed of 4 Quads:

---------
| A | B |
----+----
| C | D |
---------

- VBO is aligned ABCD
- Mesh1: Material1: Face Indices AD
- Mesh2: Material2: Face Indices BC

The problem:
Chances are that Mesh2 will be rendered correctly because the Vertices are packed one after the other in the VBO but Mesh1 might have wrong data since the Face Indices AD are not align in the VBO.

The goal:
To share V, VA and VBO between meshes. Avoiding geometry reconstruction and using FI to render whatever part of the geometry, leaving the VA undisturbed from their original structure (presumably imported from an CG package).

Now, could this be done or I’m dreaming a fantasy world?

### #2slicer4ever  GDNet+   -  Reputation: 6297

Like
0Likes
Like

Posted 14 January 2013 - 11:05 AM

it can be done, you could tag each face with an index, and then pass a texture buffer, or array of materials to the shader, and choose the appropiate material.

however, unless your going to be very memory intensive i'd recommend:

A. if the only diffrence in the mesh face's are textures, try to merge the textures(either on-load if you wanna go that far, or more likely pre-process them in some photo editing, and update model uv's to reflect these changes).

B. split the mesh by materials.

I personally employ B at the moment, however the concept of using super textures as of late makes me want to implement A in some form.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #3Neosettler  Members   -  Reputation: 150

Like
0Likes
Like

Posted 15 January 2013 - 03:50 AM

Hi Slicer, thank you for your input
it can be done, you could tag each face with an index, and then pass a texture buffer, or array of materials to the shader, and choose the appropiate material.

I'd be very interested if you could elaborate this concept. I use your B scenario, not only for textures but for all material properties.

My main concern is how to pass the face indices from the new spit meshes to the VBO. As it is for now, the materials seems to be distributed to the right faces but some vertices go to 0,0,0 stretching the whole model or, some vertices are connecting faces that shouldn't be connected. I wonder if I do have to reorder the vertices some how for the meshes to render properly.

### #4slicer4ever  GDNet+   -  Reputation: 6297

Like
1Likes
Like

Posted 15 January 2013 - 04:07 AM

no matter what, your vbo is going to have to duplicate vertices for different materials/faces, so if each vertex is given an id along with position/uv/normal data, then you simply need to pass a struct array of your material's as uniforms to the vertex shader, or alternatively, use a uniform/texture buffer and extract the information in them to use.

however there are some things you should note.  first of all, older graphics cards don't support tons of uniforms, and your gambling if older cards support texture/uniform buffers(which are standard in i believe OGL 3.3, but are extensions before then.) , secondly you'll probably have to combine this with texture arrays in order to support materials with different texture's.  pretty much this would be best suited for more modern graphics card's.

personally i'd make sure you even have to do this first, if your having performance issues, try doing culling techniques to eliminate unseen model's/rooms.

i've never attempted this, so i can't give you any number's/percents on if such a tecnique well actually give you a performance boost, so it's purely speculative from my end.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #5Neosettler  Members   -  Reputation: 150

Like
0Likes
Like

Posted 15 January 2013 - 11:02 AM

no matter what, your vbo is going to have to duplicate vertices for different materials/faces, so if each vertex is given an id along with position/uv/normal data,

Oh, Vertices and Vextex Attributes duplication is the main thing I was trying to avoid but at least I know there is no other solution... really? Anyhow, I'm curious to know how 3D packages like 3dmax/Maya/Softimage recalculate VBOs of the geometry as the material ids/face clusters are being changed... very puzzling to me.

Thank you for your inputs Slicer, very appreciated.

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