Computer Graphics

Rasterization and Pixels

1995. Pixar releases Toy Story - the first feature-length CGI film. Each frame took 4-13 hours to render on a cluster of 117 Sun SPARCstations. 2024: an RTX 4090 renders that same frame in seconds. The math has not changed one bit. Toy Story: 800,000 polygons. Spider-Man: No Way Home: 250 million. Everything on screen is triangles. And everything that happens to them is the same pipeline: rasterization, z-buffer, shaders. Not magic - integer arithmetic and clever memory tricks.

  • **Unreal Engine 5 (Nanite):** virtual geometry system rasterizes up to one billion polygons per frame, dynamically selecting LOD on the GPU
  • **Chrome (Skia / Dawn):** every div, shadow, and text run goes through GPU rasterization. On Apple Silicon the entire UI is encoded as Metal draw calls assembled by Skia
  • **Apple Core Animation:** each UIKit layer is a separate framebuffer texture. Scrolling at 120 Hz requires a buffer swap every 8.3 ms with zero tearing
  • **Stable Diffusion (SDXL):** the final diffusion step is a CUDA tensor at 1024×1024×4 float16. Displaying it means converting floats to RGBA8888 pixels - rasterization at inference time

Rasterization: from geometry to pixels

A screen is a grid of squares. A GPU is a machine that fills those squares with color. Everything else is implementation detail. The process of converting mathematical geometry - line segments, triangles, Bezier curves - into specific colored pixels is called **rasterization**. In a modern AAA title, the GPU rasterizes 10-100 million triangles every 16 milliseconds.

**Rasterization** - converting vector geometry (line segments, triangles, polygons) into a raster image (a grid of pixels). This is the foundation of real-time graphics: the GPU rasterizes millions of triangles 60+ times per second.

The simplest rasterization task: draw a line from (x₁, y₁) to (x₂, y₂). The naive approach computes y = kx + b for each x: multiply, divide, round the float. Expensive. Bresenham's insight: accumulate an integer error term and decide whether to step in y with a single comparison. No floats - only additions and subtractions.

Bresenham's Algorithm (1962)

Jack Bresenham developed the algorithm for an IBM 1401 plotter. In an era when division cost hundreds of clock cycles, an integer algorithm using only additions and shifts was a breakthrough. 60+ years later, the same principle is used in GPUs.

The main advantage of Bresenham's algorithm over the naive y = kx + b approach:

Pixels and Color Models

A pixel is a number in memory. Three numbers, actually: Red, Green, Blue. Four when transparency is included. In VRAM they are packed tightly side by side, and the GPU reads them thousands at a time. A color model is simply a convention for what those numbers mean.

**RGB** - an additive color model. Each channel (Red, Green, Blue) stores intensity from 0 to the maximum. **Bit depth** determines precision: 8 bits = 256 levels per channel (16.7 million colors), 10 bits = 1024 levels (1.07 billion colors).

FormatBits/pixelChannelsUsage
RGB56516R:5, G:6, B:5Mobile devices, embedded
RGB88824R:8, G:8, B:8Standard (JPEG, BMP)
RGBA888832R:8, G:8, B:8, A:8UI, games (with transparency)
RGB10101030R:10, G:10, B:10HDR monitors, cinema
RGBA16F644×16bit floatHDR rendering, compositing

**Alpha** is the fourth number. A = 255: pixel is fully opaque. A = 0: pixel is invisible, nothing drawn. A = 128: blend. The formula is `result = src * α + dst * (1 - α)`. Every transparent window, every drop shadow, every UI tooltip runs this formula millions of times per frame. On the GPU it is a dedicated hardware unit called the ROP (Render Output Unit).

How many unique colors can the RGBA8888 format represent?

Framebuffer and Double Buffering

After rasterization, pixels land in the **framebuffer** - a flat array in VRAM. The monitor scans it left to right, top to bottom at the refresh rate. At 60 Hz that happens 60 times per second; at 120 Hz, 120 times. The GPU has to finish painting the next frame before the monitor's next sweep - otherwise the user sees a tear.

**Framebuffer** - a contiguous block of memory (video RAM) storing the raster image of the screen. For resolution W×H with C bytes per pixel: size = W × H × C bytes. Example: 1920×1080 RGBA = 8,294,400 bytes ≈ 8 MB.

**Tearing** happens when the monitor reads the framebuffer mid-write. Top half of the screen: new frame. Bottom half: old frame. A horizontal seam crawls up the display. In a fast-paced shooter it is impossible to ignore. The fix is to never write into the buffer the monitor is currently reading. Two buffers, swap between them.

MethodTearingLatencyFPS
Single bufferYes (visible tears)MinimalUnlimited
Double buffer (no VSync)PossibleMinimalUnlimited
Double buffer + VSyncNo+1 frame (16ms at 60Hz)≤ monitor refresh rate
Triple bufferNoLess than VSync≤ monitor refresh rate

**Triple buffering** breaks the hard coupling: the GPU draws into one back buffer, a second buffer waits for VSync, a third sits in front of the monitor. The GPU never idles waiting for the display. G-Sync (NVIDIA) and FreeSync (AMD) go further - the monitor's refresh rate dynamically tracks the GPU's output frame by frame. The display adapts to the renderer, not the other way around.

Double buffering + VSync eliminates tearing. What is the cost?

Resolution and Aspect Ratio

Resolution is the framebuffer size. More pixels means more memory, more rasterizer work - a linear relationship. Double the screen area, double the load. The jump from 1080p to 4K is a 4× pixel increase, which is exactly why an RTX 3060 delivering 100+ FPS at 1080p struggles to hit 30 FPS at 4K in demanding titles.

**Resolution** - the number of pixels horizontally and vertically. **Aspect Ratio** - the ratio of width to height. 1920×1080 → 16:9. More pixels → more detail, but the GPU rasterizes proportionally more.

NameResolutionAspect RatioMegapixelsFramebuffer (RGBA)
720p (HD)1280×72016:90.92 MP3.5 MB
1080p (Full HD)1920×108016:92.07 MP7.9 MB
1440p (2K)2560×144016:93.69 MP14.1 MB
4K (UHD)3840×216016:98.29 MP31.6 MB
Ultrawide3440×144021:94.95 MP18.9 MB

**PPI** measures density, not absolute resolution. The iPhone 15 at 2556×1179 on a 6.1" diagonal delivers 461 PPI - individual pixels are physically invisible at normal viewing distance. A 27" 4K monitor at the same resolution gives 163 PPI. That is why Apple defines Retina as density above ~220 PPI rather than a specific pixel count: what matters is whether the eye can resolve individual pixels.

Toy Story took 4 hours per frame in 1995. Today: seconds. The math is identical. Bresenham wrote his algorithm for an IBM plotter in 1962 with no thought of GPUs. Sixty years later his idea runs inside every NVIDIA, AMD, and Apple Silicon chip shipped. Principles change slowly. Hardware changes fast.

Ray tracing has completely replaced rasterization in modern games and GPUs

Rasterization remains the dominant rendering method in real-time. Ray tracing is used in a hybrid approach: the main geometry is rasterized, while RT adds reflections, shadows, and global illumination. Pure ray tracing is too slow for 60+ FPS

Rasterization is O(triangle pixel area): the GPU tests thousands of pixels in parallel per clock. Ray tracing is O(W × H × scene depth): each ray traverses the entire BVH of scene geometry. At 4K with 200M triangles, pure RT cannot exceed 5-10 FPS even on an RTX 4090. Hence NVIDIA DLSS and AMD FSR: rasterize + RT at 1080p, then upsample to 4K with a neural network.

Switching from 1080p to 4K increases GPU load approximately:

Key Ideas

  • **Rasterization** - converting mathematical geometry into pixels. Bresenham's algorithm (1962) does it without floats: only integer additions. The same principle lives inside every GPU built today
  • **RGB/RGBA** - additive color model. 8 bits/channel = 16.7M colors. Alpha blending: `result = src * α + dst * (1 - α)` - the formula behind every transparent UI element
  • **Framebuffer** - a contiguous VRAM array. 1920×1080 RGBA = 7.9 MB. Double buffering: GPU draws into the back buffer while the monitor reads the front - swap on vertical blank
  • **1080p → 4K = 4× pixels = 4× GPU load.** Ray tracing layers on top of rasterization, it does not replace it - even the RTX 4090 uses a hybrid approach

Related Topics

Rasterization is the first step in understanding the graphics pipeline:

  • Linear Algebra for Graphics — Triangle vertices are transformed by matrices before rasterization
  • Coordinate Spaces — Geometry passes through a chain of spaces (model→world→screen) before rasterization
  • Binary System — RGB565, RGBA8888 - packing colors into bits. Bitwise operations for fast channel access

Вопросы для размышления

  • Why is Bresenham's algorithm still relevant if modern GPUs have hardware rasterizers?
  • How is alpha blending implemented for semi-transparent objects that overlap each other? Does draw order matter?
  • When switching to 8K (7680×4320) - how many times greater will the GPU load be compared to 4K?

Связанные уроки

  • la-01-vectors-intro — Linear algebra is the language of computer graphics: vectors, transformation matrices, dot/cross product
  • gd-01 — Graphics is the foundation of game dev: rendering, shaders, GPU physics
  • arvr-01 — AR/VR is built on top of computer graphics: stereo rendering, reprojection, spatial mapping
  • dsp-01 — DSP processes signals in time, computer graphics processes space. Convolution, filters, FFT apply to both
  • arch-04-cpu
Rasterization and Pixels

0

1

Sign In