GL_TEXTURE_CUBE_MAP_ARRAY only rendering all shadows tosingle1 face

I trying to create shadows with multiple point lights.
Original code is : Learn OpenGL, extensive tutorial resource for learning Modern OpenGL

Problem is it’s only rendering all shadows to a single face.

This is the code I’m using to create the cube map array:

	// Configure depth map FBO
	const GLuint SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
	GLuint depthMapFBO;
	glGenFramebuffers(1, &depthMapFBO);
	// Create depth cubemap texture
	GLuint depthCubemap;
	glGenTextures(1, &depthCubemap);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, depthCubemap);
	glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1, GL_DEPTH_COMPONENT32, SHADOW_WIDTH, SHADOW_HEIGHT, totalLights * 6);

	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
	// Attach cubemap as depth map FBO's color buffer
	glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0);
	glDrawBuffer(GL_NONE);
	glReadBuffer(GL_NONE);
	if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
		std::cout << "Framebuffer not complete!" << std::endl;
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

And this is how I’m binding to a layer when rendering the shadow depth map:

glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0, 0);

This is the geometry shader that generates the 6 faces:

#version 450 core
layout (triangles) in;
layout (triangle_strip, max_vertices=18) out;

uniform mat4 shadowTransforms[6];

out vec4 FragPos; // FragPos from GS (output per emitvertex)

void main()
{
    for(int face = 0; face < 6; ++face)
    {
        gl_Layer = face; // built-in variable that specifies to which face we render.
        for(int i = 0; i < 3; ++i) // for each triangle's vertices
        {
            FragPos = gl_in[i].gl_Position;
            gl_Position = shadowTransforms[face] * FragPos;
            EmitVertex();
        }    
        EndPrimitive();
    }
} 

If I change:

 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0, 0);

to:

glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0, 1);

Then it draws all shadows to a different face.

Has anyone had any experience at cube map arrays?
Can you help me out?

Thanks.

Not to worry, got it working. Since glFramebufferTextureLayer binds to a specific layer I rendered the scene 6 times, once for each face.
Though if you know how to render the scene only once then please tell.

IIRC, you can do that kind of thing with Layered Rendering and a geometry shader.

Thanks, I have a GS shader all set up. Ill look into it. :slight_smile:

Thanks Dark Photon works great.

Thought I would show what I’ve been doing today.
It’s a portal system with clipping geometry and shadows. Took me a while to work out the clipping shadows part. Already had the portal code I created the other day.
Still got to add lighting into the portal and clip that too, going to take some time working that out.
It’s mainly for a 3D GUI system I’m creating and portals are required for the clipping.


for(uint i = 0 ; i < 6; i ++)
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,0, GL_DEPTH_COMPONENT16,w,h,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);

to attatch


	
    glGenFramebuffers(1,&tFrameBuffer);
    glBindFramebuffer(GL_FRAMEBUFFER,FrameBuffer);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0);

glFramebufferTexture will allow you to render all the 6 faces at once with geomtry shader