Vertex shader outputs
Vertex shaders can output generic values to the next stage. Those values are going to be passed to the geometry shading stage first, then rasterized, and finally passed to the fragment shading stage in one of the allowed interpolation fashions. You can choose the kind of interpolation, but we will use in this book a linear perspective-corrected interpolation.
To specify an output variable, you must use the interpolation type along with the out
keyword:
#version 430 #pragma debug(on) #pragma optimize(off) layout (location = 0) in vec4 Position; layout (location = 1) in vec2 TexCoord; uniform mat4 Modelview; uniform mat4 Projection; // smooth = linearly perspective-correct interpolation smooth out vec2 texCoordsInterpolated; void main() { gl_Position = Projection * Modelview * Position; // Write the vertex attribute into an output variable that will be interpolated in a later pipeline's stages texCoordsInterpolated = TexCoord; }