I'm trying to render a shadow cubemap in one pass, using layered rendering.
I've tried to be as thorough as possible :
- I have bound a cubemap both depth attachment (GL_DEPTH_ATTACHMENT_32F) and color attachment 0 (GL_R32F) using glFramebufferTexture
- I made sure to check whether, once the textures are attached to the FBO, that the framebuffer's completeness - it is complete
- I have tried both geometry shader instancing using "layout(triangles, invocations=6) in;" and without (resorting to a for(int layer=0;layer<6;++layer) loop, setting gl_Layer = l, first for each primitive, then for each vertex)
Long story short, the first layer (ie. X+ in this case) gets rendered, but none of the others do, be it in the depth or color attachment.
It seems documentation on layered rendering is pretty sparse, even the red book spends at most half a page on it... Anyway :
The code :
Shaders :
Vertex :
#version 440 core layout(location = 0) in vec3 attrPosition; void main() { gl_Position = vec4(attrPosition, 1.0); }
Geometry :
#version 440 core layout(triangles, invocations = 6) in; layout(triangle_strip, max_vertices = 18) out; uniform mat4 dkModelMatrix; uniform mat4 dkViewMatrices[6]; uniform mat4 dkProjectionMatrix; void main() { gl_Layer = gl_InvocationID; for(int i = 0; i < 3; ++i) { gl_Layer = gl_InvocationID; gl_Position = dkProjectionMatrix * dkViewMatrices[gl_InvocationID] * dkModelMatrix * gl_in[i].gl_Position; EmitVertex(); } EndPrimitive(); }
Fragment :
#version 440 core layout(location = 0) out vec4 dkFragCoord; void main() { dkFragCoord = vec4( vec3(float(gl_Layer) * 0.1 + 0.5) , 1.0); }
C++ (mostly using my engine's classes, which actually do the bare minimum and has already been tested, in the case of FBOs, with 2D (spot) shadowmaps) :
Shadowmap-related variables creation : https://gist.github.com/xtrium-lnx/77d8989b3c2370607cfc
Shadowmap rendering : https://gist.github.com/xtrium-lnx/387b97c077525be60bb4