Graphics Reference
In-Depth Information
Vector Constructors
GLSL has a number of constructors that let you create new vectors from a mix
of scalars and other vectors. These constructors have the same name as the
vector types and serve to construct a vector of the named type. Some examples
are given in the table below.
vec3(float, float, float) Initializes each component of a vector with the
explicit floats provided.
vec4(ivec4) Makes a vec4 with component-wise conversion.
vec2(float) Initializes a vec2 with the float value in each posi-
tion.
ivec3(int, int, int) Initializes an ivec3 with three ints.
bvec4(int,int,float,float) Performs four Boolean conversions.
vec2(vec3)
Drops the third component of a vec3 .
Drops the fourth component of a vec4 .
vec3(vec4)
vec3(vec2, float)
vec3.xy = vec2
vec3.z = float
vec3(float, vec2)
vec3.x = float
vec3.yz = vec2
vec4(vec3, float)
vec4.xyz = vec3
vec4.w = float
vec4(float, vec3)
vec4.x = float
vec4.yzw = vec3
vec4(vec2a, vec2b)
vec4.xy = vec2a
vec4.zw = vec2b
To initialize a matrix by using specified vectors or scalars, we recall that
matrices are stored in column-major order (unlike in C), so the components are
assigned to the matrix elements in that order.
Each matrix is filled using one column per
argument.
mat2(vec2, vec2)
mat3(vec3, vec3, vec3)
mat4(vec4, vec4, vec4, vec4)
mat3x2(vec2, vec2, vec2)
mat2(float, float, float, float) Rows are first column and second column,
respectively.
Search WWH ::




Custom Search