Opengl layered rendering question

Started by
0 comments, last by Matias Goldberg 7 years, 3 months ago

Hey,

I'm trying to use layered rendering in opengl in the geometry shader but I'm not sure if I fully understand how it works. When I use gl_layer in the geometry shader I can pick which layer to render to in a framebuffer. How does that work then when it goes on to the fragment shader stage. Which layer does the fragment shader use? Does the fragment shader run for all the layers? I can't really find any information on how that process works internally when it comes to using layers in a geometry shader and then everything going onto the fragment shader stage. Also if that is how it works (fragment shader runs for all layer outputs) how can I know what layer is currently being used in the fragment shader so I can specify what data of an array I want to use depending on the layer in the fragment shader. This might not make any sense if my understanding of layered rendering is off.

Thanks.

Advertisement

Without a geometry shader to specify, the pixel shader's gl_Layer is always 0.

In order to render a cube (which has 6 layers), from C++ you will set one layer at a time and render over and over again.

When a geometry shader is present, the pixel shader will only produce output for that layer. If you are rendering a cubemap, you can emit 6 triangles by duplicating the original one; and assign a different layer for each.

Mind you, doing this isn't a good idea because geometry shaders are freakishly slow to the point they're nearly useless.

You can use extensions like GL_AMD_vertex_shader_layer to set the gl_Layer from the vertex shader, or GL_NV_geometry_shader_passthrough to use a geometry shader that only emits one triangle with the right gl_Layer and doesn't have the performance hit of a real GS.

If using any of these 2 extensions, if you want an object to render in all 6 cube faces; you will still have to call glDrawElements 6 times (or use instancing) and set the gl_Layer for each; as the pixel shader is ran only once.

This topic is closed to new replies.

Advertisement