Results 1 to 4 of 4

Thread: flat shading with VBO

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jan 2005
    Location
    Stockholm, Sweden
    Posts
    164

    flat shading with VBO

    I am rendering models read from files with flat shading using Vertex Buffer Objects (VBO). Now, most mesh file formats consist of a list of vertices, followed by a list of faces, where each face consists simply of small set of vertex indices (3 indices per face for a triangle mesh). This is in many ways convenient for most tasks, as the vertices can be parsed and things like normals and tex-coords can be computed, and the face-indices can be parsed in a similar fashion. All this can then be uploaded to a VBO and rendered without any problems.

    Now, in my application I want to use flat shading. By that I mean that shading is computed on a per face (i.e. triangle) basis. My understanding is that when using VBO's one must supply normal and tex-coord information on a per vertex basis, so in my case I need to duplicate vertices that are used in two or more faces, is this correct? What this means is that I will always end up having 3*num_tris number of vertices in my vertex buffer, and 3*num_tris indices in my index buffer.

    I am wondering if there is any work-around to this problem. My geometry data is static, so I could just go for a display list and let the driver optimize it, but since I like to think that the future should be embraced I would prefer working with buffers of some sort. As an additional note I am using a vertex and a fragment shader in my rendering, so setting glShadeModel(GL_FLAT) probably won't work, or would it?

    Thanks,

    T

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: flat shading with VBO

    Since the normal attributes vary for each face index, you have to build and index array which is indexing the normal array and consequently you have no choice but duplicate all remaining attributes like vertex position, uv,...

    glShadeModel just enable or disable color interpolation between vertex colors in fixed pipeline. Remember that fixed pipeline performs gouraud shading and not phong shading. Without shader there are no normal interpolation but color interpolation.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jan 2005
    Location
    Stockholm, Sweden
    Posts
    164

    Re: flat shading with VBO

    Since the normal attributes vary for each face index, you have to build and index array which is indexing the normal array and consequently you have no choice but duplicate all remaining attributes like vertex position, uv,...
    This is what I suspected. Thanks for confirming.

    glShadeModel just enable or disable color interpolation between vertex colors in fixed pipeline. Remember that fixed pipeline performs gouraud shading and not phong shading. Without shader there are no normal interpolation but color interpolation.
    Yes, in my case I don't want any interpolation on the face so I need to make sure of this myself in the shader-pair. Thus, because I can only "see" (process) one vertex at a time I need to make sure that the color is computed in the same way for each vertex of a face, hence the duplication. This may have consequences for positional lighting, but I can use directional lighting for now.

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: flat shading with VBO

    you can use a dFdx() trick to compute the triangle's normal inside a frag-shader. There's also the "varying vec4 tmp:flat" interpolation-modifier, for SM4.0 cards.

Similar Threads

  1. glDrawElements with flat shading
    By silikone in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-06-2017, 12:18 PM
  2. help with flat shading
    By ale211734 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-25-2015, 12:10 PM
  3. Implementing Flat Shading
    By Mr_Bean in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-27-2014, 02:29 PM
  4. VBO with flat shading
    By tchau83 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 09-27-2010, 08:24 AM
  5. flat shading
    By heppe in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-04-2003, 05:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean