Pre Z缓冲区传递与OpenGL? [英] Pre Z buffer pass with OpenGL?

查看:136
本文介绍了Pre Z缓冲区传递与OpenGL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以用openGL做一个Z缓冲区prepass。



我试过这个:

  glcolormask(0,0,0,0); // disable color buffer 

//绘制场景

glcolormask(1,1,1,1); // reenable color buffer

//绘制场景

//翻转缓冲区

但它不工作。这样做后我没有看到什么。



感谢

解决方案

$ p> //清除所有内容
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// z-prepass
glEnable(GL_DEPTH_TEST); //我们想深度测试!
glDepthFunc(GL_LESS); //我们想得到最近的像素
glcolormask(0,0,0,0); //禁用颜色,它没有用,我们只想要深度。
glDepthMask(GL_TRUE); //询问z写

draw()

//真实渲染
glEnable(GL_DEPTH_TEST); //我们还需要深度测试
glDepthFunc(GL_LEQUAL); // EQUAL也应该工作。 (只画出像素,如果他们是最近的)
glcolormask(1,1,1,1); //我们这次需要颜色
glDepthMask(GL_FALSE); //写z组件现在已经没用了,我们已经有了

draw();


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

解决方案

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

这篇关于Pre Z缓冲区传递与OpenGL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆