'Layered rendering with OpenGL ES

I am trying to implement the layer rendering. I have some doubts. 1)Can we do layered rendering without a Geometry shader. I mean passing the layer number value from the vertex shader to the fragment shader. set gl_Layer in the fragment shader. 3)I tried setting the gl_Layer value hardcoded in the fragment shader. first, I set it to Zero and I observed the image and I saw my triangle rendered at the bottom left corner of the image. Next, I changed the gl_Layer value to 1 .but again I see it in the same place as before.

How to layer rendering works ??? and let's say I have 4 layers, all the layers will be present side by side in a single image after drawing to 4 layers??

can someone please explain this?

Thank you



Solution 1:[1]

Can we do layered rendering without a Geometry shader.

Both OpenGL ES and desktop OpenGL supports layered rendering through the Geometry Shader. However, only desktop GL has the ARB_shader_viewport_layer_array extension that allows VS's to define the layer being rendered to.

I tried setting the gl_Layer value hardcoded in the fragment shader.

In a fragment shader, gl_Layer is an input; modifying it will accomplish nothing. The layer to be rendered to is a property of the primitive (which is why the GS is the one that outputs it). A primitive is rasterized for a particular layer. By the time a fragment is generated, the layer that the fragment targets has already been set.


Layered rendering allows rendering to layered images. This means that each primitive is assigned a layer by the vertex processing step. When the rasterizer rasterizes the primitive, the fragments generated will be written to the specific layer to which the primitive was assigned.

The images are not "side by side"; they are part of layered images like array textures.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1