GLSL常用函数
2020-11-26 本文已影响0人
hjm1fb
- genType
abs
(genType x)绝对值
Returns x if x >= 0, otherwise it returns –x. - genType
sign
(genType x)符号
Returns 1.0 if x > 0, 0.0 if x = 0, or –1.0 if x < 0 - genType
floor
(genType x)向下取整
Returns a value equal to the nearest integer that is less than or equal to x - genType
ceil
(genType x)向上取整
Returns a value equal to the nearest integer that is greater than or equal to x - genType
fract
(genType x)正数取小数,负数取(小数部分+1)
Returns x – floor (x) - genType
mod
(genType x, genType y)取模
Modulus. Returns x – y ∗ floor (x/y)
如果要对参数截断到[0.0,1.0], 正确的表达式是factor = mod(factor, 1.0 + EQUAL_THRESHOLD);
测试发现,shader精度为highp时,EQUAL_THRESHOLD为1e-8无效,至少要1e-7
- genType
min
(genType x, genType y)最小值
Returns y if y < x, otherwise it returns x - genType
max
(genType x, genType y)最大值
Returns y if x < y, otherwise it returns x. - genType
clamp
(genType x,genType minVal, genType maxVal)截断
Returns min (max (x, minVal), maxVal) Results are undefined if minVal > maxVal. - genType
mix
(genType x,genType y,genType a)混合(1-alpha)
Returns the linear blend of x and y: x(1-a)+y*a - genType
step
(genType edge, genType x)是阶梯或平地则返回1
Returns 0.0 if x < edge, otherwise it returns 1.0 - genType
smoothstep
(genType edge0,genType edge1,genType x)
顺滑返回0~1的值
Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition. This is equivalent to: genType t; t = clamp ((x – edge0) / (edge1 – edge0), 0, 1); return t * t * (3 – 2 * t); Results are undefined if edge0 >= edge1.