1. Home
  2. Explore
  3. Computer Science
  4. Video Game Graphics Pipeline

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Video Game Graphics Pipeline

Video Game Graphics Rendering Pipeline

Modern video-game graphics transform enormous amounts of numerical data into realistic three-dimensional scenes. A detailed environment may contain millions of vertices, triangles, colors, textures, and lights, yet all of these are represented digitally as binary data and processed by the computer’s graphics processing unit (GPU).

The core rendering pipeline has three fundamental stages:

  1. Vertex shading

  2. Rasterization

  3. Fragment shading

These stages have formed the foundation of real-time graphics for decades. Modern games add additional techniques, but nearly every rendered frame still depends on this basic process.


1. Scene Representation: Vertices, Triangles, Materials, and Lights

A three-dimensional game scene is constructed from geometric models called meshes. A mesh is made from:

  • Vertices: points with numerical coordinates in three-dimensional space.

  • Edges: connections between vertices.

  • Triangles: three vertices joined together to form a flat surface.

  • Materials and textures: colors and surface properties assigned to parts of a model.

  • Lights: virtual sources that illuminate objects in the scene.

Even objects that appear rounded or smoothly curved are generally approximated using many small flat triangles. Increasing the number of triangles allows a model to represent more complex shapes and finer details.

For example, a locomotive may appear to have smooth, rounded metal surfaces, but it can actually be assembled from hundreds of thousands of flat triangles. The triangles are small enough, and numerous enough, that the complete model appears curved when displayed.

A complex scene can contain:

  • Millions of vertices

  • Millions of triangles

  • Hundreds or thousands of models

  • Numerous colors and textures

  • One or more virtual light sources

The GPU is specially designed to process these large collections of geometric data in parallel.

Key idea: A three-dimensional game scene is ultimately represented as numerical coordinates, triangle connections, material data, texture data, and lighting information.


2. Overview of the Rendering Pipeline

The rendering pipeline converts a three-dimensional scene into a two-dimensional image displayed on a monitor.

The three core stages

2.1 Vertex shading

Vertex shading transforms each vertex from its original three-dimensional position into a position on the camera’s two-dimensional view screen.

2.2 Rasterization

Rasterization determines which screen pixels are covered by each transformed triangle. It converts geometric triangles into pixel groups called fragments.

2.3 Fragment shading

Fragment shading calculates the final color of each fragment by considering lighting, material properties, shadows, reflections, and other surface effects.

The pipeline must be repeated for every frame because the following may change continuously:

  • The camera’s position and direction

  • The player’s movement

  • The positions of objects

  • The positions of lights

  • Object rotations and animations

  • Shadows and reflections

At 120 frames per second, a new frame is produced approximately every:

1120 seconds≈8.3 milliseconds\frac{1}{120}\text{ seconds} \approx 8.3\text{ milliseconds}1201​ seconds≈8.3 milliseconds

Thus, the GPU must perform the rendering calculations repeatedly at extremely high speed.


Vertex Shading

3. Purpose of Vertex Shading

Vertex shading is the first core stage of the rendering pipeline. Its purpose is to determine where each three-dimensional vertex appears on the two-dimensional screen.

A game world may contain many more objects than the player can currently see. The camera’s field of view determines which portion of the world is visible. Objects outside the camera’s view may be discarded or ignored, reducing the number of objects that need to be processed.

For instance, a scene may contain 1,100 models, but the camera may only see approximately 600 of them. Rendering only the visible portion of the world improves performance.

The vertex shader processes vertices individually. Although a complete train may move as a single object conceptually, the GPU transforms every vertex that makes up the train.


4. Coordinate Spaces and Transformations

A vertex passes through several coordinate systems before it becomes a position on the screen.

4.1 Model space

Model space is the local coordinate system of an individual object. The coordinates describe the object relative to its own origin.

For example, a locomotive’s vertices may be defined relative to the center or base of the locomotive. At this stage, the model does not yet have a final position in the game world.

4.2 World space

World space describes the position of an object within the complete game environment.

The model is moved, scaled, and rotated according to its placement in the world. The transformation depends on:

  • The object’s position

  • The object’s scale

  • The object’s rotation

These properties are combined into a model transformation.

4.3 Camera space

Camera space, also called view space, describes the world relative to the camera.

The transformation depends on:

  • The camera’s position

  • The camera’s orientation

  • The camera’s rotation

An object that is stationary in world space may appear to move on the screen when the camera moves.

4.4 Screen or projection space

The final transformation applies the camera’s perspective field of view. This converts the three-dimensional camera-space position into a position on the two-dimensional screen.

The resulting coordinates include:

  • An XXX coordinate for horizontal screen position

  • A YYY coordinate for vertical screen position

  • A ZZZ coordinate representing depth

The depth value is important because it is later used to decide which surfaces are visible when objects overlap.


5. Transformation Matrices

The transformations between coordinate spaces are performed using transformation matrices.

A vertex’s original coordinates are combined with matrices representing:

  • The model’s position, scale, and rotation

  • The camera’s position and rotation

  • The camera’s perspective projection and field of view

Conceptually, the complete transformation can be expressed as:

vscreen=PVMvmodel\mathbf{v}_{screen} = \mathbf{P}\mathbf{V}\mathbf{M}\mathbf{v}_{model}vscreen​=PVMvmodel​

where:

  • vmodel\mathbf{v}_{model}vmodel​ is the vertex in model space

  • M\mathbf{M}M is the model-to-world transformation

  • V\mathbf{V}V is the world-to-camera transformation

  • P\mathbf{P}P is the projection transformation

  • vscreen\mathbf{v}_{screen}vscreen​ is the transformed screen-space position

The exact mathematical implementation may use homogeneous coordinates and a perspective division, but the central purpose is to convert a point from a model’s local three-dimensional coordinates into screen coordinates and depth.

After three vertices have been transformed, the GPU knows where one triangle lies on the view screen. It repeats this process for every vertex in every visible model.

Vertex shading transforms each 3D vertex into a screen position while preserving depth information for later visibility calculations.


6. GPU Parallelism

A complex game scene may require millions of vertex transformations. GPUs are designed to perform this type of work efficiently because many vertices can be processed independently and simultaneously.

A modern GPU may contain thousands of computational cores. These cores execute large numbers of multiplication and addition operations in parallel. This makes it possible to transform millions of vertices and triangles within a few milliseconds.

The GPU’s parallel structure is especially effective because:

  • Each vertex can often be transformed independently.

  • Similar mathematical operations are applied to many vertices.

  • Different cores can process different vertices at the same time.

  • The same pipeline can be reused for every frame.

This parallel processing allows a GPU to render complex scenes at high frame rates, sometimes exceeding 120 frames per second.


Rasterization

7. Purpose of Rasterization

After vertex shading, all visible triangles have been placed on a two-dimensional screen plane. The next question is:

Which exact pixels on the display are covered by each triangle?

Rasterization answers this question. It converts each projected triangle into a collection of screen-space pixel locations known as fragments.

A fragment is a group of pixel data generated from a particular triangle. The fragment retains information that can later be used to determine the pixel’s final color.


8. Mapping Triangles to Pixels

A display is a grid of discrete pixels. A 4K display has a resolution of:

3840×21603840 \times 21603840×2160

This produces approximately:

3840×2160=8,294,4003840 \times 2160 = 8{,}294{,}4003840×2160=8,294,400

or about 8.3 million pixels.

The GPU uses the projected XXX and YYY coordinates of a triangle’s three vertices to determine which locations in this pixel grid lie inside the triangle.

For each triangle, rasterization determines:

  • The triangle’s screen-space boundaries

  • Which pixels fall inside the triangle

  • The depth associated with each covered pixel

  • Interpolated values such as texture coordinates, colors, and normals

The process is repeated for every triangle in the scene.

If a scene contains 3.5 million triangles, the GPU must determine how those triangles map to the display’s pixel grid and how they overlap.


9. Fragments and Color Assignment

Once rasterization identifies the pixels covered by a triangle, the GPU can associate those pixels with the triangle’s material or texture.

At the simplest level, each triangle may have a color represented by red, green, and blue values:

  • Red

  • Green

  • Blue

These color components are combined to produce the final displayed color for each pixel.

The resulting image is stored in a frame buffer, which contains the pixel colors for the complete frame. The frame buffer is then sent to the display.

Rasterization therefore performs the transition:

3D triangles→2D fragments→screen pixels\text{3D triangles} \rightarrow \text{2D fragments} \rightarrow \text{screen pixels}3D triangles→2D fragments→screen pixels

However, rasterization alone does not determine which overlapping triangle should actually be visible. That requires a depth or visibility test.


Visibility and the Z-Buffer

10. The Visibility Problem

Multiple triangles may cover the same screen pixel. Some triangles are closer to the camera, while others are farther away.

For example:

  • A train may block part of a station behind it.

  • The back side of a train may be processed even though it cannot be seen.

  • Several objects may overlap at the same screen position.

  • Triangles may intersect one another.

The GPU must determine which triangle is in front at every pixel. This is called the visibility problem.


11. Depth Buffer Operation

A Z-buffer, also called a depth buffer, stores a depth value for every screen pixel in addition to its color.

For a 4K image, the depth buffer contains approximately 8.3 million depth entries, one for each pixel.

When a triangle is rasterized:

  1. The triangle covers a set of pixels.

  2. The GPU calculates a depth value for each covered pixel.

  3. Each calculated depth is compared with the value currently stored in the Z-buffer.

  4. If the new triangle is closer to the camera, its color replaces the existing pixel color.

  5. The corresponding Z-buffer value is also replaced.

  6. If the new triangle is farther away, it is discarded for that pixel.

Using a convention in which smaller depth values mean closer objects:

  • Lower ZZZ value: closer to the camera and visible

  • Higher ZZZ value: farther from the camera and hidden

The depth-buffer test can be summarized as:

Replace existing pixel if Znew<Zstored\text{Replace existing pixel if } Z_{\text{new}} < Z_{\text{stored}}Replace existing pixel if Znew​<Zstored​

Only the closest triangle remains visible at each pixel.


12. Per-Pixel Depth Interpolation

The three vertices of a triangle do not necessarily have the same depth. One vertex may be closer to the camera than another.

Therefore, the GPU must calculate an appropriate depth for every pixel inside the triangle. The depth varies smoothly across the triangle according to the depths of its vertices.

This per-pixel depth calculation allows the GPU to correctly render:

  • Sloped surfaces

  • Intersecting triangles

  • Partial occlusion

  • Objects with different distances from the camera

A visualization of a depth buffer commonly represents:

  • Black as close to the camera

  • White as far from the camera

The depth image does not show surface color. It displays only the relative distance of visible surfaces from the camera.


Anti-Aliasing

13. Jagged Edges from Pixel Sampling

A display contains discrete square pixels, but the boundaries of triangles can pass through them at arbitrary angles.

If a triangle passes through the center of a pixel, a simple rasterizer may classify the entire pixel as belonging to the triangle. This creates a sharp staircase pattern along diagonal or curved edges, known as aliasing or jagged pixelation.

The problem occurs because a single pixel cannot perfectly represent a boundary that passes through only part of its area.


14. Super Sampling Anti-Aliasing

Super Sampling Anti-Aliasing, or SSAA, reduces jagged edges by testing multiple sample points within each pixel.

For example, the GPU may use 16 sampling points distributed across a pixel:

  1. The GPU checks which of the 16 points are covered by the triangle.

  2. It determines the fraction of the pixel covered.

  3. It uses that fraction to blend the triangle’s color with the surrounding image.

  4. The resulting pixel has a partially shaded edge instead of an abrupt boundary.

If the triangle covers approximately half of the sample points, the pixel receives an intermediate shade. This produces a faded transition along the edge and makes the boundary appear smoother.

SSAA improves image quality but increases computational cost because the GPU performs multiple coverage tests for each pixel.

Anti-aliasing approximates partial pixel coverage so that geometric edges appear smoother and less jagged.


Fragment Shading

15. Purpose of Fragment Shading

Rasterization determines which pixels belong to each triangle, but simply assigning a flat material color would produce an unrealistic image.

Realistic rendering must account for:

  • The direction of incoming light

  • The intensity of the light

  • The direction the surface faces

  • The camera’s position

  • Surface reflections

  • Specular highlights

  • Shadows

  • Ambient illumination

  • Multiple light sources

  • Material properties

Fragment shading calculates the final appearance of each fragment using these factors.

A black metal train, for example, would look flat and inaccurate if every pixel were assigned the same black color. Fragment shading can make:

  • Upper surfaces brighter

  • Lower surfaces darker

  • Metal surfaces shinier

  • Surfaces facing away from the light dimmer

  • Shadows appear where objects block illumination

As the virtual sun moves, the lighting on the train changes, creating the appearance of time passing. At night, ambient illumination decreases and objects may instead be lit by local sources such as fire or lamps.


16. Light Direction and Surface Direction

The basic lighting calculation depends on two directions:

  1. The direction from the surface toward the light

  2. The direction the surface itself faces

The direction a triangle faces is represented by its surface normal.

A surface normal is a vector perpendicular to the plane of the surface. It can be imagined as a flagpole sticking straight out from the center of a flat triangle.

The angle between the light direction and the surface normal determines how directly the surface receives light.

  • A surface facing directly toward the light receives maximum direct illumination.

  • A surface perpendicular to the light receives little or no direct illumination.

  • A surface facing away from the light receives no useful direct illumination.


17. Diffuse Lighting and the Cosine Relationship

The brightness of a surface is related to the cosine of the angle θ\thetaθ between the light direction and the surface normal.

The cosine behaves as follows:

  • cos⁡(θ)=1\cos(\theta)=1cos(θ)=1 when the directions are aligned.

  • cos⁡(θ)=0\cos(\theta)=0cos(θ)=0 when the surface is perpendicular to the light.

  • cos⁡(θ)<0\cos(\theta)<0cos(θ)<0 when the surface faces away from the light.

A simplified direct-lighting calculation can be expressed as:

Idirect=max⁡(0,cos⁡θ) Ilight CsurfaceI_{\text{direct}} = \max(0,\cos\theta)\,I_{\text{light}}\,C_{\text{surface}}Idirect​=max(0,cosθ)Ilight​Csurface​

where:

  • IlightI_{\text{light}}Ilight​ is the light intensity

  • CsurfaceC_{\text{surface}}Csurface​ is the material’s base color

  • max⁡(0,cos⁡θ)\max(0,\cos\theta)max(0,cosθ) prevents negative illumination

In vector form, the cosine can be computed using a normalized dot product:

cos⁡θ=L⋅N∥L∥∥N∥\cos\theta = \frac{\mathbf{L}\cdot\mathbf{N}} {\|\mathbf{L}\|\|\mathbf{N}\|}cosθ=∥L∥∥N∥L⋅N​

where:

  • L\mathbf{L}L is the light-direction vector

  • N\mathbf{N}N is the surface-normal vector

  • L⋅N\mathbf{L}\cdot\mathbf{N}L⋅N is the dot product

  • ∥L∥\|\mathbf{L}\|∥L∥ and ∥N∥\|\mathbf{N}\|∥N∥ are the vector magnitudes

This calculation causes different triangles to receive different brightness values depending on their orientations.


18. Ambient Illumination

Using only direct lighting would make surfaces facing away from a light source completely black. Real environments contain reflected and scattered light, so surfaces usually retain some visible illumination.

To approximate this, rendering systems add ambient light:

Itotal=max⁡(0,cos⁡θ) Ilight Csurface+Iambient CsurfaceI_{\text{total}} = \max(0,\cos\theta)\,I_{\text{light}}\,C_{\text{surface}} + I_{\text{ambient}}\,C_{\text{surface}}Itotal​=max(0,cosθ)Ilight​Csurface​+Iambient​Csurface​

Ambient illumination:

  • Prevents surfaces from becoming unrealistically black

  • Can be stronger in daytime scenes

  • Can be reduced at night

  • Represents indirect environmental light in a simplified way

The ambient component is not necessarily produced by a specific visible lamp or sun. It is an approximation of general background illumination.


19. Multiple Light Sources

When a scene contains several lights, the lighting contribution from each light can be calculated separately and then added together:

Itotal=Iambient+∑i=1nIiI_{\text{total}} = I_{\text{ambient}} + \sum_{i=1}^{n} I_iItotal​=Iambient​+∑i=1n​Ii​

Each light may have its own:

  • Direction

  • Intensity

  • Color

  • Range of influence

Multiple lights increase realism but also increase computational workload. To maintain real-time performance, games may:

  • Limit the number of lights in a scene

  • Limit the distance over which a light affects objects

  • Ignore distant lights for a particular triangle or fragment

  • Use simplified lighting models


Flat Shading and Smooth Shading

20. Flat Shading

In flat shading, each triangle has one surface normal. The entire triangle therefore receives a single lighting calculation and a uniform shade.

Flat shading is computationally simple, but it can make curved objects look faceted. A curved surface made from many triangles may visibly appear as a collection of flat panels.

This occurs because neighboring triangles can have noticeably different orientations, causing abrupt color changes at their shared edges.


21. Vertex Normals

To make curved surfaces appear smoother, rendering systems assign a normal to each vertex rather than using only one normal for each triangle.

A vertex normal is commonly calculated by averaging the normals of the triangles adjacent to that vertex.

If a vertex belongs to several triangles, its normal represents an averaged surface direction. Neighboring triangles then share related normal values, producing smoother transitions in lighting.

This does not change the underlying triangle geometry. Instead, it changes how lighting is calculated across the geometry.


22. Barycentric Interpolation

The GPU uses barycentric coordinates to interpolate vertex normals across the interior of a triangle.

Each point inside a triangle can be described as a weighted combination of its three vertices. If the triangle’s vertices are labeled AAA, BBB, and CCC, a point PPP may be represented as:

P=αA+βB+γCP = \alpha A+\beta B+\gamma CP=αA+βB+γC

with:

α+β+γ=1\alpha+\beta+\gamma=1α+β+γ=1

The same type of weighting can be applied to the three vertex normals:

NP=αNA+βNB+γNC\mathbf{N}_P = \alpha\mathbf{N}_A + \beta\mathbf{N}_B + \gamma\mathbf{N}_CNP​=αNA​+βNB​+γNC​

The resulting normal is then used for the lighting calculation at that fragment.

Conceptually, barycentric interpolation is similar to mixing three colors across a triangle. Instead of mixing colors, the renderer mixes three normal directions.


23. Smooth Shading on Curved Objects

When many triangles form a curved surface:

  1. Each vertex receives an averaged normal.

  2. The normals are interpolated across each triangle.

  3. Each fragment receives a slightly different normal.

  4. The angle between the surface normal and the light changes gradually.

  5. The resulting brightness also changes gradually.

This creates a continuous lighting gradient across the surface, making the object appear smooth even though its geometry is still made from flat triangles.

Smooth shading changes the lighting normals across a mesh; it does not eliminate the underlying triangular geometry.


Advanced Rendering Techniques

The three core stages explain the fundamental rasterization-based pipeline, but modern games use additional technologies to improve lighting, reflections, performance, and image quality.


24. Ray Tracing

Ray tracing calculates how simulated rays of light travel through a scene. It can produce highly accurate:

  • Shadows

  • Reflections

  • Indirect lighting

  • Light transport effects

Ray tracing has traditionally been expensive. In film and television production, rendering one highly detailed frame may take many minutes or longer.

Real-time games generally use rasterization for the primary visibility and shading of objects because it is faster. Ray tracing may be added selectively for specific effects, such as:

  • More accurate shadows

  • Reflections in reflective surfaces

  • Improved global illumination

  • More realistic light interactions

Thus, ray tracing often supplements the rasterization pipeline rather than replacing it entirely.


25. Deep Learning Super Sampling

Deep Learning Super Sampling, or DLSS, is an image-upscaling technique.

Instead of rendering the entire scene directly at a high resolution such as 4K, the GPU can:

  1. Render the scene at a lower resolution.

  2. Use a convolutional neural network to reconstruct a higher-resolution image.

  3. Output an image that approximates a native 4K frame.

The lower-resolution rendering requires less work from the primary graphics pipeline. DLSS then uses learned patterns and image information to add detail and produce a sharper output.

DLSS is therefore generally applied after the pipeline has generated a lower-resolution frame. It improves performance by trading some direct rendering work for neural-network-based reconstruction.


26. Specialized GPU Hardware

Modern GPUs may contain separate computational resources for different workloads.

Shading or CUDA cores

These execute the conventional graphics workload, including:

  • Vertex processing

  • Rasterization-related calculations

  • Fragment shading

  • General parallel computation

Ray-tracing cores

These are specialized for accelerating ray-tracing operations, including calculations involving rays and geometric intersections.

Tensor cores

These are specialized for matrix and neural-network operations. DLSS can use tensor cores to execute the deep-learning computations needed for image upscaling.

When a game uses rasterization, ray tracing, and DLSS together, these different hardware resources can operate concurrently. This allows the GPU to render advanced effects and upscale the image efficiently.

Without these specialized resources, relying only on general-purpose shading cores would require substantially more time per frame.


27. Other Advanced Graphics Topics

Additional rendering techniques build on the core pipeline, including:

  • Shadows: determining where light is blocked by objects

  • Reflections: representing light reflected from surfaces

  • UV mapping: assigning two-dimensional texture coordinates to three-dimensional surfaces

  • Normal mapping: creating the visual appearance of fine surface detail by modifying normals without adding large numbers of triangles

  • Material shading: modeling properties such as metalness, roughness, transparency, and reflectivity

These techniques add realism while attempting to remain within the limited time available for rendering each frame.


Mathematical Foundations

28. Vectors

Vectors represent quantities with direction and magnitude. They are used throughout the rendering process to describe:

  • Vertex positions

  • Camera directions

  • Light directions

  • Surface normals

  • Object movement

  • Object orientation

The light direction and surface normal are especially important in fragment shading because their relationship determines the intensity of direct illumination.


29. Dot Products

The dot product measures how closely two vectors point in the same direction. For vectors a\mathbf{a}a and b\mathbf{b}b:

a⋅b=∥a∥∥b∥cos⁡θ\mathbf{a}\cdot\mathbf{b} = \|\mathbf{a}\|\|\mathbf{b}\|\cos\thetaa⋅b=∥a∥∥b∥cosθ

When both vectors are normalized, their dot product directly gives cos⁡θ\cos\thetacosθ:

a^⋅b^=cos⁡θ\mathbf{\hat{a}}\cdot\mathbf{\hat{b}} = \cos\thetaa^⋅b^=cosθ

This makes the dot product a fundamental operation for calculating diffuse lighting.


30. Matrices and Coordinate Transformations

Matrices provide a compact way to represent and combine transformations such as:

  • Translation

  • Scaling

  • Rotation

  • Camera transformations

  • Perspective projection

By multiplying matrices together, the GPU can combine several transformations into one operation. This is essential because every visible vertex may need to pass through multiple coordinate systems before being rasterized.

Linear algebra and matrix operations are therefore central to real-time graphics.


Complete Frame-Rendering Sequence

A simplified frame-rendering process can be summarized as follows:

  1. Scene selection

    • The game determines which objects and lights are relevant to the camera.

  2. Vertex shading

    • Each object-space vertex is transformed into world space.

    • World-space vertices are transformed into camera space.

    • Camera-space vertices are projected onto the screen.

    • Screen-space XXX, YYY, and depth ZZZ values are produced.

  3. Triangle formation

    • Groups of three transformed vertices define projected triangles.

  4. Rasterization

    • The GPU determines which pixels each triangle covers.

    • Covered regions become fragments.

    • Attributes such as colors, texture coordinates, depth, and normals are interpolated.

  5. Depth testing

    • Each fragment’s depth is compared with the Z-buffer.

    • Fragments closer to the camera replace farther fragments.

  6. Fragment shading

    • Lighting, material color, normals, shadows, and reflections are used to calculate each fragment’s final color.

  7. Anti-aliasing and image processing

    • Edge smoothing and other post-processing may be applied.

  8. Frame buffer output

    • The completed pixel image is stored in the frame buffer and sent to the display.

The process then begins again for the next frame, often thousands of times per minute.


The graphics pipeline converts model geometry into pixels by transforming vertices, rasterizing triangles, testing visibility with depth values, and calculating realistic fragment colors through lighting.

The realism of a modern game image emerges from the combination of enormous geometric detail, massively parallel GPU computation, accurate coordinate transformations, per-pixel visibility tests, lighting calculations, interpolated surface normals, and advanced techniques such as ray tracing and neural upscaling.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent