Picking a set of vertices

Started by
2 comments, last by DemonDar 9 years, 8 months ago

Hi All

I'm looking for standard/convenient solution for picking a set of vertices (see attach). Questions:

- is glFeedbackBuffer a way to go?

- if so how can I detect vertex indices and (more important) vertex visibility (e.g. it's overlapped by polygon(s)). Solutions based on culling/normals aren't perfect, for example no vertices could be selected on plane turned back. In other hand it looks too expensive to write a raytracer for this task.

Thanks

Tom

[attachment=22962:Vertices.png]

Advertisement

If you are on GL 4 you can render the teapot and at the same time output selected vertices into a nother buffer just by using a geometry shader with 2 streams. I could try to add example code but unluckily I can't use that feature on my local machine so that will be buggy code.

For vertex visibility you need to render again outputted vertices (maybe as points?) and check if Z test pass/fail or use occlusion query. If you want indices of those vertices you just have to add a vertex attribute that store the index


For vertex visibility you need to render again outputted vertices (maybe as points?) and check if Z test pass/fail or use occlusion query. If you want indices of those vertices you just have to add a vertex attribute that store the index
Thx for your reply

- how can I perform this Z test and/or occlusion query?

- should I use GL_PASS_THROUGH_TOKEN to assign index or there is other/better way?

Thanks

Those are basic GL concepts, I could try to explain everything that but that will take too long, I suggest you to look at modern OpenGL books and tutorials (opengl version 3.3 and 4.x). You need to be strong in those concepts before you ever start writing a geometry shader that write to multiple streams :/

In short:

When GPU draws triangles on the screen it does nothing more than writing color values in "pixels" and Depth values in a Zbuffer (well that's not precise, nowadays all thos values are wrote to a framebuffer object)

The reason why if you render a box behind a wall you don't see the box is because of Z test. Basically each frame the Zbuffer is resetted. Each pixel of each primitive, performs a Z test (if Z testing is enabled!), if test fails the pixel is not drawn and some computations are skipped. If test succed the pixel is drawn and a new color and Z value are drawn.

When Z testing is enabled rendering order is not important: objects appears in correct order because nearest objects will "overwrite" farest objects, and farest objects will not overwrite nearest objects.

Occlusion query allows to query GPU for occlusion => You rendered a box behind a patch of gras and you want to know how much % of the box is visible. The occlusion query allows to know how much pixels are occluded (not rendered because Z test failed). This is a simple task for the GPU but even the most complex physics engine can't do that efficiently. However occlusion query may not be enough for selecting single vertices (most notable use of occlusion query is to show lens flares when sun is visibile in videogames).

To assign the index of each vertex to the vertex itself you just need to add the index as vertex attribute

Vertices are made of "components" each component have arbitrary values (usually values that make sense to you. not to the GPU)

-Position

-Normal

-Uv

The type and value is totally free and dependent only on your needs, for example instead of using 3x32bit floating points for position, you could use a 3x16bit integer if your model is made of cubes, this is up to you.

Since every 3D model is made by vertices that are stored in a buffer, those vertices have a implicit index. You must tell to the GPU wich vertices to pick for each triangle,

Example (a quad made by 2 triangles => each triangle have 3 vertices, but there are only 4 totale vertices)

A -----------B

| \ |
| \ |
| \ |
C------------D

Vertices:

ABCD

Indices

0,2,3,0,3,1

Triangle1:

0,2,3

Triangle2:

0,3,1

... Since attributes to vertices are totally custom instead of providing a "Vertex Color", you could provide a "Vertex Index" so that when vertex is wrote to a stream who will read the stream will know wich vertex that was. but that's just because you'll need it.

For visible vertices look also at here: https://www.opengl.org/discussion_boards/archive/index.php/t-183434.html

This topic is closed to new replies.

Advertisement