Depth Offset in OpenGL

What would be the best way to compensate for depth in OpenGL? Currently, I have an index vertex attribute for each polygon, which I go to the vertex shader in OpenGL. My goal is to compensate for the depth of the polygons, where the highest index will always be ahead of the lower index. I currently have this simple modifying approach gl_Position.z.

gl_Position.z += -index * 0.00001;
+5
source share
1 answer

The usual way to set auto offset for depth is glPolygonOffset(GLfloat factor,GLfloat units)

GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE GL_POLYGON_OFFSET_POINT , . factor * DZ + r * units, DZ - angular, r , . .

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

, gl_FragDepth .

gl_FragDepth, :

, gl_FragDepth , . gl_FragDepth, ( z gl_FragCoord), , gl_FragDepth.

, gl_FragDepth (. GLSL gl_FragCoord.z 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_COMPONENT24 GL_DEPTH_COMPONENT32 , 16, 24 32 [0, 1].

, GL_DEPTH_COMPONENT32F 32- IEEE 754.

+5

Source: https://habr.com/ru/post/1682264/


All Articles