简体   繁体   English

Pre Z缓冲区通过OpenGL?

[英]Pre Z buffer pass with OpenGL?

How exactly can I do a Z buffer prepass with openGL. 我怎样才能使用openGL进行Z缓冲预处理。

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 谢谢

// 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();

You're doing the right thing with glColorMask. 你正在使用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). 你需要GL_LEQUAL,而不是GL_LESS(这恰好是默认值)。

glDepthFunc(GL_LEQUAL);

If i get you right, you are trying to disable the depth-test performed by OpenGL to determine culling. 如果我找到了你,你试图禁用OpenGL执行的深度测试来确定剔除。 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. 不要忘记在每次通过开始时清除深度缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM