Question

Here are 2 images of the same 3D scene, from the same point of view (virtual camera), with and without backCulling. The images don't depict the final mesh, but the contents of the depth buffer.

Without BackCulling

glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

enter image description here

With BackCulling

glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

enter image description here

Question

  1. Why is there such a difference Between the 2 images? Of course, one would expect difference, but I don't get why without BackCulling the depth map is so smooth, while with BackCulling the depth values don't seem so continuous.
  2. In the case without BackCulling , for a certain pixel, what is the value of the depth buffer? Is it the one closer to the camera (the smooth image looks like this), or since many things project to the same 2d point/pixel I should expect something else?

Reference - 3D Scene - 2D Frame

enter image description here

enter image description here

Was it helpful?

Solution

They're difference because you're culling the wrong faces. Your mesh data is clearly oriented so that the front face is different from OpenGL's defaults. OpenGL defaults to counter-clockwise being front. Your mesh data puts the clockwise face front (or you're inverting your mesh at some point).

So, in lieu of rearranging your vertex data, change your front face with the aptly named glFrontFace(GL_CW).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top