0

I'm implementing shadow mapping for my little 3d engine. However, there seem to be artifacts in the depth texture, which can be seen by using the texture and observing the shadows, or drawing the depth texture on a quad.

Here is what the depth texture looks like when drawn on a quad:

Yes, those little white rectangles shouldn't be there.

So, what could be causing it?

Opening the glfw window:

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindow(width, height,
               8, 8, 8, 8,
               24, 0, // 24 = depth buffer bits
               GLFW_WINDOW);

Creating the depth framebuffer and texture:

glGenFramebuffers(1, &depth_framebuffer_);

glGenTextures(1, &depth_texture_);
glBindTexture(GL_TEXTURE_2D, depth_texture_);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glBindFramebuffer(GL_FRAMEBUFFER, depth_framebuffer_);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture_, 0);

glDrawBuffer(GL_NONE);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  exit(-1);

Rendering to the depth texture:

glBindFramebuffer(GL_FRAMEBUFFER, depth_framebuffer_);
glClear(GL_DEPTH_BUFFER_BIT);
render_objects();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
tiftik
  • 978
  • 5
  • 10

1 Answers1

1

So, what could be causing it?

Looks like a hardware problem to me. I have a couple of "dead" graphics cards lying around, which exhibit similar patterns due to memory failure. Could as simple as broken solder pads and putting the graphics card into a reflow solder oven for a few seconds could fix the problem. Could as well be a dead GPU memory controller.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks. This possibility crossed my mind, but I thought there would be another explanation since I didn't experience these unusual artifacts in games or other applications. I'll test my program on other computers to see if the problem persists. – tiftik Dec 24 '12 at 14:38
  • @tiftik: Oh, such HW bugs can be concealed by many things. For example what happens if you add change the texture into a depth-stencil texture? I experienced a very similar problem years ago and by consuming a part of the video memory with a stencil buffered PBuffer (FBO weren't available at the time) I could make this problem disappear. But only with a stencil buffer added. Just a regular RGB-depth buffer => problem there. – datenwolf Dec 24 '12 at 15:10
  • I tried this on another machine that also has a Radeon card and saw a very similar pattern. Maybe it's the Radeon drivers, or maybe it's a bug in Radeon hardware. The problem goes away if I don't use an FBO and copy the default depth buffer to a texture, though this probably has performance implications due to copying. – tiftik Dec 25 '12 at 14:34
  • @tiftik: Radeon you say? Which model? I've seen similar patterns also with some non-broken Radeons and certain drivers. If so, this may very well be a driver bug as well. In any case, something like this should not happen if you render just a simple quad into a depth buffer. – datenwolf Dec 25 '12 at 15:28