Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Materials and Vertex Arrays

  1. #1
    Intern Newbie
    Join Date
    Nov 2001
    Posts
    47

    Materials and Vertex Arrays

    Hi all,

    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?

    TIA,
    GG

  2. #2
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Materials and Vertex Arrays

    Two options.
    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:-
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    (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.
    Knackered

  3. #3
    Intern Newbie
    Join Date
    Nov 2001
    Posts
    47

    Re: Materials and Vertex Arrays

    knackered:
    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.

    Thanks,
    GG

  4. #4
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Materials and Vertex Arrays

    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.
    Knackered

  5. #5
    Intern Newbie
    Join Date
    Nov 2001
    Posts
    47

    Re: Materials and Vertex Arrays

    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.

    Thanks,
    GG

  6. #6
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: Materials and Vertex Arrays

    If you're not given ambient and diffuse properties per vertex, then just use glMaterial to specify materials *before* rendering your model.
    Knackered

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •