着色器常量

除了 OpenGL ES 着色器语言 (GLSL ES) 参考页面 中定义的着色器函数和常量外,还有许多着色器 uniform 可供您使用,这些着色器 uniform 是 GameMaker 独有的。

使用着色器数组常量GM_矩阵时,可以将以下显示矩阵常量用作数组索引:

常量描述
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.

 

以下常量也可用:

常量描述
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.

 

可以在着色器中使用以下预定义的矩阵统一和常量来访问 GameMaker 特定值:

常量描述
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.