shader_enable_corner_id

This function enables the use of corner IDs in shaders.

It sets a global state for all shaders being used where, when enabled, the shader "steals" 2 bits from the input colour values; one from the lowest bit of the red colour value, and one from the lowest bit of the blue colour value. These values can then be recovered in the shader to work out which vertex you are dealing with (i.e. which corner).

NOTE This will not work when using vertex buffers and primitives as the colour data for each vertex is handled by the user.

The lowest bit of the blue component stores the most significant bit, the lowest bit of the red component stores the least significant bit. You can calculate the corner ID in a vertex shader by doing this:

vec2 rem = mod(in_Colour.rb * 255., 2.);
int corner_id = int(dot(vec2(1., 2.), rem));

The following table lists the possible values and their corresponding corner position: 

Shader Corner ID
Red Lowest BitBlue Lowest BitCorner IDPosition
000Top-left
101Top-right
012Bottom-right
113Bottom-left

NOTE The corner IDs are numbered consecutively going clockwise, starting at 0 for the top-left corner.

 

Syntax:

shader_enable_corner_id(enable);

ArgumentTypeDescription
enableBooleanEnable (true) or disable (false) this function.

 

Returns:

N/A

 

Example:

shader_enable_corner_id(true);

The above code will enable the use of colour bits for the corner ID for all shaders.