Introduction

Shaders are also a set of instructions, but the instructions are executed all at once for every single pixel on the screen. That means the code you write has to behave differently depending on the position of the pixel on the screen.

The program will work as a function that receives a position and returns a color, and when it's compiled it will run extraordinarily fast.

GLSL stands for openGL Shading Language, which is the specific standard of shader programs. There are other types of shaders depending on hardware and Operating Systems.

<aside> 💡 Because GLSL (OpenGL Shading Language) shaders compile and run on a variety of platforms, you will be able to apply what you learn here to any environment that uses OpenGL, OpenGL ES or WebGL.

</aside>

Basic Structure of a GLSL Shader Program

Shaders always begin with a version declaration, followed by a list of input and output variables, uniforms and its main function.

Each shader's entry point is at its main function where we process any input variables and output the results in its output variables.

Generally a shader look like this:

#version version_number

in type in_variable_name;
in type in_variable_name;
out type out_variable_name;

uniform type uniform_name;

void main() {
// process input(s) and do some weird graphics stuff ...// output processed stuff to output variable
	out_variable_name = weird_stuff_we_processed;
}

Input and Output to Shaders

GLSL defined the in and out keywords to have inputs and outputs on the individual shaders.

The vertex and fragment shaders differ a bit sometimes.

Macros

Coordinates of Canvas