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 2 of 2

Thread: Discarding vertices possible using element array buffer?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    25

    Discarding vertices possible using element array buffer?

    Hi all,

    I'm trying to use the discard; command in my fragment shader to eliminate vertices with a specific color. When displaying using 2D textures, borderline effects can be eliminated by setting the third parameter in glTexParameterf to GL_NEAREST:

    Code :
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);

    However, when I display my object in 3D using an element array buffer, I want to achieve the same functionality... Any idea how to do this equivalently?

    Code :
    __glewBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
     
    //glTexParameterf(GL_ELEMENT_ARRAY_BUFFER, GL_TEXTURE_MAG_FILTER,GL_NEAREST); // <- Looking for appropriate function
          glPolygonMode(GL_FRONT_AND_BACK, wireFrame ? GL_LINE : GL_FILL);
          glDrawElements(GL_TRIANGLE_STRIP, 2*(width-1)*(height-1), GL_UNSIGNED_INT, 0);
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
     
    __glewBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);


    Click image for larger version. 

Name:	snapshot1.jpg 
Views:	56 
Size:	20.5 KB 
ID:	1202
    Last edited by samvdj; 12-18-2013 at 07:15 AM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    I think you're a little confused about something here.

    Quote Originally Posted by samvdj View Post
    I'm trying to use the discard; command in my fragment shader to eliminate vertices with a specific color.
    Eliminate "vertices" with a fragment shader? Frag shader has discard, but you're not eliminating vertices at that point, but fragments. We're not dealing with vertices at this point in the pipeline.

    glTexParameterf to GL_NEAREST ... However, when I display my object in 3D using an element array buffer, I want to achieve the same functionality... Any idea how to do this equivalently?
    Code :
    __glewBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);[
     
    //glTexParameterf(GL_ELEMENT_ARRAY_BUFFER, GL_TEXTURE_MAG_FILTER,GL_NEAREST); // <- Looking for appropriate function
    ...
    The TEXTURE_MAG/MIN_FILTER settings are for texture units (the gizmos that sample textures), and the element array buffer is not a texture unit but just a bind point for a data buffer, so this doesn't work.

    But reading between-the-lines, I think I know what you're trying to ask for. Whereas with texture sampling, MAG/MIN_FILTERS of NEAREST disable color interpolation when sampling, I "think" you're saying you would like to disable color vertex attribute interpolation across polygons (this is interpolation, but in a different context from texture sampling).

    For fixed-function rendering (the old days), you could just use glShadeModel( GL_FLAT ) to disable color interpolation across triangles. Now when using shaders, you instead declare your color interpolator in the shader with the keyword "flat" to tell the driver to use no interpolation for this value -- see the GLSL manual. You also have control over which triangle vertex's attributes are used through PROVOKING_VERTEX control.

    Backing up a step though, if you're trying to throw away whole triangles whose vertices have some color that matches a shader-determined criteria, then it would be much more efficient to kill the triangle in the vertex shader rather than in every single fragment (pixel or sample) generated by the triangle. There's no discard in the vertex shader, but you can mimic this by just moving each vertex behind the near clip plane. If you're using a perspective projection, here's one way to do that:

    Code glsl:
    gl_Position =  vec4( 0,0,1,0 );    // Clipped! (with perspective projection)
    Last edited by Dark Photon; 12-18-2013 at 03:40 PM.

Posting Permissions

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