Shader Constants

Apart from the shader functions and constants defined in the OpenGL ES Shading Language (GLSL ES) Reference Pages, there are also a number of shader uniforms available to you that are unique to GameMaker.

The following display matrix constants can be used as array indices when using the shader array constant gm_Matrices:

ConstantDescription
MATRIX_VIEWThis array index constant holds the index to the current view matrix. The index returned would be used as an array value when calling the gm_Matrices constant within the shader code.
MATRIX_PROJECTIONThis array index constant holds the index to the current projection matrix. The index returned would be used as an array value when calling the gm_Matrices constant within the shader code.
MATRIX_WORLDThis array index constant holds the index to the current world matrix. This can be used for things like lighting if you have light information in world-space. The index returned would be used as an array value when calling the gm_Matrices constant within the shader code.
MATRIX_WORLD_VIEWThis array index constant holds the index to the result of the world and view matrices multiplied together. This is often used for things like fog. The index returned would be used as an array value when calling the gm_Matrices constant within the shader code.
MATRIX_WORLD_VIEW_PROJECTIONThis array index constant holds the index to the result of the world, view and projection matrices multiplied together. This is the normal transformation matrix used for vertex positions. The index returned would be used as an array value when calling the gm_Matrices constant within the shader code.

 

The following constants are also available:

ConstantDescription
MATRIX_MAXThe size of the matrix array (gm_Matrices) in the vertex shader.
MAX_VS_LIGHTSThe maximum number of point and directional lights available in the shader.

 

The following pre-defined matrix uniforms and constants can be used in your shader to access GameMaker specific values:

ConstantDescription
gm_Matrices[matrix]This array constant returns a transform matrix and is one of the available pre-defined uniforms that GameMaker creates for you to use within the shader code editor. The array index is chosen from one of the above listed constants.
gm_BaseTextureThis is a 2D sampler constant that returns the texture of the current object, as set by GameMaker. So it would be the current sprite, surface or texture that would normally be used when drawing without the shader being called.
gm_LightingEnabledThis can be used to get or set the GameMaker lighting when using 3D.
gm_Lights_Direction[]This is an array of vec4s, each vec4 contains a light's normalised direction vector (X, Y, Z) and a fourth dimension (W) which is 1 when the light is enabled, and 0 when disabled
gm_Lights_PosRange[]This is an array of vec4s, each vec4 contains a light's position (X, Y, Z) and a fourth dimension (W) which is the light's range, which is 0 when that light is disabled
gm_Lights_ColourThis is an array of vec4s, each vec4 contains a light's colour (R, G, B), with the alpha channel (A) always being 1
gm_AmbientColourThis is a vec4 containing the colour of the ambient light as set in draw_light_define_ambient()
gm_FogStartThis can be used to get the distance where polygons start to be blended with the fog colour.
gm_RcpFogRangeThis can be used to get the distance at which fog is maximal and nothing can be seen anymore.
gm_PS_FogEnabledThis will return true or false if the GPU has pixel fog enabled or not.
gm_FogColourThis can be used to get the fog colour used by GameMaker.
gm_VS_FogEnabledThis will return true or false if the GPU has vertex fog enabled or not.
gm_AlphaTestEnabledThis can be used to get alpha testing in the shader. See gpu_set_alphatestenable() for more information on alpha testing.
gm_AlphaRefValueThis can be used to get the current alpha testing reference value. See gpu_set_alphatestref() for more information on the alpha test reference.