vertexShader.vs - Fish-In-A-Suit/Conquest GitHub Wiki

new code:

#version 330

layout (location = 0) in vec3 inVertexPosition;
layout (location = 1) in vec3 inVertexColour;

out vec3 outVertexColour;

uniform mat4 translationMatrix;
uniform mat4 projectionMatrix;

void main()
{
	gl_Position = vec4(inVertexPosition, 1.0) * translationMatrix * projectionMatrix;

    outVertexColour = inVertexColour;
}

Specified version of GLSL to be used is 3.3.

The input locations to the vertex shader are specified via the layout keyword:

layout (location = 0) in vec3 inVertexPosition;
layout (location = 1) in vec3 inVertexColour;

The above specifies that the source for inVertexPosition is the attribute list of the vao at index 0. The source for inVertexColour is the attribute list of the vao at index 1.

The output variable is defined by

out vec3 outVertexColour;

The outVertexColour variable will be sent off to the fragment shader. Note that the input to the fragment shader must matcg with the output of the vertex shader. For this example, the input to the fragment shader would be specified as in vec3 outVertexColour.

As in any program, the most important code is assigned inside the main() method:

void main()
{
    // gl_Position = vec4(inVertexPosition.x, inVertexPosition.y, inVertexPosition.z, 1.0);
    gl_Position = vec4(inVertexPosition, 1.0);
    outVertexColour = inVertexColour;
}

Prior to being assigned to the built-in GLSL variable gl_Position, which holds the on-screen position of a vertex, the input vertex poosition of type vec3 is extended to become a homogoneous vector representing position (vec4).

The input vertex colour of a vertex (inVertexColour) is sent to the fragment shader (outVertexColour) without any modifications - this shader is just a pass-thorugh shader what considers the vertex colour.