常用函數(shù):
genType abs (genType x) ?-----genType代表范型
返回x的絕對(duì)值
genType sign (genType x)
如果x>0进胯,返回1.0懊悯;如果x=0,返回0十办,如果x<0,返回-1.0
genType floor (genType x)
返回小于等于x的最大整數(shù)值
floor(3.2) ->3; ? ?floor(3.8)->3;
genType ceil (genType x)
返回大于等于x的最小整數(shù)值
ceil(3.3)->4; ceil(3.8)->4
genType fract (genType x)
返回x-floor(x),即返回x的小數(shù)部分
genType clamp (genType x, genType minVal, genType maxVal)
genType clamp (genType x, float minVal, float maxVal)
獲取x和minVal之間較大的那個(gè)值,然后再拿較大的那個(gè)值和最后那個(gè)最大的值進(jìn)行比較然后獲取較小的那個(gè)严衬,意思就明白了,clamp實(shí)際上是獲得三個(gè)參數(shù)中大小處在中間的那個(gè)值笆呆。函數(shù)有個(gè)說明:如果minVal > minMax的話请琳,函數(shù)返回的結(jié)果是未定的。也就是說x的值大小沒有限制赠幕,但是minval的值必須比maxVal小俄精。
clamp(0.5,0,1) ->0.5; ? ?clamp(-0.5,0,1) ->0; ? ?clamp(1.5,0,1) ->1
genType mix (genType x, genType y, genType a)
genType mix (genType x, genType y, float a)
返回線性混合的x和y,如:x?(1?a)+y?a
genType step (genType edge, genType x)榕堰,genType step (float edge, genType x)
如果edge>x竖慧,返回0.0,否則返回1.0
smoothstep()逆屡,平滑階梯函數(shù)圾旨,平滑過渡函數(shù)
曲線圖:
對(duì)于y=smooth_step(e0,e1,x)曲線圖為:
注:x小于e0時(shí)為0,x大于e1時(shí)為e1魏蔗,x在e0到e1之間時(shí)線性變化
如下圖:
幾何函數(shù):
length()函數(shù):
返回向量的長(zhǎng)度(到(0,0)的距離)
normalize (genType x):
標(biāo)準(zhǔn)化向量砍的,返回一個(gè)方向和x相同但長(zhǎng)度為1的向量
float distance (genType p0, genType p1):
計(jì)算向量p0,p1之間的距離
float dot (genType x, genType y)
向量x莺治,y之間的點(diǎn)積
vec3 cross (vec3 x, vec3 y)
向量x廓鞠,y之間的叉積
角度和三角函數(shù):
1. radian函數(shù)是將角度轉(zhuǎn)換為弧度帚稠,degrees函數(shù)是將弧度轉(zhuǎn)換為角度
genType有點(diǎn)像面向?qū)ο笾蟹盒停慈绻鹓enType是float型的床佳,那么
genType pow (genType x, genType y)
就變成了:
float pow (float x, float y)
同理滋早,如果genType是int型的,那么就變成了:
int pow (int x, int y)夕土;
2. sin, cos, tan都是標(biāo)準(zhǔn)的三角函數(shù)馆衔。asin, acos, atan是反三角函數(shù)