I’m very new to GLSL coding, so I might be making an elementary mistake here, but I’m using fragment shaders to get a depth map (actually several depth maps, for two-step depth peeling and shadow mapping), but the shadow maps are coming out as either pure max depth, or pure min depth.
Here’s where I set up the framebuffers:
glGenFramebuffers(1, &framebuffers);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffers);
glGenTextures(DEPTH_PEEL_LAYERS, &(rendered_textures[0]));
glGenRenderbuffers(DEPTH_PEEL_LAYERS, &(depthbuffers[0]));
for (int i = 0; i<DEPTH_PEEL_LAYERS; ++i)
{
glBindTexture(GL_TEXTURE_2D, rendered_textures[i]);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, 600, 600, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, rendered_textures[i], 0);
glBindRenderbuffer(GL_RENDERBUFFER, depthbuffers[i]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, 600, 600);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffers[i]);
}
// Set the list of draw buffers.
GLenum DrawBuffers[DEPTH_PEEL_LAYERS] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3};
glDrawBuffers(DEPTH_PEEL_LAYERS, DrawBuffers);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glGenFramebuffers(DEPTH_PEEL_LAYERS, &(depthframebuffers[0]));
glGenTextures(DEPTH_PEEL_LAYERS, depth_textures);
for (int i = 0; i<DEPTH_PEEL_LAYERS; ++i)
{
glBindFramebuffer(GL_FRAMEBUFFER, depthframebuffers[i]);
glBindTexture(GL_TEXTURE_2D, depth_textures[i]);
glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT32F, 600, 600, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_textures[i], 0);
GLenum DrawBuffers[1] = {GL_NONE};
glDrawBuffers(1, DrawBuffers);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
I’m getting the issue with extremely simple shaders (vertex is just a passthrough, fragment just writes the depth to the first colour attachment’s xyz), so I’m guessing it’s an issue in setup, since “gl_FragCoord.z” in the fragment shader always seems to be “1.0”