Pre Z buffer pass with OpenGL?

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

How exactly can I do a Z buffer prepass with openGL.

I'v tried this:

glcolormask(0,0,0,0); //disable color buffer  //draw scene  glcolormask(1,1,1,1); //reenable color buffer  //draw scene  //flip buffers 

But it doesn't work. after doing this I do not see anything. What is the better way to do this?

Thanks

回答1:

// clear everything glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // z-prepass glEnable(GL_DEPTH_TEST);  // We want depth test ! glDepthFunc(GL_LESS);     // We want to get the nearest pixels glcolormask(0,0,0,0);     // Disable color, it's useless, we only want depth. glDepthMask(GL_TRUE);     // Ask z writing  draw()  // real render glEnable(GL_DEPTH_TEST);  // We still want depth test glDepthFunc(GL_LEQUAL);   // EQUAL should work, too. (Only draw pixels if they are the closest ones) glcolormask(1,1,1,1);     // We want color this time glDepthMask(GL_FALSE);    // Writing the z component is useless now, we already have it  draw(); 


回答2:

You're doing the right thing with glColorMask.

However, if you're not seeing anything, it's likely because you're using the wrong depth test function. You need GL_LEQUAL, not GL_LESS (which happens to be the default).

glDepthFunc(GL_LEQUAL); 


回答3:

If i get you right, you are trying to disable the depth-test performed by OpenGL to determine culling. You are using color functions here, which does not make sense to me. I think you are trying to do the following:

glDisable(GL_DEPTH_TEST); // disable z-buffer  // draw scene  glEnable(GL_DEPTH_TEST); // enable z-buffer  // draw scene  // flip buffers 

Do not forget to clear the depth buffer at the beginning of each pass.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!