It is important to note that GameMaker also supports some conditional compile Macros which can be used within GLSL ES shaders so they can perform alternative code on specific supported platforms. In general you'd do these checks on game start and store the results as a global variable to then check later. Therefore you are recommended to check that the shader has been compiled before setting uniforms or using the shader itself, like this:Įlse show_debug_message("Shader failed") Īs an extra check you can also call the function shaders_are_supported() to see if the hardware even supports shaders.
One final thing to note is that although shaders are accepted across all platforms, they are still device specific and if the hardware or software of the device cannot use shaders then you will get an error. Shader_set_uniform_f(colour_to_set, 1,0,0 ) ĭraw_sprite(sprite_index,image_index,x+24, y) Shader_set_uniform_f(colour_to_find, 1,1,1 ) Once you have the uniform handles, they can then be set in the shader code for the Draw Event like this: You would first get the uniform handle (which is essentially an ID value for the uniform to be set) using the function shader_get_uniform() in the Create Event of the instance using the shader, and then store these handles in variables, something like this:Ĭolour_to_find = shader_get_uniform(sShaderDemo5, "f_Colour1") Ĭolour_to_set = shader_get_uniform(sShaderDemo5, "f_Colour2") If the shader you are using has input values, these are set using the uniform functions. It is also worth noting that if you are trying to use a colour value in a shader and the object has no texture, the results will turn out black. NOTE: Shaders, like anything related to drawing, can only be used in the draw event.
If you wish to render the full screen through a shader, and not just a single sprite or background, you will need to set up a surface to catch the current view, and then pass that through to the shader (see Surfaces for more information). Using a shader in your projects is very simple, and only requires a couple of lines of code to get the most basic of use from it:Īs you can see, they are used in a similar manner to blend modes and surfaces, where you first select (set) the shader, draw what you want using it, then reset the draw target again afterwards. The following link is also useful as it contains some quick reference cards for the OpenGL ES API (note that only the last two cards shown are applicable to GameMaker): OpenGL ES Reference Cards. NOTE Shaders do not permit you to change the value of any variables that you pass into them, and so these will be called shader constants in all the documentation that refers to them.įor a complete overview of the available GLSL ES functions and variables that you can use to program the shaders themselves, please refer to the OpenGL ES Shading Language (GLSL ES) Reference Pages.
To create a shader you will need to have written both a Vertex Shader and a Fragment Shader (also know as a Pixel Shader) using the Shader Editor, and even if (for example) you only wish to change the vertex positions for an instance being drawn, or if you only want to change the colour values for the pixels, you will still need both programs for a complete shader to work. Since these tiny programs are actually run on the graphics card itself, this means that they are extremely fast to process, freeing up valuable CPU cycles for more game logic.
Shaders are an incredibly powerful tool for manipulating what and how things are rendered to the screen by the graphics card.