Add custom values to the vertex format.


GML Code Example

vertex_format_add_custom(type, usage);

Argument Description
type The data type that this custom vertex data will hold (see the type constants listed below).
usage The use that the data will get(see the usage constants listed below).

Returns: N/A


Tell GameMaker: Studio to accept a custom value (or values) as part of the new vertex format being created. The available values to use are defined by the data type constant that you choose, listed below:

Constant Description
vertex_type_float1 A single floating point value
vertex_type_float2 Two floating point values
vertex_type_float3 Three floating point values
vertex_type_float4 Four floating point values
vertex_type_colour Four component values (r, g, b, a)
vertex_type_ubyte4 Four component unsigned byte values (from 0 to 255)

The use that these constants will be put too also needs to be defined so that the values can be "bound" properly within the shader being created. This is necessary due to the fact that DX and OpenGL have different requirements so if you don't bind them properly, they won't come through right in the shader. The available usage constants that you can choose are listed below and those you use will depend on the specifics of the shader being created:

Constant Description
vertex_usage_position position values (x, y, z)
vertex_usage_colour colour values (r, g, b, a)
vertex_usage_normal vertex normal values (nx, ny, nz)
vertex_usage_textcoord UV coordinates (u, v)
vertex_usage_blendweight the blendweight of the input matrix (for skeletal animation, for example)
vertex_usage_blendindices the indices of the matrices to use (for skeletal animation, for example)
vertex_usage_depth vertex depth buffer value
vertex_usage_tangent tangent values
vertex_usage_binormal binormal values
vertex_usage_fog fog values
vertex_usage_sample sampler index


GML Code Example

 vertex_format_add_custom(vertex_type_float3, vertex_usage_position);
 my_format = vertex_format_end();

The above code will create a new vertex format with just texture and 3 custom floating point values for position. It is then stores the format id in the variable "my_format".

These examples are submitted by the community. Upvote the examples you think are most helpful.

Retrieving Custom Vertex Attributes by /u/babyjeans on June 08, 2017

GML Code

// GML custom vertex format (in .gml)
vertex_format_add_custom(vertex_type_float2, vertex_usage_texcoord); // Note that the usage is texcoord
vertexFormat = vertex_format_end();

// shader.vsh
// vertex shader
attribute vec3 in_Position;       // (x,y,z)
attribute vec4 in_Colour;         // (r,g,b,a)

// When binding more attributes to the same constant, index them from 0:
attribute vec2 in_TextureCoord0; // GML: vertex_add_texcoord();
attribute vec2 in_TextureCoord1; // GML: vertex_format_add_custom(vertex_type_float2, vertex_usage_texcoord); 

varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 v_vAnotherCoord;

void main()
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    v_vColour = in_Colour;
    v_vTexcoord = in_TextureCoord0;
    v_vAnotherCoord = in_TextureCoord1;

Edited On June 08, 2017

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here