曾几何时,当>比&LT快; ......等等,什么? [英] Once upon a time, when > was faster than < ... Wait, what?

查看:137
本文介绍了曾几何时,当>比&LT快; ......等等,什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读<一个href=\"http://alfonse.bitbucket.org/oldtut/Positioning/Tut05%20Overlap%20and%20Depth%20Buffering.html\">an真棒OpenGL的教程。这真是太棒了,相信我。我目前的主题是Z缓冲区。除了解释什么是一回事,作者提到,我们可以执行自定义的深度测试,如GL_LESS,GL_ALWAYS,等他还解释说,深度值的实际意义(这是顶部,这是不)也可以定制。我至今明白。然后作者说令人难以置信:


  

范围zNear可以比zFar的范围越大;如果是,则
  窗口空间值将发生逆转,在什么构成条件
  最接近或最远观众。


  
  

此前,有人说是0窗口空间Z值最接近和
  1最远。然而,如果我们的裁剪空间Z值被否定,则
  1深度将是最接近观点和0的深度会
  最远。然而,如果我们翻转深度测试的方向(GL_LESS到
  GL_GREATER,等等),我们得到完全相同的结果。所以这真的只是一个
  惯例。 事实上,翻转z的符号和深度测试一度
  一个重要的性能优化对于许多游戏。


如果我理解正确的话,性能明智的,翻转z的符号和深度测试只不过是改变&LT; 相比于 &GT; 比较。所以,如果我理解正确,作者是不是在说谎或胡编,然后更改&LT; &GT; 曾是 至关重要的优化对于许多游戏。

是作者胡编,我误解的东西,或者是它的确是一次&LT的情况下; 较慢(极其的,正如作者说的)比&GT;

感谢澄清这一颇为好奇的事!

<子>免责声明:本人完全清楚,算法复杂度是优化的主要来源。此外,我怀疑现在它绝对不会做出任何区别,我不问这个优化什么。我只是非常,痛苦,也许比登天好奇。


解决方案

  

如果我理解正确的话,性能明智的,翻转z的符号和深度测试只不过是改变&LT;比较A>比较。所以,如果我理解正确,作者是不是在说谎或胡编,然后更改&LT;到>曾经是许多游戏的一个重要的优化。


我没有解释,特别好,因为它并不重要。我只是觉得这是琐事的有趣的一点补充。我不打算走了过来算法明确。

不过,上下文是关键。我从来没有说,&LT;比较是比>比较快。请记住:我们谈论的图形硬件深度测试,而不是你的CPU。没有运营商的LT;

我指的是一个具体的老优化,其中一帧你可以使用 GL_LESS 射程为[0,0.5]。下一帧,你渲染 GL_GREATER 射程[1.0,0.5]的。你来回走,字面意思是翻转z的符号和深度测试每一帧。

这失去深度precision中的一位,但你没有清除深度缓冲,这从前是一个相当缓慢的操作。由于深度结算不仅是释放这些天,但实际上比这个技术快,人不这样做了。

I am reading an awesome OpenGL tutorial. It's really great, trust me. The topic I am currently at is Z-buffer. Aside from explaining what's it all about, the author mentions that we can perform custom depth tests, such as GL_LESS, GL_ALWAYS, etc. He also explains that the actual meaning of depth values (which is top and which isn't) can also be customized. I understand so far. And then the author says something unbelievable:

The range zNear can be greater than the range zFar; if it is, then the window-space values will be reversed, in terms of what constitutes closest or farthest from the viewer.

Earlier, it was said that the window-space Z value of 0 is closest and 1 is farthest. However, if our clip-space Z values were negated, the depth of 1 would be closest to the view and the depth of 0 would be farthest. Yet, if we flip the direction of the depth test (GL_LESS to GL_GREATER, etc), we get the exact same result. So it's really just a convention. Indeed, flipping the sign of Z and the depth test was once a vital performance optimization for many games.

If I understand correctly, performance-wise, flipping the sign of Z and the depth test is nothing but changing a < comparison to a > comparison. So, if I understand correctly and the author isn't lying or making things up, then changing < to > used to be a vital optimization for many games.

Is the author making things up, am I misunderstanding something, or is it indeed the case that once < was slower (vitally, as the author says) than >?

Thanks for clarifying this quite curious matter!

Disclaimer: I am fully aware that algorithm complexity is the primary source for optimizations. Furthermore, I suspect that nowadays it definitely wouldn't make any difference and I am not asking this to optimize anything. I am just extremely, painfully, maybe prohibitively curious.

解决方案

If I understand correctly, performance-wise, flipping the sign of Z and the depth test is nothing but changing a < comparison to a > comparison. So, if I understand correctly and the author isn't lying or making things up, then changing < to > used to be a vital optimization for many games.

I didn't explain that particularly well, because it wasn't important. I just felt it was an interesting bit of trivia to add. I didn't intend to go over the algorithm specifically.

However, context is key. I never said that a < comparison was faster than a > comparison. Remember: we're talking about graphics hardware depth tests, not your CPU. Not operator<.

What I was referring to was a specific old optimization where one frame you would use GL_LESS with a range of [0, 0.5]. Next frame, you render with GL_GREATER with a range of [1.0, 0.5]. You go back and forth, literally "flipping the sign of Z and the depth test" every frame.

This loses one bit of depth precision, but you didn't have to clear the depth buffer, which once upon a time was a rather slow operation. Since depth clearing is not only free these days but actually faster than this technique, people don't do it anymore.

这篇关于曾几何时,当&GT;比&LT快; ......等等,什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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