PDA

View Full Version : How to know a particular vertex location is visible



sharath
03-20-2017, 01:25 AM
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.

Silence
03-20-2017, 03:58 AM
Occlusion queries (https://www.khronos.org/opengl/wiki/Query_Object) is most certainly what you are looking for.

sharath
03-20-2017, 05:48 AM
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.

john_connor
03-20-2017, 06:21 AM
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:
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

Silence
03-20-2017, 09:29 AM
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 (http://http.developer.nvidia.com/GPUGems/gpugems_ch29.html) might help you. If you still have issues, then post back.

GClements
03-21-2017, 05:08 AM
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.