Shader precision and pixel color formats.

DOGMA1138

Regular
why is the shader precision much higher then the color format?
i mean, 32bit FP precision gives you 32bit per color channel and alpha. if your game set to a 32bit color precision you get only 8bits per channel and another 8 bits for the alpha, so why is it so important, to have a 128/96bit color format, if in the end you are limited to only 32bits?
 
ok, i thought there might be another reason besides that 8)
oh and why not take an advantage of the higher shader precision wich is needed any way, and boost the color format aswell. 64/96/128bit color should look sweet IMO can the CRT monitors work with 32+ bit color formats?
:D
 
i think crts can go higher than 32, but not up to 128. for some reason 48 keeps popping into my head.
 
Even if the frame-buffer were to use FP32, the output would still be clamped to [0,1] since you can't exactly produce negative colour and the monitor won't produce over-bright pixels. In that case, the precision presented to the user would be 23 bits per channel.

Still, there is a display format for providing more than 8 bits per channel. The token in DirectX is A2R10G10B10. 2 bits of alpha and 10 bits each for red, green, and blue. It's not particularily useful for alpha-blending (except for masking), but it does produce 64x more colours.
 
DOGMA1138 said:
why is the shader precision much higher then the color format?

Here's a very simple analogy. Suppose you have a pixel with a value of 12 (out of 255) in the red channel (integer), and your final output image also has to be in integer format. Now, you want to blend the pixel with itself and achieve a value of 30 for said pixel's red channel. How can you do it with 1 instruction while using integer precision?

12 * 2 = 24

that's not good enough so let's try this instead:

12 * 3 = 36

Still no good. Now switch to floating point and you can do:

12.0 * 2.5 = 30.0 which gets clamped to 30 in output.

Shader precision is all about the operations you do before spitting the value out. And those operations will get bigger and bigger errors the less precision you use.
 
The main reason you need at least FP24 is texture coordinates. You need enough bits to have some amount of sub-texel precision even in huge textures like 2048², and you need a range well beyond [0, 1] to allow repeating textures.
Additionally, there's normal and positional calculations that need precision and range to avoid banding.
You also loose some precision on rounding, so a long shader requires more precision than a short one.

For colors, FP16 usually is enough.
 
Back
Top