可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.