Writing a vertex shader that multiplies vertex position by a projection matrix
Transforming geometry from local to clip space is usually performed by the vertex shader, though any other vertex processing stage (tessellation or geometry) may accomplish this task. The transformation is done by specifying model, view, and projection matrices and providing them from the application to the shaders as three separate matrices, or as one, joined model-view-projection matrix (in short MVP). The most common and easy way is to use a uniform buffer through which we can provide such a matrix.
How to do it...
- Create a vertex shader in a text file called
shader.vert
(refer to the Writing vertex shaders recipe). - Define an input variable (attribute) through which vertex positions will be provided to the vertex shader:
layout(location = 0) in vec4 app_position;
- Define a uniform buffer with a variable of type
mat4
through which data for the combined model-view-projection matrix will be provided:
layout...