vertex_format_add_custom

This function adds a custom data type for specific vertex format attributes 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: 

Vertex Data Type Constant
ConstantDescription
vertex_type_float1A single floating point value
vertex_type_float2Two floating point values
vertex_type_float3Three floating point values
vertex_type_float4Four floating point values
vertex_type_colourFour component values (r, g, b, a)
vertex_type_ubyte4Four component unsigned byte values (from 0 to 255)


The use that these constants will be put to 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 DirectX 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: 

Vertex Usage Type Constant
ConstantDescription
vertex_usage_positionposition values (x, y, z)
vertex_usage_colourcolour values (r, g, b, a)
vertex_usage_normalvertex normal values (nx, ny, nz)
vertex_usage_textcoordUV coordinates (u, v)
vertex_usage_blendweightthe blendweight of the input matrix (for skeletal animation, for example)
vertex_usage_blendindicesthe indices of the matrices to use (for skeletal animation, for example)
vertex_usage_depthvertex depth buffer value
vertex_usage_tangenttangent values
vertex_usage_binormalbinormal values
vertex_usage_fogfog values
vertex_usage_samplesampler index


There are some important things to note when using custom formats like these:

 

attribute vec3 in_Position;
attribute vec4 in_BlendIndices;
attribute vec4 in_BlendWeights;

varying vec4 v_vColour;
varying mat4 v_mat;

void main()
{
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vec4( in_Position.xyz, 1.0);
    v_vColour = in_BlendWeights;
     ivec4 t = ivec4(in_BlendIndices);
     v_mat = gm_Matrices[ t.x ];
}

 

Syntax:

vertex_format_add_custom(type, usage);

ArgumentTypeDescription
typeVertex Data Type ConstantThe data type that this custom vertex data will hold (see the type constants listed above).
usageVertex Usage Type ConstantThe use that the data will get (see the usage constants listed above).

 

Returns:

N/A

 

Example:

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

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