Skip to content

[rlgl] fix vertex calculation precision in vertex shader for depth buffer#5609

Closed
arlez80 wants to merge 1 commit intoraysan5:masterfrom
arlez80:fix_shader
Closed

[rlgl] fix vertex calculation precision in vertex shader for depth buffer#5609
arlez80 wants to merge 1 commit intoraysan5:masterfrom
arlez80:fix_shader

Conversation

@arlez80
Copy link
Contributor

@arlez80 arlez80 commented Mar 1, 2026

Insufficient precision in vertex calculations causes depth calculation issues when 3D rendering, resulting in Z-fighting or clipping error.
I fixed specify highp to ensure sufficient precision.

The screen flickers with every camera movement, I'm took two screenshots of the issues occurring.
environment: RG40XXH (Allwinner h700; Quad-core ARM Cortex-A53; G31 MP2 GPU)

error-screen-2

the ground is clipped.

error-screen-3

the character's some polygon is z-fighting. the ground depth is weird also.

@arlez80 arlez80 changed the title [rlgl] fix vertex calculation accuracy in vertex shader for depth buffer [rlgl] fix vertex calculation precision in vertex shader for depth buffer Mar 1, 2026
@maiconpintoabreu
Copy link
Contributor

maiconpintoabreu commented Mar 1, 2026

Hi @arlez80 the default is already highp no?
Reference: https://www.khronos.org/files/opengles20-reference-card.pdf

@arlez80
Copy link
Contributor Author

arlez80 commented Mar 1, 2026

@maiconpintoabreu yes the glsl default is highp.
but the default precision set mediump at here or here.
therefore, I have set highp for the vertex variable and model-view-projection matrix.

@raysan5
Copy link
Owner

raysan5 commented Mar 1, 2026

@arlez80 Afair, not all platforms support highp, specially for OpenGL ES 2.0, also specifying the precision at beginning should be enough. I prefer to avoid this change.

@raysan5 raysan5 closed this Mar 1, 2026
@arlez80
Copy link
Contributor Author

arlez80 commented Mar 1, 2026

@raysan5
I have a proposal, how about separate them by macro?

like:

// ...
#if defined(GRAPHICS_API_USE_HIGHP_VERTEX)
"in highp vec3 vertexPosition;      \n"
#else
"in vec3 vertexPosition;            \n"
#endif
// ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants