From time to time, we get questions regarding users sprites or cameras “shaking”/“wobbling”/“jittering” etc.
Most often, it appears when doing floating point math away from origin (0,0,0).
And floating point numbers in shaders are also susceptible to this behavior.
In C/C++ you can use the types “float”, and “double”, and they’re usually (not always!) 32 and 64 bit.
In OpenGL ES, the precision of floating point numbers are also specified with minimum allowed ranges and precision. From the documentation, section 4.5.2:
“Precision qualifiers declare a minimum range and precision that the underlying implementation must use when storing these variables. Implementations may use greater range and precision than requested, but not less. The amount of increased range and precision used to implement a particular precision qualifier can depend on the variable, the operations involving the variable, and other implementation dependent
details.”
Which means that the graphics driver is allowed to use higher precision.
And that’s likely what happens on your desktop machine, since it has more cpu cycles to spare.
But, for lower end devices, e.g. older mobile phones (which we still target), the precision can have a detrimental effect, so choose your precision wisely, and test on your target devices.
Here are the minimum precision numbers as defined by OpenGL ES:
-
highp
- 16-bit, floating point range: -2^62 to 2^62, integer range: -2^16 to 2^16 -
mediump
- 10 bit, floating point range: -2^14 to 2^14, integer range: -2^10 to 2^10 -
lowp
- 8 bit, floating point range: -2 to 2, integer range: -2^8 to 2^8