60

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?

hippietrail
  • 13,703
  • 15
  • 87
  • 133
Hard Rain
  • 1,170
  • 3
  • 13
  • 19
  • Have a look at [this SO post](http://stackoverflow.com/a/6336285/344480), especially the GLSL specification. Does it answer your question? – Matthias Dec 08 '12 at 18:47
  • 2
    possible duplicate of [In OpenGL ES 2.0 / GLSL, where do you need precision specifiers?](http://stackoverflow.com/questions/5366416/in-opengl-es-2-0-glsl-where-do-you-need-precision-specifiers) – Peter O. Dec 08 '12 at 20:00
  • You did not understand what mediump means from your article, because it does not explain it. – Ivan Kuckir Oct 09 '15 at 17:18

1 Answers1

82

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!

Jeroen van Langen
  • 18,289
  • 3
  • 33
  • 50
HowDoIDoComputer
  • 1,193
  • 1
  • 9
  • 16
  • 2
    Thanks you. And is it possible somehow, if high/medium/low p is supported or not? – Hard Rain Dec 08 '12 at 19:02
  • 4
    Different 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 :) – HowDoIDoComputer Dec 08 '12 at 19:06
  • 2
    Thanks 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. – Trevor Hart Aug 28 '16 at 04:51
  • @TrevorHart - try this: http://litherum.blogspot.com/2013/04/precision-qualifiers-in-opengl-es.html – HowDoIDoComputer Aug 28 '16 at 22:28
  • Is this GLSL or GLSL ES feature? Is it deprecated? – user5280911 Dec 24 '17 at 01:02
  • It'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. – Andrea Dec 03 '19 at 20:24