glsl中lowp, mediump, highp的区别 (Precision Qualifier)

定义

浮点数和整数类型的区间和精度取决于数据来源(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

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值