定义
浮点数和整数类型的区间和精度取决于数据来源(varying, uniform, texture look-up, etc.), 是在片元着色器还是在顶点着色器中,及其他细节。Precision Qualifier的用处就是定义一个变量的最小的储存需求。
Precision Qualifiers
任何浮点数或整数的定义可以由这三个precision qualifier之中的一个定义
例子
lowp float color;
varying mediump vec2 Coord;
lowp ivec2 foo(lowp mat3);
highp mat4 m;
Precision qualifiers declare a minimum range and precision that the underlying implementation must use when storing these variables. Implementations may use greater range and precision than requested, but not less.
The required minimum ranges and precisions for precision qualifiers are
where Floating Point Magnitude Range is the range of magnitudes of non-zero values. For Floating Point Precision, relative means the precision for any value measured relative to that value, for all non-zero values. For all precision levels, zero must be represented exactly. For integer types, all integer values within the specified range must be represented.
If an implementation cannot provide the declared precision for storage of a variable in a compilation unit, it must result in a compilation or link error.
For high and medium precisions, integer ranges must be such that they can be accurately represented by the corresponding floating point value of the same precision qualifier. That is, a highp int can be represented by a highp float, a mediump int can be represented by a mediump float. However, lowp int CANNOT be represented by a lowp float;
The vertex language requires any uses of lowp, mediump and highp to compile and link without error. The fragment language requires any uses of lowp and mediump to compile without error. Support for highp is optional.
默认精度
顶点着色器中默认精度:
-
precision highp float;
-
precision highp int;
-
precision lowp sampler2D;
-
precision lowp samplerCube;
像素着色器中默认精度
-
precision mediump int;
-
precision lowp sampler2D;
-
precision lowp samplerCube;
-
float 没有默认精度
建议
一般来说:
vertex position : highp
texture coordinate : midump
colors : lowp