sách gpt4 ai đã đi

opengl - OpenGL 中的深度偏移

In lại 作者:行者123 更新时间:2023-12-04 15:07:31 29 4
mua khóa gpt4 Nike

在 OpenGL 中偏移深度的最佳方法是什么?我目前每个多边形都有索引顶点属性,我将其传递给 OpenGL 中的顶点着色器。我的目标是在深度上偏移多边形,其中最高索引始终位于较低索引的前面。我目前有这个简单的方法修改 gl_Position.z .

gl_Position.z += -index * 0.00001;

1 Câu trả lời

为深度设置自动偏移的常用方法是 glPolygonOffset(GLfloat factor,GLfloat units)

Khi GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE, or GL_POLYGON_OFFSET_POINT 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.


glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset( 1.0, 1.0 );

如果要手动操作深度,则必须设置 gl_FragDepth在片段着色器中。

gl_FragDepth , Fragment Shader :

Available only in the fragment language, gl_FragDepth is an output variable that is used to establish the depth value for the current fragment. If depth buffering is enabled and no shader writes to gl_FragDepth, then the fixed function value for depth will be used (this value is contained in the z component of gl_FragCoord) otherwise, the value written to gl_FragDepth is used.



一般来说, gl_FragDepth计算如下(见 GLSL gl_FragCoord.z Calculation and Setting gl_FragDepth):
float ndc_depth = clip_space_pos.z / clip_space_pos.w;
gl_FragDepth = (((farZ-nearZ) * ndc_depth) + nearZ + farZ) / 2.0;

您需要向深度添加或减去以获得最小差异的最小偏移量取决于深度缓冲区的格式。

深度缓冲区格式 GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT24GL_DEPTH_COMPONENT32是规范化的整数格式,
其中 16、24 或 32 位整数范围映射到深度值 [0, 1]。

另一方面,格式 GL_DEPTH_COMPONENT32F是 IEEE 754 标准 32 位浮点格式。

关于opengl - OpenGL 中的深度偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45314290/

29 4 0
Bài viết được đề xuất: raku - Perl 6 本身是否支持契约式设计?
Bài viết được đề xuất: keras - 构建 Keras Tensorboard 图
Bài viết được đề xuất: apache-spark - 启动集群时在 EMR 上配置 Zeppelin 的 Spark 解释器
Bài viết được đề xuất: docker - 将启动脚本添加到 dockerfile
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com