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

Thread: "Backface culling" GL_LINES

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Nov 2012
    Posts
    33

    "Backface culling" GL_LINES

    I have a dynamically generated "grid" (more of a lattice, if anything) with variable distances between lines that I'm drawing via VBO and GL_LINES. All the lines are in the same plane, and they are offset somewhat from the modelview's center of rotation (which appears in the center of the screen).

    I'm allowing the user to rotate the modelview freely, and I have a perspective projection matrix in place.

    Is there any way I can piggyback OpenGL's backface culling and/or matrix system to hide one side of this grid? I'm currently using a huge kluge: using gluUnProject to convert a vector that's perpendicular to the screen and taking the dot product of the resultant vector and the normal vector of the grid. It doesn't really work as well as I would have hoped, because of the perspective projection.

    I've considered a large quad with a texture or drawing individual lines with polys, but these approaches don't preserve the thickness of the lines as they are rotated. I think it might be possible with a custom shader and some linear interpolation, but I'm not sure.

    Any ideas? Thanks.

  2. #2
    Junior Member Newbie yoyonel's Avatar
    Join Date
    Sep 2010
    Location
    Paris
    Posts
    23
    Hello !


    I'm not sure to really understand your problem ...
    The plane (who contains 'all the line') is visible or not visible (cull or not cull), even with a perspective projection.
    So, when you're want to draw your grid, just compute the visibility of the plane and decide (client side) if u want to draw or not the grid (lattice, set of lines in that plane).


    Maybe i'm missing something ... tell me :-)


    YoYo

  3. #3
    Junior Member Newbie yoyonel's Avatar
    Join Date
    Sep 2010
    Location
    Paris
    Posts
    23
    If you want to do this in device side (gpu),
    you can simply add normal information for all vertex that define yours lines (the plane normal)
    and compute the culling a vertex shader (just transform the normal with the 'normal' matrix transformation, do a dot product and compare sign),
    it's work (i think).

    Good Luck,
    YoYo

  4. #4
    Intern Newbie
    Join Date
    Nov 2012
    Posts
    33
    Hi yoyonel,

    The problem is that in perspective projection, computing visibility isn't as simple as I'd like it. In an orthographic projection, all the "vision vectors" are parallel, so you need only pick one and take its dot product with the polygon normal. In perspective, however, the "vision vectors" are not parallel (when considered in world coordinates), so the previous method doesn't work as well.

    Your post got me thinking: if you apply backface culling before applying the perspective matrix, will it work? I'm trying to figure out how OpenGL does it on the GPU, and that seems to be the only logical way. If so, I'll probably get to trying to break that down with the remarkably handy matrix multiplication functions gluUnproject and gluProject.

    Quote Originally Posted by yoyonel View Post
    If you want to do this in device side (gpu),
    you can simply add normal information for all vertex that define yours lines (the plane normal)
    and compute the culling a vertex shader (just transform the normal with the 'normal' matrix transformation, do a dot product and compare sign),
    it's work (i think).

    Good Luck,
    YoYo
    This might work, actually, but I'm not sure if it will give anti-aliased lines. I will give it a try if my client-side method proves too slow.

    Thanks for your help. I'll post how well this turns out later.

    EDIT: As of this edit, I haven't made much progress, so for the time being I'm going to change my approach so I won't have to do this in the first place. I still prefer it the old way, though, so I'll still gladly take any suggestions anybody may have.
    Last edited by Aestivae; 12-14-2012 at 11:20 AM.

  5. #5
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    yoyonel's idea would work. You have to treat each line as part of a triangle. If the line is shared between different triangles, you have to duplicate it.

    An easier way would be to generate triangles (GL_TRIANGLES) instead of lines and render your grid in wireframe mode. This would work all the way down to GL 1.0
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  6. #6
    Junior Member Newbie yoyonel's Avatar
    Join Date
    Sep 2010
    Location
    Paris
    Posts
    23
    Aestivae: Perspective projection don't "bend" a plane, you need to rethink about visibility with projection transformation.
    Good Luck

Posting Permissions

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