Look closely at a brick wall in almost any video game. It has a thousand tiny variations — mortar lines, chipped corners, subtle grime, a hint of moss. You might imagine the artist modelled every brick as separate geometry. They did no such thing. That entire wall is very often a single flat quadrilateral — four corners, two triangles — with a photograph of a brick wall glued onto it. The geometry is trivial; all the richness lives in an image. This trick, called texture mapping, is how modern graphics gets astonishing detail almost for free. And to pull it off we need two ideas working together: how colour is stored as numbers, and how an image is pinned onto a surface.
A screen makes colour by adding light. Every pixel is three tiny lamps — one red, one green, one blue — and their brightnesses mix in your eye. This is the RGB model, and it is additive: start from black (all lamps off) and add light to build up toward white. Full red plus full green makes yellow; full green plus full blue makes cyan; all three at full makes white.
Each channel's brightness is usually stored in 8 bits, giving
the famous "16.7 million colours" — more shades than the human eye can reliably tell apart, which
is exactly why 24-bit became the standard. A colour is then just a triple like
Below are three overlapping lamps — one per channel. Drag each slider to change that channel's
brightness and watch the overlaps: where two lamps meet you get a secondary colour, where all three
meet you head toward white. The readout shows the three 8-bit channel values,
RGB is natural for screens but awkward for humans — "a bit less blue and a touch brighter" is not obvious in RGB numbers. So other models exist for other jobs:
Everyone learns in art class that red and green paint make a muddy brown. So why does the screen insist red light plus green light makes bright yellow? Because they are opposite processes. Screens are additive: they start black and add light, so piling colours on climbs toward white. Paint and ink are subtractive: they start from white paper and each pigment absorbs (subtracts) some wavelengths, so piling colours on sinks toward black/brown.
The two systems even have swapped "primaries": the secondary colours of light — cyan, magenta, yellow — are exactly the primary colours of ink (that is where CMY comes from). If you ever design something on screen in RGB and it prints looking dull and dark, this mismatch is usually the culprit: the bright, glowing colours a monitor can emit simply cannot all be reproduced by subtracting light with ink.
Now the second half: how does the brick photo know where to sit on the quad? We give every vertex
of the geometry a pair of texture coordinates
The key point: UVs are stored only at the vertices. But a triangle has thousands of pixels
between its corners, and each of those needs its own
Any point
The three weights
and the same blend works for colours, normals, or depth. This is exactly how the rasterizer fills a
triangle: for each pixel it finds the barycentric weights, blends the corner UVs to get this
pixel's
A triangle's three corners carry the texture
The identical blend gives the interpolated colour. Suppose the corners are red-ish, green-ish and
blue-ish and we want the red channel at
Nothing stops an artist assigning UVs bigger than
Clamping a stray value is just