What does `precision mediump float` mean?

JavascriptOpengl EsWebglTerminologyFragment Shader

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHard RainView Question on Stackoverflow
Solution 1 - JavascriptHowDoIDoComputerView Answer on Stackoverflow