What does `precision mediump float` mean?

41,491

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!

Share:
41,491
Hard Rain
Author by

Hard Rain

Updated on October 29, 2020

Comments

  • Hard Rain
    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
    Hard Rain over 11 years
    Thanks you. And is it possible somehow, if high/medium/low p is supported or not?
  • HowDoIDoComputer
    HowDoIDoComputer over 11 years
    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 :)
  • Trevor Hart
    Trevor Hart over 7 years
    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.
  • HowDoIDoComputer
    HowDoIDoComputer over 7 years
    @TrevorHart - try this: litherum.blogspot.com/2013/04/…
  • user5280911
    user5280911 over 6 years
    Is this GLSL or GLSL ES feature? Is it deprecated?
  • Andrea
    Andrea over 4 years
    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.