webgl内置函数--通用函数

第一个通用函数:float abs(float x)
此函数会返回x的无符号绝对值,即如果x大于0则返回x,否则返回-x。
在这里插入图片描述
第二个通用函数:float sign(float x)
此函数又称为符号函数,如果x>0返回1.0,如果x=0返回0.0,否则返回-1.0
在这里插入图片描述
第三个通用函数:float floor(float x)
此函数会返回小于等于x并且最接近x的整数,通俗来说就是像下取整。
在这里插入图片描述
第四个通用函数:float ceil(float x)
此函数会返回大于等于x并且最接近x的整数,通俗来说就是向上取整。
在这里插入图片描述
第五个通用函数:float fract(float x)
此函数会返回x的小数部分,即x-floor(x)。
在这里插入图片描述
第六个通用函数:float mod(float x, float y)
此函数会返回x除以y的余数。
在这里插入图片描述
为什么这个图像和fract函数的图像这个相似呢?因为mod的这个函数图像的第二个参数我写的是1.0
第七个通用函数:float min(float x, float y)
此函数会返回x和y两个值中的最小值。
第八个通用函数:float max(float x, float y)
此函数会返回x和y两个值中的最大值。
第九个通用函数:float clamp(float x, float minVal, float maxVal)
此函数会将x限制在minVal和maxVal之间。
在这里插入图片描述
上面的图像中我将minVal的值调节为0.0,将maxVal的值调节为1.0,那么x的值比0.0小的时候,就会返回0.0,在0.0到1.0之间就会返回x值本身,而大于1.0的时候就会返回1.0。
第十个通用函数:float mix(float x, float y, float a)
此函数会返回x和y的线性混合,即x*(1-a)+ya
下面我们看一下y = mix(0.,1.,x);这个函数的图像。
在这里插入图片描述
第十一个通用函数:float step(float edge, float)
此函数会根据两个数值生成阶梯函数,如果x<edge则返回0.0,否则返回1.0
在这里插入图片描述
第十二个通用函数:float smoothstep(float edge0, float edge1, float x)
如果x<=edge0则返回0.0,如果x>=edge1则返回1.0,否则
t=clamp((x-edge0)/(edge1-edge0), 0, 1)
return t
t(3-2*t)
在这里插入图片描述

发布了59 篇原创文章 · 获赞 22 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/Albert_Ejiestein/article/details/102550806
今日推荐