解决Z-fighting, 使用Polygon Offset

[ 2007-02-27 18:02:51 | 作者: Admin ]
字体大小: | |
如有转载,请注明:
http://www.azure.com.cn/

当两个面共面时,会出现十分难看的z - fighting 问题,

要解决此问题可以使用, Polygon Offset, 方法如下:
drawSomething();

//同一位置绘制另一个东西
glEnable( GL_POLYGON_OFFSET_FILL ); // This is the one we need...
glPolygonOffset( g_OffsetFactor, g_OffsetUnit );

drawOtherthing();

glPolygonOffset( 0.0f, 0.0f );
glDisable( GL_POLYGON_OFFSET_FILL );
其中
g_OffsetFactor代表 factor,
g_OffsetUnit 代表 units,

关于factor, units 的解释如下:

When GL_POLYGON_OFFSET is enabled, each fragment's depth
value will be offset after it is interpolated from the depth
values of the appropriate vertices. The value of the offset
is factor * DZ + r * units, where DZ is a measurement of
the change in depth relative to the screen area of the
polygon, and r is the smallest value that is guaranteed to
produce a resolvable offset for a given implementation. The
offset is added before the depth test is performed and
before the value is written into the depth buffer.
glPolygonOffset is useful for rendering hidden-line images,
for applying decals to surfaces, and for rendering solids
with highlighted edges.

www.azure.com.cn
评论Feed 评论Feed: http://www.azure.com.cn/feed.asp?q=comment&id=302

浏览模式: 显示全部 | 评论: 4 | 引用: 0 | 排序 | 浏览: 9341
yaolq
[ 2007-03-02 12:14:11 ]
这个方法不错
你真爽,放一个月假...这几天升级新版本,调死我了
Admin
[ 2007-03-03 12:45:38 ]
你以为我想啊,
票没有安排好。
这几天烦死了。
koya
[ 2007-04-02 20:39:12 ]
是很不错,不过好象用glDepthMask(GL_FALSE)也可以实现同样的作用吧!
他们有哪些区别?
m17
[ 2008-10-24 09:19:02 ]
请问 D3D 下有类似 Polygon Offset 的功能么

此日志不可发表评论.
ħ˽ ħ˽