skip to content

Why are colour textures stored sRGB-encoded while normal, roughness and other data maps stay linear, and what breaks when they are swapped?

level: middleimportance: must knowfreq 62%

answer

  1. colour versus measurement
  2. perceptual precision in dark tones
  3. decoded on sample, before filtering
  4. a stored 0.5 is not half

basics

~20 s

sRGB encoding gives dark tones more of the 8-bit codes, and the GPU decodes it to linear on sampling. Data maps hold numbers, not colours: decoding them tilts normals and lowers roughness, so surfaces look skewed and glossier.

solid answer

~50 s

Lighting maths is only correct on **linear** values, so the shader must receive linear numbers either way; the choice is how they are stored. Colour textures are authored as sRGB, and an sRGB format makes the sampler decode them to linear as they are read, on current hardware before filtering. That encoding suits 8 bits: the darkest tenth of linear intensity gets about 90 of 256 codes instead of about 26, so dark gradients do not band. **Data maps** (normals, roughness, metallic, masks, heights) were computed as linear numbers. Flag one as sRGB and the curve bends it: a stored 0.5 reads as about 0.21, so a flat normal component unpacks to about -0.57 and lighting tilts, and roughness 0.5 reads as 0.21 and looks glossy. The reverse mistake, sRGB albedo sampled as linear, makes midtones too bright and surfaces washed out. Alpha is never decoded.

go deeper

for a junior

Remember the rule: colour textures are sRGB, data textures such as normals, roughness and masks are linear, and the shader always works with linear values.

for a middle

Explain the transfer curve, why it suits 8-bit storage, that decoding happens on sample before filtering, and the concrete symptom of each swapped flag, with the 0.5 to 0.21 example.

for a senior

Diagnose a material that looks skewed, glossy or washed out by checking import flags, mip generation and format variants, and know which compressed formats have sRGB variants and why.

for a principal

Make colour-space handling a pipeline rule: per-map-type defaults in import, a validation step for mismatched flags, and an agreed list for the ambiguous maps your pipeline must decide once.

## Two kinds of texel value A texture holds numbers, but they mean different things. In a **colour texture** (albedo or base colour, a UI sprite, an 8-bit emissive colour) they describe a colour someone painted or photographed, saved the way image files save colour: **sRGB-encoded**. In a **data texture** (a normal map, roughness, metallic, a height map, a mask) they are values a tool computed, such as a vector component or a 0-to-1 parameter, and they are **linear**: 0.5 means exactly half. Lighting maths is only correct on linear values, because light adds linearly: two lights of intensity 0.25 make 0.5. The shader must therefore receive linear numbers from both kinds of texture; they differ only in how they are stored. ## The sRGB transfer function sRGB applies a curve, close to a power of 1/2.2, before quantising to 8 bits. Decoding a stored value `c` in 0..1 back to linear is: ``` linear = c / 12.92 if c <= 0.04045 linear = ((c + 0.055) / 1.055) ^ 2.4 otherwise ``` Two consequences matter: - **Precision goes where eyes need it.** Vision is more sensitive to differences between dark tones. With 8-bit sRGB, the darkest tenth of linear intensity gets about 90 of the 256 codes; with 8-bit linear it gets about 26, so dark gradients in an 8-bit linear albedo band visibly. - **The midtones differ a lot.** A stored 0.5 decodes to about 0.214 in linear light. ## What the GPU does with an sRGB format A texture format flagged as sRGB tells the sampler to decode each texel to linear as it is read. On current hardware this happens before filtering, so bilinear blends and anisotropic averages are computed in linear light. Only the colour channels are decoded; **alpha is always linear**. Render targets can carry the same flag and encode on write, but how the final HDR image reaches the display belongs to the post-processing chain, not to texture storage. Compressed formats follow the same split. BC1, BC2, BC3, BC7, ETC2 and ASTC have sRGB variants for colour. BC4 and BC5 have none, because one- and two-channel formats are meant for data, and BC6H stores half-float HDR values that are already linear. ## Which map is which | Map | Stored as | Why | |---|---|---| | Base colour or albedo | sRGB | authored as colour; gains dark-tone precision | | UI and sprite colour | sRGB | authored as colour | | Tangent-space normal map | linear | encodes vector components as `n * 0.5 + 0.5` | | Roughness, metallic, masks | linear | parameters with a defined numeric meaning | | Height or displacement | linear | a distance | | HDR environment or emissive | linear float or BC6H | values above 1 need floating point | Pipelines differ on a few maps, such as ambient occlusion or an 8-bit emissive colour; what matters is that the import flag matches how each map was authored. ## What breaks when the flags are swapped 1. **A normal map decoded as sRGB.** A flat normal is stored as (0.5, 0.5, 1.0). Decoding turns each 0.5 into about 0.214, which unpacks to about -0.57 instead of 0, so every normal tilts strongly toward one diagonal and the lighting looks skewed across the whole surface. 2. **A roughness map decoded as sRGB.** A roughness of 0.5 reads as about 0.21, so surfaces look glossier and highlights tighter than the artist painted; every value between 0 and 1 is pushed lower. 3. **An sRGB albedo sampled as linear.** The shader receives the encoded values, which are higher than the true linear colour in the midtones (0.5 instead of 0.214), so lit surfaces look washed out and low in contrast. 4. **An albedo converted to 8-bit linear storage.** Colours survive on average, but dark gradients band because the darkest tones lost most of their codes. ## Debugging the mix-up - Compare each map's import flag with how it was authored, map by map, rather than trusting a folder-wide default. - Light a test material with a single white directional light: an sRGB-decoded normal map shows the same tilt everywhere, and a mis-decoded roughness map shows the wrong gloss on a known reference value. - Check the mip generator as well: averaging sRGB-encoded values without decoding first darkens fine contrast in distant levels even when sampling is correct. - In many pipelines the flag only changes how the same stored bytes are read, so a wrong flag is cheap to fix once found and easy to miss until lighting looks wrong.

  • Why must mip generation and filtering of colour textures happen in linear space?
    Averaging encoded values is not averaging light. A black-and-white checker averages to an encoded 0.5, which is about 0.21 in linear light, while the true average is 0.5, so a distant checker looks too dark and contrast collapses. Decoding before filtering, as sRGB formats do on current hardware, and before building mips keeps averages physical.
  • Where do HDR textures such as an environment map or a bright emissive fit in this split?
    Values above 1 cannot live in an 8-bit 0-to-1 encoding, so HDR maps use floating-point formats or BC6H, which store linear values and have no sRGB variant. An 8-bit emissive colour can stay sRGB and be scaled by a separate intensity parameter.

  • Gamma correction is just a brightness tweak applied at the end of the frame.
  • Normal maps should be stored sRGB because they are images like any other texture.
  • sRGB decoding also applies to a texture's alpha channel.
  • 8-bit linear storage is always more accurate than 8-bit sRGB.
  • A roughness map reads the same whether or not it is decoded as sRGB.