Jump to content

  • Log In with Google      Sign In   
  • Create Account


shadow buffer depth not reset properly


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 miggs   Members   -  Reputation: 260

Like
0Likes
Like

Posted 07 August 2012 - 02:53 PM

it seems as if glClear(GL_DEPTH_BUFFER_BIT); does not do it's job properly (probably due to some wrong setup on my side).

when i render the depth into a color attachment (the commented code instead of the uncommented code) using the gl_Position.z component in the fragment shader everything works fine, when my sun is moving and the shadow map is recalculated, it is correctly reset and redrawn and i have correct shadows.

here is the setup code:

  CheckGL(glGenFramebuffers(1, &m_Fbo));
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo));

  //glActiveTexture(GL_TEXTURE0);
  CheckGL(glGenTextures(1, &m_ShadowTexture));
  // depth
  CheckGL(glBindTexture(GL_TEXTURE_2D, m_ShadowTexture));
  CheckGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, sMapWidth, sMapHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
  CheckGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE));
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));//GL_CLAMP_TO_BORDER
  CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));//GL_CLAMP_TO_BORDER
  CheckGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_ShadowTexture, 0));
  //CheckGL(glBindTexture(GL_TEXTURE_2D, m_ShadowTexture));
  //CheckGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sMapWidth, sMapHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
  //CheckGL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
  //CheckGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ShadowTexture, 0));
  // disable writing to the color buffer
  CheckGL(glDrawBuffer(GL_NONE));
  CheckGL(glReadBuffer(GL_NONE));
  CheckGL(glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ));
  CheckGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
  bool succeeded = OpenGLCheckFramebuffer(__FILE__, __LINE__);
  CheckGL(glBindTexture(GL_TEXTURE_2D, 0));
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));


and thats how i use them
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo));

  CheckGL(glDrawBuffer(GL_NONE));
  CheckGL(glReadBuffer(GL_NONE));

  // when using color attachment
  //CheckGL(glDrawBuffer(GL_COLOR_ATTACHMENT0));

  CheckGL(glViewport(0,0,sMapWidth, sMapHeight));
 
  CheckGL(glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ));
  CheckGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); // when using GL_DEPTH_BUFFER_BIT with depth_attachment, i only see black, while when clearing both color and depth i see the depth attachment without beeing cleared (screenshot attached)
  CheckGL(glColorMask(0,0,0,0)); // this is 1,1,1,1 if i use color_attachment
 
 
  // render scene...
 
  CheckGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
  CheckGL(glColorMask(1,1,1,1));

here's how it looks like:
the top 2 images are using the depth attachment, i can't provide a video, but when the sun is moving, this is what happens (no depth clearing)
the bottom 2 images clear and render correctly

Posted Image

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS