Color / Material for each vertex on a VBO model (and a texture)

Started by fiendfan1, May 20, 2013, 01:55:17

Previous topic - Next topic

fiendfan1

How would you go about allowing each vertex / face on a VBO have its own color, shininess, ect?

Also, is there a better way to use a custom texture for each vertex / face in a VBO's than GL_TEXTUREX?
This page showed a way to do it using immediate mode, but it was a little confusing and I'm not sure how it would translate to VBOs.
http://lwjgl.org/wiki/index.php?title=Multi-Texturing_with_GLSL

fiendfan1

I Just found the function glColorPointer() , so I can do colors.

Still have no idea on shininess.

quew8

The only way to do shininess with the fixed functionality is to render one face at a time, switching the shininess between (it makes no sense to do it per vertex, that's why it's a uniform). If you are using your own shaders however, you could make a custom attribute variable  and add the data to your vbo, or potentially even better - use the alpha channel of your colour as a shininess. This also works if you are using textures provided that you aren't using the alpha channel.

As for the individual texture for each face, I think you might be confused because it really makes no difference whether you are in immediate mode or are using vbos.

fiendfan1

Quote from: quew8 on May 20, 2013, 08:55:51
As for the individual texture for each face, I think you might be confused because it really makes no difference whether you are in immediate mode or are using vbos.

I am trying to load a 3d .obj file with a .mtl file for textures and materials, and I have the parsing of the file down. Now I have a variable for each face telling what texture to use. So how would I get that data to the shader?

quew8

Simple Method:
Bind texture for face 1, render face 1, bind texture for face 2, render face 2 ... This is not the most efficient of means as not only do you have to keep changing the texture binding, but you also need to keep calling the draw method of choice instead of just once.

Method 2: (Requires you use your own shaders)
Bind each texture you need to a different texture unit (glActiveTextureX then glBindTexture). Then create an attribute variable for each vertex which tells it which texture it needs. Then choose the appropriate sampler in the fragment shader. Also not a brilliant method, it depends on their only being so many textures for each model, requires another attribute for each vertex which could be just for each face and requires you use several if statements in the shader (no arrays of samplers).

Method 3: (this is probably the best for this and future endeavors)
Use texture atlas / texture sheet (whatever you want to call a single texture containing several images). I'm not going to explain this because its a simple enough concept and there are vast numbers of tutorials out there. The idea is to just mess around with the texture coordinates.

Method 4:
Look into array textures or 3d textures. (Array textures are 3.0+ only, not sure about 3d textures)

fiendfan1

Quote from: quew8 on May 21, 2013, 08:31:52
Method 2: (Requires you use your own shaders)
Bind each texture you need to a different texture unit (glActiveTextureX then glBindTexture). Then create an attribute variable for each vertex which tells it which texture it needs. Then choose the appropriate sampler in the fragment shader. Also not a brilliant method, it depends on their only being so many textures for each model, requires another attribute for each vertex which could be just for each face and requires you use several if statements in the shader (no arrays of samplers).

In order to load .obj models I'm going to have to do this. I have a variable set to each face telling it what texture to use. The only thing I'm confused about is getting that information from java to the shaders. How would I pass every texture id variable? glUniformx? And what data type would I use?

quew8

Create an int type attribute variable in you vertex shader. Then switch on this whether to use sampler1, sampler2, sampler3 or whatever you want to call them.

If you don't know what attributes are: http://www.lwjgl.org/wiki/index.php?title=GLSL_Tutorial:_Communicating_with_Shaders
If you don't know about having multiple textures: http://www.lwjgl.org/wiki/index.php?title=GLSL_Tutorial:_Texturing