openGLES矩陣操作 向量點積等函式

2021-09-11 03:46:20 字數 3652 閱讀 5075

opengles著色語言內建函式

1  角度和三角函式

標識為angle的函式引數假定以弧度為單位。這些函式不可能出現被0除的情況,如果被除數為0,結果是未定義的。

radian函式是將角度轉換為弧度,degrees函式是將弧度轉換為角度。sin, cos, tan都是標準的三角函式。asin, acos, atan是反三角函式。gentype有點像物件導向中泛型,即如果gentype是float型的,那麼

gentype pow (gentype x, gentype y)

就變成了:

float pow (float x, float y)

同理,如果gentype是int型的,那麼就變成了:

int pow (int x, int y);

2  指數函式

(1)gentype pow (gentype x, gentype y)

x的y次方。如果x小於0,結果是未定義的。同樣,如果x=0並且y<=0,結果也是未定義的。使用時應特別注意。

(2)gentype exp (gentype x)

e的x次方

(3)gentype log (gentype x)

計算滿足x等於e的y次方的y的值。如果x的值小於0,結果是未定義的。

(4)gentype exp2 (gentype x)

計算2的x次方

(5)gentype log2 (gentype x)

計算滿足x等於2的y次方的y的值。如果x的值小於0,結果是未定義的。

(6)gentype sqrt (gentype x)

計算x的開方。如果x小於0,結果是未定義的。

(7)gentype inversesqrt (gentype x)

計算x的開方之一的值,如果x小於等於0,結果是未定義的。

3  常用函式

(1)gentype abs (gentype x)

返回x的絕對值

(2)gentype sign (gentype x)

如果x>0,返回1.0;如果x=0,返回0,如果x<0,返回-1.0

(3)gentype floor (gentype x)

返回小於等於x的最大整數值

(4)gentype ceil (gentype x)

返回大於等於x的最小整數值

(5)gentype fract (gentype x)

返回x-floor(x),即返回x的小數部分

(6)gentype mod (gentype x, float y)、gentype mod (gentype x, gentype y)

返回x – y * floor (x/y),即求模計算%

(7)gentype min (gentype x, gentype y),gentype min (gentype x, float y)

返回x和y的值較小的那個值。

(8)gentype max (gentype x, gentype y),gentype max (gentype x, float y)

返回x和y的值較大的那個值。

(9)gentype clamp (gentype x, gentype minval, gentype maxval)、gentype clamp (gentype x, float minval, float maxval)

clamp翻譯為夾具,就叫夾具函式吧,這個函式是什麼意思呢?看看解釋的意思是:獲取x和minval之間較大的那個值,然後再拿較大的那個值和最後那個最大的值進行比較然後獲取較小的那個,意思就明白了,clamp實際上是獲得三個引數中大小處在中間的那個值。函式有個說明:如果minval > minmax的話,函式返回的結果是未定的。也就是說x的值大小沒有限制,但是minval的值必須比maxval小。

(10)gentype mix (gentype x, gentype y, gentype a)、gentype mix (gentype x, gentype y, float a)

返回線性混合的x和y,如:x⋅(1−a)+y⋅a

(11)gentype step (gentype edge, gentype x),gentype step (float edge, gentype x)

如果x < edge,返回0.0,否則返回1.0

(12)gentype smoothstep (gentype edge0,gentype edge1,gentype x),gentype smoothstep (float edge0,float edge1,gentype x)

如果x <= edge0,返回0.0 ;如果x >= edge1 返回1.0;如果edge0 < x < edge1,則執行0~1之間的平滑埃爾公尺特差值。如果edge0 >= edge1,結果是未定義的。

4  幾何函式

(1)float length (gentype x)

返回向量x的長度

(2)float distance (gentype p0, gentype p1)

計算向量p0,p1之間的距離

(3)float dot (gentype x, gentype y)

向量x,y之間的點積

(4)vec3 cross (vec3 x, vec3 y)

向量x,y之間的叉積

(5)gentype normalize (gentype x)

標準化向量,返回乙個方向和x相同但長度為1的向量

(6)gentype faceforward(gentype n, gentype i, gentype nref)

如果nref和i的點積小於0,返回n;否則,返回-n;

(7)gentype reflect (gentype i, gentype n)

返回反射向量

(8)gentype refract(gentype i, gentype n,float eta)

返回折射向量

5  矩陣函式

(1)mat matrixcompmult (mat x, mat y)

矩陣x乘以y,result[i][j]是 x[i][j] 和 y[i][j] 的標量積。注意,要獲取線性代數矩陣的乘法,使用乘法操作符*。

6  向量相關函式

相關或相等的操作符(<, <=, >, >=, ==, !=)被定義(或保留),返回乙個標量布林值。下面, 「bvec」 是表示bvec2, bvec3, or bvec4的佔位符, 「ivec」是ivec2, ivec3, or ivec4的佔位符,  「vec」 是vec2, vec3, or vec4的佔位符. 在任何情況下,輸入和返回值向量的長度必須匹配。

(1)lessthan

比較x < y.

(2)lessthanequal

比較x<=y

(3)greaterthan

比較x>y

(4)greaterthanequal

比較x>=y

(5)equal

比較x==y

(6)notequal

比較x!=y

(7)bool any(bvec x)

如果向量x的任何元件為true,則結果返回true。

(8)bool all(bvec x)

如果向量x的所有元件均為true,則結果返回true。

(9)bvec not(bvec x)

返回向量x的互補矩陣

**:

Matlab向量 矩陣基本操作

1 向量的建立 1 直接輸入 行向量 a 1,2,3,4,5 列向量 a 1 2 3 4 5 2 用 生成向量 a j k 生成的行向量是a j,j 1,k a j d k 生成行向量a j,j d,j m d m fix k j d 3 函式linspace 用來生成資料按等差形式排列的行向量 x...

MKL學習 矩陣向量操作

前面介紹的blas level 1是向量 向量的操作,而這裡的blas level 2主要還是對矩陣 向量之間的操作。命名規則與前面的一樣,主要記住定義的是資料型別 s實數域,單精度 c複數域,單精度 d實數域,雙精度 z複數域,雙精度 也可結合起來,比如sc代表實數域和複數域的單精度型別,dz代表...

Matlab R向量與矩陣操作

matlab r向量與矩陣操作 描述 matlab r 1建立行向量v 1 2 3 4 v 1 2 3 4 v c 1,2,3,4 或v scan 然後輸入1 2 3 4,並按enter 2建立列向量v 1 2 3 4 v 1 2 3 4 同上,r中不區分行列 3建立矩陣a 1 4 2 5 3 6 ...