Data Types

  • WayVes utilises OpenGL - driven Shaders to draw high - quality Visuals.
  • OpenGL uses GLSL (OpenGL Shading Language), which is a C - typed Language.
  • Aside from most of the basic data types from C, there are some additional data types that GLSL supports.

The following sections are taken from the official OpenGL Khronos Wiki


Scalars Fundamental Data Types
PropertyDescription
boolSpecifies whether the value is True or False.
intSpecifies an integer number. 32-bit.
uintAn unsigned 32-bit integer
floatSpecifies a floating-point number with decimal places; single-precision
double(OpenGL 4.0 and above) Double-precision; can store more decimal places

Vectors Each of the scalar types, including booleans, have 2, 3, and 4-component vector equivalents
PropertyDescription
bvec2A vector of 2 booleans
bvec3A vector of 3 booleans
bvec4A vector of 4 booleans
vec2A vector of 2 single-precision floating-point numbers
vec3A vector of 3 single-precision floating-point numbers
vec4A vector of 4 single-precision floating-point numbers

Swizzling

You can access the components of vectors using the following syntax:


vec4 someVec;
float value = someVec.x + someVec.y;

This is called swizzling. You can use x, y, z, or w, referring to the first, second, third, and fourth components, respectively.


vec2 uv = vec2(1);                           // Same as vec2(1, 1);

You can also combine smaller vecn variables in the initialisation of a larger one.


vec4 Color = vec4(uv, 0, 1);             // x and y components of Color are the same as the x and y components of uv.

Or you can Swizzle the components to switch the ordering of the inner vector to the desired order.


Color = vec4(uv.yx, uv.xy);              // Color = vec4(uv.y, uv.x, uv.x, uv.y);

Matrices Collection of Vectors
  • In addition to vectors, there are also matrix types.
  • All matrix types are floating-point, either single-precision or double-precision.
  • Matrix types are as follows, where n and m can be the numbers 2, 3, or 4:
PropertyDescription
matnxmA matrix with n columns and m rows (examples: mat2x2, mat4x3). Note that this is backward from convention in mathematics!
matnCommon shorthand for matnxn: a square matrix with n columns and n rows.
dmat(GL 4.0 and above) Double-precision matrices.

Swizzling does not work with matrices. You can instead access a matrix's fields with array syntax:


mat3 theMatrix;
theMatrix[1] = vec3(3.0, 3.0, 3.0);             // Sets the second column to all 3.0s
theMatrix[2][0] = 16.0;                               // Sets the first entry of the third column to 16.0.

However, the result of the first array accessor is a vector, so you can swizzle that:


mat3 theMatrix;
theMatrix[1].yzx = vec3(3.0, 1.0, 2.0);

Explicit Type Conversion

To cast a data type to another, use datatype_to_cast_to(variable)


int a = 2;
float b = float(a) / 3;             // a is treated as a float before the division