PDA

View Full Version : GL_TEXTURE_CUBE_MAP_ARRAY only rendering all shadows tosingle1 face



paul_g_griffiths
01-18-2017, 11:26 AM
I trying to create shadows with multiple point lights.
Original code is : https://learnopengl.com/#!Advanced-Lighting/Shadows/Point-Shadows

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.

paul_g_griffiths
01-18-2017, 02:46 PM
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.

https://s29.postimg.org/daa5tr7ef/Sketch.jpg

Dark Photon
01-18-2017, 04:35 PM
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 (https://www.khronos.org/opengl/wiki/Geometry_Shader#Layered_rendering) and a geometry shader.

paul_g_griffiths
01-18-2017, 08:08 PM
Thanks, I have a GS shader all set up. Ill look into it. :)

paul_g_griffiths
01-18-2017, 10:11 PM
Thanks Dark Photon works great.

paul_g_griffiths
01-19-2017, 10:24 AM
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.

https://s23.postimg.org/3o12diuwr/Sketch.jpg