2
\$\begingroup\$

I am using OpenGL to render the following scene, using vertex data from one of the map files of a popular MMORPG. The data is chunked and the pictured scene is made up of 256 (16x16) chunks.

However between the chunks I am seeing what I believe to be glitches due to the float precision. Yet I am not doing any large translations and rendering very close to the origin, should I be seeing this problem? The glitches very noticeable as you fly over the scene with it flickering different points along the chunk edges.

I was wondering if I was overlooking something simple or there are tricks other games use to mask this problem. I guess the source data could be the reason for this problem but I am not aware of it happening in the original game.

Overview Zoomed

View screenshots in a new window to see the issue.

\$\endgroup\$
2
\$\begingroup\$

The loss of precision happens due to the rotation in your combined view-model or projection-view-model` matrix.

You will need to use a vertex shader (if not already using one) and apply the model matrix (or a plain translation in your case since those are axis-aligned chunks) before applying the view-projection separately:

uniform vec2 chunk_offset;

...

vec4 temp = vec4(chunk_vertex.xy + chunk_offset, chunk_vertex.z, 1) * projection_view_matrix; 

The isue is because the +/- chunk offset gets rotated first and put into the translation part of the combined projection-view-model matrix causing an initial precision loss before being added to the also-rotated vertex coordinates (another precision loss).

Separating the operations avoid this loss of precision and your +0.5 vertex will match your -0.5 vertex + 1.0 chunk offset perfectly giving the exact same value which will then be rotated with both hitting the same loss of precision in the projection-view matrix.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.