What does `precision mediump float` mean?
This determines how much precision the GPU uses when calculating floats. highp
is high precision, and of course more intensive than mediump
(medium precision) and lowp
(low precision).
Some systems do not support highp
at all, which will cause code not to work at all on those systems.
On systems that DO support highp
, you will see a performance hit, and should use mediump
and lowp
wherever possible. A good rule of thumb that I saw was:
- highp
for vertex positions,
- mediump
for texture coordinates,
- lowp
for colors.
Hope that helps!
Hard Rain
Updated on October 29, 2020Comments
-
Hard Rain over 3 years
In the learningwebgl tutorial1 I've found an interesting line in the fragment shader.
precision mediump float;
I've found an article about it here, but I still can't understand what does it mean?
And if I remove this line, nothing changes. Everything is the same. So what does
precision mediump float
mean? -
Hard Rain over 11 yearsThanks you. And is it possible somehow, if high/medium/low p is supported or not?
-
HowDoIDoComputer over 11 yearsDifferent systems will support different settings. The only thing I've ever read about NOT being supported is high. I think medium and low should be safe, but it's something to keep in mind some day if some code isn't running on a device and you can't find a reason :)
-
Trevor Hart over 7 yearsThanks for that rule of thumb, really helpful, do you know where I can find the actual precision of each in terms of the mantissa of each type? I know it doesn't really matter I'm just curious about it.
-
HowDoIDoComputer over 7 years@TrevorHart - try this: litherum.blogspot.com/2013/04/…
-
user5280911 over 6 yearsIs this GLSL or GLSL ES feature? Is it deprecated?
-
Andrea over 4 yearsIt's GLSL ES. In practice, it is mediump/lowp that may not be supported, specifically on desktop GPUs. On mobile, there is usually reduced precision support.