2.6.10. Shader arithmetic

Internally, the geometry processor works on 32-bit floating point values that follow the IEEE 754 standard with the exception that de-normalized, small values are taken as 0.0. The vertex shader represents integers using floating-point values.

You can transfer vertex data, from the geometry processor to the pixel processor, in several different formats. Values are converted by hardware from and to the float forms used in the shaders, at no extra cost.

The OpenGL ES 2.0 standard implies that, by default, data must be transferred as 32-bit floating point values. However, this produces a lot of memory traffic, and the full 32-bit precision is often not necessary. To avoid using 32-bit values, set the precision for the output varying values from the vertex shader program to either mediump or lowp.

The fragment shader uses 16-bit floating point format, that consists of:

This format corresponds to approximately three decimal digits of precision.

The arithmetic for 16-bit floating point values deviates slightly from the IEEE 754 standard. For example:

In many cases, this treatment of 16-bit floating point values results in reasonable pixel colors rather than NaN values. For example, division by zero or taking a square root of a negative argument always yields NaN. If the fragment shader uses these results as color components, they are dark. When used as texture coordinates, it has the same effect as 0.0.

If you blend the resulting color with other contributions, the error might not be noticeable. In other words, it might not be necessary to include if statements in your shader program to guard against division by zero or bad arguments to built-in functions. Avoid taking such precautions until you notice bad pixels on the display.

Copyright © 2007-2009 ARM. All rights reserved.ARM DUI 0363D
Non-Confidential