Graphics

Graphics

OpenGL Graphics Pipeline

Graphics Pipeline

Shaders

Ins and Outs

Vertex Shader

#version 330 core
// position variable has attribute position 0
layout (location = 0) in vec3 aPos;

// specify colour output to fragment shader
out vec4 vertexColor;

void main() {
    gl_Position = vec4(aPos, 1.0);
    vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
}

Fragment Shader

#version 330 core
out vec4 FragColor;

// input variable from the vertex shader
in vec4 vertexColor;

void main() {
    FragColor = vertexColor;
}

Uniforms

Sources

Learn OpenGL

Transformations

Homogeneous coordinates

Scaling

Scaling by $(S_1, S_2, S_3)$ on a vector $(x,y,z)$ can be done with the following matrix:

\[\begin{bmatrix} S_1 & 0 & 0 & 0 \\ 0 & S_2 & 0 & 0 \\ 0 & 0 & S_3 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \\ \end{bmatrix} = \begin{bmatrix} S_1x \\ S_2y \\ S_3z \\ 1 \\ \end{bmatrix}\]

Translation

Rotations

\[\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ 0 & \sin \theta0 & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \\ \end{bmatrix} = \begin{bmatrix} x \\ \cos\theta y - \sin\theta z\\ \sin\theta y + \cos\theta z\\ 1 \\ \end{bmatrix}\]

Edit this page.