Jump to content
  • Advertisement
Sign in to follow this  
KneeDeep

OpenGL Opengl layered rendering question

This topic is 618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!