内置函数

GLSL ES 提供了很多内置函数,我们一起来看下:

角度函数

radians 角度制转孤度制 degrees 弧度制转角度制

三角函数

sin 正弦 cos 余弦 tan 正切 asin 反正弦 acos 反余弦 atan 反正切

指数函数

pow 开方 exp 自然指数 log 自然对数 exp2 2的x方 log2 以2为底对数 sqrt 开平方 inversesqrt 平开方的倒数

通用函数

abs 绝对值 min 最小值 max 最大值 mod 取余数 sign 取下负号 floor 向下取整 ceil 向上取整 clamp 限定范围 mix 线性内插 step 步进函数 smoothstep 艾米内插步进 fract 获取最小数部分

几何函数

length 矢量长度 distance 两点间距离 dot 内积 cross 外积 normalize 归一化 reflect 矢量反射 faceforward 使向量“朝前”

矩阵函数

matrixCmpMult 逐元素乘法

矢量函数

lessThan 逐元素小于 lessThanEqual 逐元素小于等于 greaterThan 逐元素大于 greaterThanEqual 逐元素等于 equal 逐元素等于 notEqual 逐元素不等 any 任一元素为true则为true all 所有元素为true则为true not 逐元素取补

纹理查询函数

texture2D 在二维纹理中获取纹素 textureCube 在立方体纹理中获取纹素 texture2DProj texture2D 的投影版本 texture2DLod texture2D的金字塔版本 textureCubeLod textureCube的金字塔版本 texture2DProjLod textureCubeLod的投影版本