简体   繁体   中英

Grouping data from Vertex Shader to Geometry Shader

Let's suppose I have some points p1 , p2 , p3 and p4 . I need to apply some transformations to each them in the Geometry Shader phase based on its successor, so my GS would require having access to the pairs (p1, p2) , (p2, p3) , (p3, p4) . How can I achieve this? If I use the POINTS primitive I can only gain access to a single point at a time.

Please also note that this is a simplification, since in pratice I would need to have four points at a time, placed like the vertices of a cube. I have thought of using something like a line strip, but it doesn't provide enough points...

EDIT: To clarify, what I am actually trying to achieve is to have the CPU send a "cubic lattice" (?) to the GPU expressed as a set of points. My GS will have to take four of this points at a time, each representing one cube's vertex, and output triangles based on the attributes of these points.

Let's say you have your 3D lattice in a buffer. You know the order (eg by rows). So you know in advance how to extract the four points needed in each iteration. For a regular grid, you know the stride between points. Thus you can use glVertexAttribPointer() with the right stride parameter.

You can also use indexed buffer and glDrawElements .

Another aproach, likely slower, is to use four buffers bound in the same VAO and read with different attributes.

The command can be glDrawArray(GL_POINTS,...) . Or even you can try instanced drawing and use the instace ID as an indication to the lattice location.

The thing is that glDrawXXX will read from the bound buffers the number of times you specify. Each time you can read your four points.

Whatever you use, you get four points in the VS that you can pass to the GS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM