I'm trying to render a shadow cubemap but I'm getting a black texture. I tried to look for an answer but most of the answers I found seem to be either including an unnecessary color attachment or the issue is with the projection of the shadow map. I got it to work for 2D images (dir + spot lights) but not point lights due to this issue.
Here is my Framebuffer generation code:
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glGenTextures(1, &depthBuffer);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthBuffer);
for (size_t i = 0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + (GLenum)i, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthBuffer, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
fprintf(stderr, "Framebuffer Error. Status 0x%x\n", status);
}
// Unbind
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
Here is my shadow map rendering code run for each view. I don't use geometry shaders to automatically swap between the views because right now I'm trying to support everything starting 3.1 (I have a decent PC but my old laptop only supports that.) I may support both paths based on performance later:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
for (size_t j = 0; j < 6; j++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, depthBuffer, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
geometryCache->Draw(proj, view[j]);
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
And finally, I render the deferred rendering sphere for the point light including this:
...
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, depthBuffer);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
...
Does anyone have any ideas? Also, is it better to use gl_FragDepth to manually define the depth or to use a blank fragment shader for shadow maps (both spotlight and pointlight? Thanks in advance!