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: How to know a particular vertex location is visible

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    7

    How to know a particular vertex location is visible

    My objective is to pick a nearest node(vertex) in a mesh of trias and quads which are huge in number( in a 3D model ).

    I am picking by Ray cast method. Now I would like to know that the nearest node is not behind any another triangle or quad.

    How to query, whether a particular node is in front of any object in opengl.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Location
    France
    Posts
    316
    Occlusion queries is most certainly what you are looking for.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    7
    I have drawn the mesh with glDrawElements.

    Can you help me with a sample code, if you have.

    I have gone through the manual, but, I could not understand on usage point of view
    Help me how to use this.

  4. #4
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    381
    the vertexshader executes on each vertex of the model, and you want to know which one is nearest to a certain position, maybe "transform feeback" can help. in the vertexshader, you upload this:
    Code glsl:
    uniform vec3 position_to_compare = vec3(0, 0, 0);
    -- before you start rendering, upload the "position_to_compare"
    -- calculate the vertexposition in worldspace
    -- calculate the distance of that vertex to the "position_to_compare"
    -- feedback the distance

    https://www.khronos.org/opengl/wiki/Transform_Feedback

    when done, you have a buffer full of distance values (of all vertices), the next thing would be to figure out what distance is the smallest: a computeshader could do that task, or you could do it yourself on the cpu-side (that would be much slower)

    https://www.khronos.org/opengl/wiki/Compute_Shader

  5. #5
    Member Regular Contributor
    Join Date
    Jul 2012
    Location
    France
    Posts
    316
    Quote Originally Posted by sharath View Post
    I have drawn the mesh with glDrawElements.

    Can you help me with a sample code, if you have.

    I have gone through the manual, but, I could not understand on usage point of view
    Help me how to use this.
    This might help you. If you still have issues, then post back.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,308
    Quote Originally Posted by sharath View Post
    How to query, whether a particular node is in front of any object in opengl.
    OpenGL is a rendering API, not a modelling or geometry library.

    That said, you can use transform-feedback mode or a compute shader as a means to accelerate computations.

    Alternatively::if you can accept the limitations, you can render the scene, then project the vertex position to window coordinates, query the relevant pixel from the depth buffer, and test whether the vertex' depth is greater or less than the value from the depth buffer. This approach may be preferable if you're going to be rendering the scene anyhow.

Posting Permissions

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