Quiz: how graphics cards store colour
Before this unit: From triangles to shaded pixels (previous unit); Day 51: Marching cubes.
See also: 12- and 16-bit images in practice (day 3); Floating point (day 3); Day 46: Colour; Day 3: Bit depth and noise.
Short questions to test your understanding. Try each on paper first, then open the answer.
Q1. An image you load shows people with blue faces and an orange sky. What is the most likely cause?
The channel order: the data are BGR(A) and are read as RGB(A) (or the other way round), so red and blue are swapped. Skin (reddish) turns bluish, the blue sky turns orange. Green is in the middle in both orders and stays put.
Q2. An image looks sheared, with diagonal stripes, and its colours change from row to row. The pixel values themselves look plausible. What went wrong?
The row stride: the rows are padded (say to a multiple of 4 bytes) but were read as if they were packed, or with the wrong width. Each row then starts a little further off than the one before (shear), and when the offset is not a multiple of the pixel size the bytes are read as the wrong channels (colour change).
Q3. An 8-bit texture and a 10-bit normalised texture both give the shader numbers between 0 and 1. What is the difference, and when would you see it?
The step: 1/255 against 1/1023, four times finer. You see it in smooth, low-contrast gradients (a dark sky, a smooth fluorescence background) after contrast stretching: the 8-bit texture shows bands, the 10-bit one much finer ones.
Q4. Why can a GPU not interpolate (linearly filter) an integer texture, and why would you not want it to for a label image?
The hardware filters only normalised and float formats; an integer texture with linear filtering is incomplete and reads as zero. For labels interpolation would be meaningless anyway: halfway between object 3 and object 7 is not object 5. Use nearest-neighbour sampling for labels.
Q5. A photo is stored as 8-bit sRGB. You shrink it to half size by averaging 2 × 2 blocks of the stored codes. Is that right? What does a GPU do with an sRGB texture format?
Not quite: sRGB codes are not proportional to light, so averaging codes does not average light (fine black-and-white detail comes out too dark; why is explained on the colour day). With an sRGB texture format the GPU decodes each texel to a linear value before filtering, averages light correctly, and works in linear values from then on.
Q6. Why does resizing an image with transparency, without premultiplied alpha, give dark or coloured fringes around objects?
Transparent pixels still store some colour (often black). With straight alpha the filter averages that invisible colour into the edge pixels with the same weight as the visible colour. With premultiplied alpha, a transparent pixel’s colour is multiplied by \alpha = 0, so it contributes nothing, and the edge keeps the object’s colour.
Q7. How much memory does a 2048 × 2048 texture with RGBA half floats take, with a full mipmap chain?
2048^2 texels × 8 bytes = 32 MiB; the mipmaps add about a third: about 42.7 MiB.