1
votes

mediump float in GLES shaders is supposed to be enough for texture coordinates, but is it enough for screen coordinates?

According to the this answer, mediump float has a good amount of range - from -16384 to +16384, however the precision is only 10 bit, which means that above +1024 or below -1024, the float variable can be incremented only two pixels at a time, if I understand it correctly, so you will get pixel errors and seams between textures near screen edges.

With modern phones going up to 3840x2160 in display resolution, it looks like mediump is not enough for specifying pixel-perfect screen coordinates in the vertex shader.

I guess 1920x1080 screens are still kind of okay, if you use the middle of the screen as your zero coordinate, and not the top-left or bottom-left corner, and be careful about arithmetical operations you are performing on these variables to never exceed their safe -1024:+1024 range.

The phone manufacturers also could increase the floating point precision in their GFX hardware above the spec, to match their bigger screens, but I doubt they will.

Can someone please confirm this?

1

1 Answers

0
votes

Most GPUs are likely to implement mediump as a half-precision float. This is slightly better than the minimum allowed for mediump as it can represent all of the ints in the range -2048 to 2048 (Source), not the -1024 to 1024 that you're worrying about.

Also, you shouldn't have visible seams on properly welded geometry because rasterization rules would avoid that.

But you are absolutely right that mediump is going to cause problems on high resolution screens, you won't be able to specify exact coordinates.

I'd always recommend to use highp for position coordinates and any matrices that operate on position. However, even if you do that there's a problem on high res screens that gl_FragCoord can be implemented as a mediump (some discussion here)