glsl类型
void
Declaration
void main(void);
int aFunction(void);
void bFunction(float);
Declaration
void is used when a function has no parameters or when a function does not return a value.
bool
Declaration
bool aBool = true;
bool bBool = bool(aInt);
bool cBool = bool(aFloat);
Description
bool data type is either true or false
int
Declaration
int aInt = 42;
int bInt = int(aBool);
int cInt = int(aFloat);
Description
int is used for integer values.
float
Declaration
float aFloat = 1.0;
float bFloat = float(aBool);
float cFloat = float(aInt);
Description
float is used for floating point values.
bvec2
Declaration
bvec2 aBvec2 = bvec2(true, true);
bvec2 bBvec2 = bvec2(true);
bvec2 cBvec2 = bvec2(aBvec3);
bvec2 dBvec2 = bvec2(aBvec3.x, aBvec3.y);
Description
bvec2 is a boolean vector with two components. It can be initialized by:
Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.
bvec3
bvec4
ivec2
Declaration
bvec2 aIvec2 = ivec2(1, 1);
bvec2 bIvec2 = ivec2(1);
bvec2 cIvec2 = ivec2(aIvec3);
bvec2 dIvec2 = ivec2(aIvec3.x, aIvec3.y);
Description
ivec2 is an integer vector with two components. It can be initialized by:
Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.
ivec3
ivec4
vec2
Declaration
vec2 aVec2 = vec2(1.0, 1.0);
vec2 bVec2 = vec2(1.0);
vec2 cVec2 = vec2(aVec3);
vec2 dVec2 = vec2(aVec3.x, aVec3.y);
Description
vec2 is a floating point vector with two components. It can be initialized by:
Providing a scalar value for each component.
Providing one scalar value. This value is used for all components.
Providing a vector of higher dimension. The respective values are used to initialize the components.
vec3
vec4
mat2
Declaration
mat2 aMat2 = mat2(1.0, 0.0, // 1. column
0.0, 1.0); // 2. column
mat2 bMat2 = mat2(1.0);
mat2 cMat2 = mat2(aVec2, bVec2);
mat2 dMat2 = mat2(aVec3, aFloat);
Description
mat2 data type is compose for a 2x2 matrix of floating point. As you can see above, can be initialize in different ways:
Providing a value for each component column by column.
Providing one value that is used for the components on the main diagonal.
Providing a combination of vectors and scalars.
In the same way data can be accessed component-wise or column by column:
mat2 aMat2;
aMat2[1][1] = 1.0;
float aFloat = aMat2[1][1];
aMat2[0] = vec2(1.0);
vec2 aVec2 = aMat2[0];
mat3
mat4
sampler2D
samplerCube
struct
Example
struct matStruct {
vec4 ambientColor;
vec4 diffuseColor;
vec4 specularColor;
float specularExponent;
} newMaterial;
newMaterial = matStruct(vec4(0.1, 0.1, 0.1, 1.0),
vec4(1.0, 0.0, 0.0, 1.0),
vec4(0.7, 0.7, 0.7, 1.0),
50.0);
Description
struct declare a custom data structures based on standard types. A constructor for the structure with the same name is created automatically. The declaration of a variable (in this case “newMaterial”) is optional.