Varyings

You may need to read the article about attributes before this one.


Another way to pass data to the GPU is with varyings, which are variables that vary between vertices. They are outputs from vertex shaders and inputs to fragment shaders, so they are declared using the out and in keywords, respectively.

A varying must be declared in both the vertex shader and the fragment shader. For example:

#version 300 es

in vec4 a_position;
in vec4 a_color;

out vec4 v_color;

void main() {
	gl_Position = a_position;
	v_color = a_position;
}
#version 300 es

precision highp float;

in vec4 v_color;

out vec4 outColor;

void main() {
	outColor = v_color;
}

The value of the varying for a fragment is interpolated between the values passed to that varying from the vertices in the primitive that contains it.


The next article covers transformation.