2

With the GLE Tubing and Extrusion Library (http://www.linas.org/gle/) I am able to extrude 2D countours into 3D objects using OpenGL. The Library does all the work on the CPU and uses OpenGL immediate mode.

I guess doing the extrusion on the GPU using Geometry Shaders might be faster especially when rendering a lot of geometry. Since I do not yet have any experience with Geometry Shaders in OpenGL i would like to know if that is possible and what I have to pay attention to. Do you think it is a good Idea to move those computations to the GPU and that it will increase performance? It should also be possible to get the rendered geometry back to the CPU from the GPU, possibly using "Render to VBO".

genpfault
  • 51,148
  • 11
  • 85
  • 139
trenki
  • 7,133
  • 7
  • 49
  • 61
  • 2
    Why do you want to do this with Geometry Shaders? If you think it's going to be faster than with CPU methods, you should reconsider that. – Nicol Bolas Aug 17 '13 at 07:43
  • I figured it might be faster on the GPU. Don't you think? – trenki Aug 17 '13 at 12:37
  • What exactly are you doing with that library? Does the input change every frame? How? The extrusion itself (geometry generation) might be faster with a geometry shader, but rendering the extruded geometry might not. – Andreas Haferburg Aug 17 '13 at 22:05
  • The geometry does change every frame. – trenki Aug 18 '13 at 20:50

1 Answers1

1

If the geometry indeed changes every frame, you should do it on the GPU.
Keep in mind that every other solution that doesn't rely on the immediate mode will be faster than what you have right now. You might not even have to do it on the GPU.

But maybe you want to use shadow mapping instead, which is more efficient in some cases. It will also make it possible to render shadows for alpha tested objects like grass. But it seems like you really need the resulting shadow geometry, so I'm not sure if that's an option for you.

Now back to the shadow volumes.
Extracting the shadow silhouette from a mesh using geometry shaders is a pretty complex process. But there's enough information about it on the internet.

Here's an article by Nvidia, which explains the process in detail:
Efficient and Robust Shadow Volumes Using Hierarchical Occlusion Culling and Geometry Shaders.

Here's another approach (from 2003) which doesn't even require geometry shaders, which could be interesting on low-end hardware:
http://de.slideshare.net/stefan_b/shadow-volumes-on-programmable-graphics-hardware

If you don't need the most efficient solution (using the shadow silhouette), you can also simply extract every triangle of the mesh on it's own. This is very easy using a geometry shader. I'd try that first before trying to implement silhouette extraction on the GPU.

About the "render to VBO" part of your question:
As far as I know there's no way to read the output of the geometry shader back to the CPU. Don't quote me on this, but I've never heard of a way to do this.

fospathi
  • 537
  • 1
  • 6
  • 7
Tara
  • 1,673
  • 22
  • 30
  • 2
    One can read back the output of a geometry shader with 'transform feedback' – Sam Nov 20 '13 at 11:00
  • I know about transform feedback, but can you really read back the output to the CPU? If yes, do you know any links regarding that? I couldn't find anything. – Tara Nov 20 '13 at 12:21
  • The output is written into a regular buffer. Reading that back to the CPU works like with a vertex array buffer. The only difference is the additional buffer binding target `GL_TRANSFORM_FEEDBACK_BUFFER`. However, one can easily rebind that output buffer as a vertex array buffer for rendering. https://www.opengl.org/wiki/Transform_Feedback#Buffer_binding | Instance culling using transform feedback: http://rastergrid.com/blog/2010/02/instance-culling-using-geometry-shaders/ – Sam Nov 20 '13 at 12:31
  • Thanks a lot for the links! I'll look through the articles. So this even works if you output a variable count of primitives from the geometry shader? – Tara Nov 20 '13 at 13:07
  • You're welcome. Dynamic output is supported, there are configurable limits like buffer size and max number of output components. Lookup 'Section 2.Z, Primitive Queries' and the `MAX_*` enums here: https://www.opengl.org/registry/specs/EXT/transform_feedback.txt – Sam Nov 20 '13 at 13:15
  • 1
    Wow! That's some really nice stuff. Thx! I bet the Asker will also benefit of this information. – Tara Nov 20 '13 at 13:19