简体   繁体   English

Opengl深度缓冲和剔除

[英]Opengl Depth buffer and Culling

什么是在OpenGL中使用背面剔除和深度缓冲之间的区别?

Backface culling is when OpenGL determines which faces are facing away from the viewer and are therefore unseen. 背面剔除是指OpenGL确定哪些面背向观察者,因此是看不见的。 Think of a cube. 想想一个立方体。 No matter how your rotate the cube, 3 faces will always be invisible. 无论你如何旋转立方体,3个面都将永远不可见。 Figure out which faces these are, remove them from the list of polygons to be drawn and you just halved your drawing list. 弄清楚这些面临哪些面,将其从要绘制的多边形列表中删除,然后将绘图列表减半。

Depth buffering is fairly simple. 深度缓冲非常简单。 For every pixel of every polygon drawn, compare it's z value to the z buffer. 对于绘制的每个多边形的每个像素,将其z值与z缓冲区进行比较。 if it's less than the value in the z buffer set the z buffer value as the new z buffer value. 如果它小于z缓冲区中的值,则将z缓冲区值设置为新的z缓冲区值。 If not, discard the pixel. 如果没有,丢弃像素。 Depth buffering gives very good results but can be fairly slow as each and every pixel requires a value lookup. 深度缓冲提供了非常好的结果,但可能相当慢,因为每个像素都需要值查找。

In reality there is nothing similar between these two methods and they are often both used. 实际上,这两种方法之间没有任何相似之处,它们通常都被使用。 Given a cube you can first cut out half the polygons using culling then draw them using z buffering. 给定一个立方体,您可以先使用剔除切出一半多边形,然后使用z缓冲绘制它们。

Culling can cut down on the polygons rendered, but it's not a sorting algorithm. 剔除可以减少渲染的多边形,但它不是排序算法。 That's what Z buffering is. 这就是Z缓冲。

A given triangle has two sides, the front face and the back face. 给定的三角形有两个面,即正面和背面。 The side you are looking at is determined by the order the points appear in the vertex list (also called the winding). 您正在查看的一侧取决于点在顶点列表中出现的顺序(也称为绕组)。 Typically lists of triangles have alternating winding so that you can reuse the preceding two points but the facing of a given triangle in the strip doesn't alternate. 通常,三角形列表具有交替缠绕,因此您可以重复使用前两个点,但条带中给定三角形的面对不会交替。 Back face culling is the optimization step where in triangles in the scene which are oriented away from the view are removed from the list of triangles to draw. 背面剔除是优化步骤,其中从要绘制的三角形列表中移除场景中远离视图的三角形。

A depth buffer (z-buffer) is used to hang onto the closest thing (the depth is relative to the view) that has already been rendered. 深度缓冲区(z缓冲区)用于挂起已经渲染的最接近的东西(深度相对于视图)。 If the thing that comes up next in the draw list is behind something that I've drawn already (ie, it has a depth that places it farther away) I can skip drawing it, as it is obstructed. 如果绘图列表中下一个出现的东西是我已经绘制过的东西(也就是说,它的深度远远超出它),我可以跳过绘制它,因为它被阻挡了。 If the new thing to draw is closer, I draw it and I update the depth buffer with the new, closer value. 如果要绘制的新东西更接近,我绘制它并使用新的更接近的值更新深度缓冲区。

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

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