glPolygonOffset 函数解析
两个面共面或面之间距离很近时,会出现十分难看的z - fighting 问题, 另外在地形上绘制等高线也有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.
我的翻译:
当GL_POLYGON_OFFSET启用,多边形每个由相应顶点内插得到的深度值将被“偏移”。
偏移值的量为 “factor * DZ + r * units”,这里DZ是多边形深度值相对其屏幕面积变化的一个量算值,
r 是一个可以确保能产生一个可用于实行的偏移最小值。 这个“偏移”值在深度检测和值被写入z-Buffer之前要加到片段深度值上。
在渲染隐藏线影像,申请表面注记,和渲染带有高亮边的填充体方面glPolygonOffset很有用。
经测试,经验值,一般这三种参数肯定有一种能达到预想效果。
glPolygonOffset( 0.0f, 0.1f );
glPolygonOffset( -0.1f, 0.2f );
glPolygonOffset( 0.1f, 0.2f );
我的测试如果要线(用线模式绘制的面)偏移面,用glPolygonOffset( -0.1f, 0.2f );
如果用面偏移线(用线模式绘制的面),用glPolygonOffset( 0.0f, 0.1f ); 或glPolygonOffset( 0.1f, 0.2f ); 都可以。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)