View Full Version : Materials and Vertex Arrays
01-27-2002, 06:44 PM
I'm wondering if one could include material properties in vertex arrays? I don't want to preassign colors to vertices but rather have them computed from ligting, material properties, and normal vectors. Is this possible or must I choose textures to render the object?
01-27-2002, 11:58 PM
1) Use GL_COLOR_MATERIAL. If you execute this command set(below) before drawing your vertex array, then every colour in your colour array will change the specified material property rather than the colour:-
(every time a colour value is read from the colour array, the AMBIENT_AND_DIFFUSE properties for the next triangle will change to that colour value).
2) Use a vertex program, and calculate the lighting yourself - you can use the vertex attribute pointers to pass in seperate values for ambient, diffuse, emissive and specular material properties. This gets you round the limitation of GL_COLOR_MATERIAL that only diffuse-per-vertex OR diffuse+ambient-per-vertex OR specular-per-vertex OR ambient-per-vertex OR emission-per-vertex.
01-28-2002, 02:40 AM
By using a "vertex program" you mean write my own "colour" program to extract information from my lighting model, material properties, normal vectors and assign colour to the vertices of my triangle, right? I believe that could easily be done, as described in the Red Book, page 211, 3rd edition. I guess I would compute the colour each time I pass my position in the scene changes.
01-28-2002, 03:12 AM
No, I mean using the NVidia GL_VERTEX_PROGRAM_NV extension.
It enables you to offload all this kind of stuff onto the graphics card.
You *could* calculate your stuff in software, which is what you seem to be suggesting (BTW, you wouldn't have to recalculate the colours every time the viewpoint changes, unless you've got a significant specular contribution - only when the light or the mesh moves).
But what's wrong with using GL_COLOR_MATERIAL? It's a robust and totally generic OpenGL solution.
01-28-2002, 03:33 AM
I'm not sure what's wrong with GL_COLOR_MATERIAL. It looks like I need a colour array to begin with before I use this property and this is the array I'm trying to computer per vertex. I could be looking at this the wrong way or I don't quite understand how GL_COLOR_MATRIAL works. In my model I'm given material ambient & diffuse, lighting ambient & diffuse, vertex indices and vertex coordinates.
I'll think some more about it.
01-28-2002, 05:34 AM
If you're not given ambient and diffuse properties per vertex, then just use glMaterial to specify materials *before* rendering your model.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.