如何避免在距离上发生Z战? [英] How to avoid Z-fighting in distance?

查看:103
本文介绍了如何避免在距离上发生Z战?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我最近观看了有关Z战的视频,并了解了一种简单的方法来解决它-主要是.给出的解决方案是使投影实际倾斜,以便为更近的对象提供更大的空间以进行更精确的深度测试(因为浮子只能如此精确),而更远的对象被塞满投影的一小部分.现在,我对OpenGL和图形编程非常陌生(只是慢慢学习),实际上我还没有做过足够复杂的事情,但这对我来说是个问题,但是将来我可能需要知道这一点.无论如何,上述解决方案带来的新问题是远距离的Z战(例如Skyrim,Rust等山区).是否有一种更好的解决方法,即使它具有成本效益,也不会涉及图形妥协?假设地说(由于我还不太熟悉OpenGL管道),程序中的Z值是否可以在进行深度测试之前就强制转换为两倍?

让我澄清一下.想想天际.注意山有时会忽悠吗?当使用OpenGL渲染场景时,所有对象都被填入或夹紧"到Z值从-1.0到1.0的小坐标平面中.然后对每个对象进行深度测试-树木,雪,山,动物,房屋,您可以自己命名,以便在其他物体覆盖时不会画出东西.但是,浮点只能达到一定的精度,因此将数百个对象夹持在一个很小的空间中将不可避免地导致某些对象具有完全相同的Z坐标,并且两个对象在屏幕上一起闪烁,这称为"Z"现象-斗争".我在问是否可以将每个对象的深度(z-)坐标转换为双精度,以便它们具有足够的精度(值得在可忽略的一段时间内使用可忽略的额外内存),以便按正确的顺序准确地绘制对象,不会互相夹住.

解决方案

当使用OpenGL渲染场景时,所有对象都被挤入或夹紧"到Z值从-1.0到1.0的小坐标平面中.

这只是故事的一部分.另一部分是z是非线性存储的:保真度"最高的部分是靠近Z平面的保真度,当您向后移动时,保真度会降低.有关公式,请参见此页面.

OpenGL常见问题解答 12.深度缓冲区 12.070中讨论了这一点,为什么深度缓冲区的前端有更高的精度?,而 12.080 提出了针对不同z距离的多遍渲染.

您可以使用glGetIntegerv(GL_DEPTH_BITS, &bits);查询当前深度缓冲区的大小,但是(搜索之后)似乎没有标准的方法可以更改它以使用更大(或更小)的深度.

可以通过不将其绘制为3D对象来抵消在遥远物体中发生的Z战.例如,如果您的示例中的山脉距离很远,则任何视差效果都将是不可见的.因此,在这种情况下,最好将较远的对象绘制到天空盒上.

So I recently watched a video on Z-fighting, and learned of a simple way to take care of it--mostly. The solution given was to actually skew the projection so that closer objects were given more space for more accurate depth testing (since floats can only be so precise), and further away objects were crammed into a small area of the projection. Now I'm quite new to OpenGL and graphics programming (just working through slowly), and I haven't actually made anything complex enough where this is a problem for me, but I'll probably need to know this in the future. Anyways, the new problem posed by said solution is even worse Z-fighting in the distance (e.g. the mountains in Skyrim, Rust, etc.). Is there a better work around that doesn't involve graphical compromises, even if it does cost performance? Speaking hypothetically (since I'm not totally cozy with the OpenGL pipeline yet), could Z-values in a program be cast to doubles just before being clamped for depth testing?

Let me clarify. Think of Skyrim. Notice how the mountains sometimes flicker? When a scene is rendered with OpenGL, all the objects are crammed, or "clamped" into a small coordinate plane with Z-values from -1.0 to 1.0. Then depth testing is performed on every object--trees, snow, mountains, animals, houses, you name it, so that things aren't drawn when they're covered by something else. However, floating points can only get to a certain level of precision, so clamping hundreds of objects into a tiny space inevitably results in some having the exact same Z-coordinates, and the two objects flicker together on screen in a phenomenon known as "Z-fighting". I'm asking if every object's depth (z-) coordinates can be cast into doubles, so that they have sufficient precision (worth the negligible extra memory used for a negligible period of time) in order to accurately draw objects in the right order, without clipping into each other.

解决方案

When a scene is rendered with OpenGL, all the objects are crammed, or "clamped" into a small coordinate plane with Z-values from -1.0 to 1.0.

This is only part of the story. The other part is that z is stored non-linearly: the part with the highest 'fidelity' is that close to the near Z plane, and the fidelity decreases as you travel backwards. See this page for a formula.

The OpenGL FAQ 12. The Depth Buffer discusses this in 12.070 Why is there more precision at the front of the depth buffer?, and 12.080 proposes multi pass rendering for distinct z distances.

You can query the current depth buffer size with glGetIntegerv(GL_DEPTH_BITS, &bits);, but (after searching) there seems to be no standard way to change it to use a greater (or lesser) depth.

Z fighting in far-off objects can be countered by not drawing them as 3D objects. For instance, if the mountains in your example are very far off, any parallax effects will be invisible. So in that case you'd probably be better off with drawing far objects onto a skybox.

这篇关于如何避免在距离上发生Z战?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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