Brain Dump

Graphics Pipeline

Tags
computer-graphics

The high level [see page 25, Stages] in rendering something. Involves a mapping points through a [see page 2, bunch] of coordinate spaces until we get a 2D projection on the display space.

the entire process vertices have to walk through before ending up as one or more pixels on the screen.

A basic graphics system goes from the CPU, to the Graphics Processor to the Frame Buffer, before finally rendering the result back to the users screen.

Fixed Function Pipeline

  • We build up a state (data about camera, lights etc.) in the OpenGL state machine.
  • Pass in the modelled data (points, lines, polygons)
  • The GPU modifies the model using the state and passes the result to the screen.

The [see page 31, functions] uses in this model are provided by the GPU and interfaced through OpenGL. We have little control over them

[see page 31, Programmable] Pipeline

Differs from the fixed function pipeline by letting us ALSO send program code to the GPU (alongside the data). This program code is run in the GPU and gives us control over how the GPU functions are used to render the data.

Stages in the Pipeline

See example here.

Vertex Shader

Converts points from the local coordinate system to the world coordinate system and then clips out parts of the world which aren't visible.

The vertex shader uses the predefined gl_Position variable (vec4) as the output coordinates that're passed through to the next shader in the graphics pipeline.

#version 330 core
layout (location = 0) in vec3 aPos;

void main() {
    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}

Shape Assembly

The second stage of the graphics pipeline which takes points from the vertex-shader and groups them into a 3D surface that's to be drawn.

This shader specialises in building the boundary for an object that's passed into the graphics pipeline.

Geometry Shader

The third stage in the graphics-pipeline which takes a primitive from the shape-assembly stage and produces zero-or more primitives.

For example it can tessellate a triangle into two triangles.

Rasterisation

A stage in the graphics pipeline which maps primitives to pixels on the final screen. This process produces Fragments for the fragment shader to then color.

Fragment Shader

Calculates the color values for pixel Fragments. It outputs a vec4 (RGBA) variable called FragColor to indicate the color of a pixel.

Usually the fragment shader contains data about the 3D scene that it can use to calculate the final pixel color (like lights, shadows, color of the light and so on).
#version 330 core
out vec4 FragColor;

void main() {
    FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}

Tests & Blending

This stage checks the corresponding depth (and stencil) value (we'll get to those later) of the fragment and uses those to check if the resulting fragment is in front or behind other objects and should be discarded accordingly. The stage also checks for alpha values (alpha values define the opacity of an object) and blends the objects accordingly. So even if a pixel output color is calculated in the fragment shader, the final pixel color could still be something entirely different when rendering multiple triangles.