Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLES and noperspective

Tags:

c++

opengl-es

I'm rendering a number of triangles provided in clip coordinates with OpenGL ES 3.0. Using a varying, I generate interpolated texture coordinates for every fragment. However, since the interpolation uses the z coordinate of the vertices the interpolation is not linear in screen space. GLES, as far as I know, does not support the noperspective qualifier which supposedly does what I want.

Do you have a recommendation for a workaround? I could supply the clip coordinates without z, but I need z for depth testing.

like image 821
user5024425 Avatar asked Oct 14 '25 08:10

user5024425


1 Answers

I believe in your case you can fix the depth in the fragment shader (supported in ES3). You could use that to set the depth while removing the Z coordinate from the position. You would need another varying value for the Z component though.

So in fragment shader you would have something like:

...
varying zPositionComponent;
...
    vac4 actualVertexPosition = ...; // whatever you had in gl_Position
    zPositionComponent = actualVertexPosition.z;
    gl_Position = vec4(actualVertexPosition.x, actualVertexPosition.y, 0.0, actualVertexPosition.w);

then in fragment shader simply add the fragment depth correction as gl_FragDepth = zPositionComponent;

Note: I am not sure this will work or if you actually have the support for this. You might actually need to check the current depth at the fragment and discard the fragment (manually doing the depth buffer) which can complicate things... Let me know how it goes and leave the question unanswered to see some better solutions please.

like image 125
Matic Oblak Avatar answered Oct 16 '25 22:10

Matic Oblak