OpenGL ES 2.0 / GLSL 1.0
Types
最終更新:
opengles
-
view
A shader can aggregate these using arrays and structures to build more complex types. There are no pointer types.
Basic Types
void | no function return value or empty parameter list |
bool | Boolean |
int | signed integer |
float | floating scalar |
vec2, vec3, vec4 | n-component floating point vector |
bvec2, bvec3, bvec4 | Boolean vector |
ivec2, ivec3, ivec4 | signed integer vector |
mat2, mat3, mat4 | 2x2, 3x3, 4x4 float matrix |
sampler2D | access a 2D texture |
samplerCube | access cube mapped texture |
Structures and Arrays [4.1.8, 4.1.9]
Structures | struct type-name{ members } struct-name[]; // optional variable declarationor an array |
Arrays | float foo[3]; * structures and blocks can be arrays * only 1-dimensional arrays supported * structure members can be arrays |
スカラー、ベクトル、マトリクスの演算サンプル
float f = 1.0;
bool b = true;
int i = 0;
f = float(b); // boolをfloatに変換
f = float(i); // intをfloatに変換
b = bool(i); // floatをboolに変換
vec4 v4 = vec4(1.0); // v4 = {1.0, 1.0, 1.0, 1.0};
vec3 v3 = vec3(1.0, 0.0, 0.5); // v3 = {1.0, 0.0, 0.5};
vec3 tmp = vec3(v3); // tmp = v3;
vec2 v2 = vec2(v3); // v2 = {v2.x, v2.y};
v4 = vec4(v2, tmp, 0.0); // v4 = {v2.x, v2.y, tmp.x, 0.0};
mat3 m3 = mat3(1.0, 0.0, 0.0, // 最初の列
0.0, 1.0, 0.0, // 2番目の列
0.0, 0.0, 1.0); // 3番目の列
ベクトル成分の入れ替えサンプル
vec3 v3 = vec3(0.0, 1.0, 2.0);
vec3 tmp;
tmp = v3.xyz; // tmp = {0.0, 1.0, 2.0};
tmp = v3.xxx; // tmp = {0.0, 0.0, 0.0};
tmp = v3.zyx; // tmp = {2.0, 1.0, 0.0};
行列アクセスのサンプル
mat4 m4 = mat4(1.0); // 対角要素を1.0(単位行列)に初期化
vec4 col0 = m4[0]; // 行列からベクトルを取得
float m1_1 = m4[1][1]; // 行列の1行1列の要素を取得
float m2_2 = m4[2][2]; // 行列の2行2列の要素を取得