`precision mediump float`是什么意思? [英] What does `precision mediump float` mean?
问题描述
在 learningwebgl 教程1中,我在片段着色器中发现了一条有趣的行.
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?
如果我删除这条线,什么都不会改变.一切都是一样的.那么precision mediump float
是什么意思呢?
And if I remove this line, nothing changes. Everything is the same.
So what does precision mediump float
mean?
推荐答案
这决定了 GPU 在计算浮点数时使用的精度.highp
是高精度的,当然比 mediump
(中精度)和 lowp
(低精度)更密集.
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).
有些系统根本不支持highp
,这会导致代码在这些系统上根本无法运行.
Some systems do not support highp
at all, which will cause code not to work at all on those systems.
在支持 highp
的系统上,您会看到性能下降,应尽可能使用 mediump
和 lowp
.我看到的一个很好的经验法则是:
- highp
用于顶点位置,
- mediump
用于纹理坐标,
- lowp
用于颜色.
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.
希望有帮助!
这篇关于`precision mediump float`是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!