1

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) :

xtrium
  • 64
  • 6
  • Where is the code generating 6 faces? Compare to code here : http://stackoverflow.com/questions/462721/rendering-to-cube-map – silvesthu Jan 27 '15 at 01:19
  • There's no need to invoke this 6 times. You can do layered rendering like this (where you only output 1 triangle per-layer) in a single invocation. The reason you would use multiple invocations is to overcome a limitation on the maximum number of output vertices per invocation, and that is absolutely not a problem here (256 is the minimum limit that an implementation must support). – Andon M. Coleman Jan 27 '15 at 03:22
  • @Andon, that's not true. GS instancing enables parallel computation of the 6 faces. Instancing such a GS is like an optimization in that very specific case. – phaazon Jan 27 '15 at 08:35
  • @phaazon: I was more concerned with the fact that the shader is written to output 18 vertices per-invocation but then uses 6 invocations each writing 3 vertices. It seems that xtrium does not know what the `max_vertices` layout qualifier represents. – Andon M. Coleman Jan 27 '15 at 20:13
  • Actually, I do :) This was a remainder of experimenting without using instancing. As it's the _maximum_ number of vertices emitted per instance, having it too small would be a problem, true, but it being too large just allocates too much memory. Anyway, I reverted its value to 3, to no avail. – xtrium Jan 27 '15 at 20:44
  • @xtrium, you should edit the question then and/or answer it if you know how to solve the issue now ;) – phaazon Jan 29 '15 at 21:23

0 Answers0