Precision & range of variables

The OpenGL ES Shading Language, used in e.g. IPhone OpenGL ES 2.0, lets you decide upon the range and precision used to represent integer or floating point variables.

PRECISION QUALIFIERS:

  • highp (e.g. highp mat4 myMatrix)
  • mediump (e.g. varying mediump vec2 myTexCoord)
  • lowp (e.g. lowp float myColor)

MINIMUM RANGES AND PRECISION

BitsFP RangeFP PrecisionInt Range
highp16(-262, 262)Relative 2-16(-216, 216)
mediump10(-214, 214)Relative 2-10(-210, 210)
lowp8(-2, 2)Absolute 2-8(-28, 28)

DEFAULT VERTEX SHADER PRECISIONS

  • precision highp float
  • precision highp int
  • precision lowp sampler2D
  • precision lowp samplerCube

DEFAULT FRAGMENT SHADER PRECISIONS

  • precision mediump int
  • precision lowp sampler2D
  • precision lowp samplerCube

Notice the fragment shader is missing a default precision for float. This means you must include precision qualifier for floats.

Built-in Variables

VERTEX SHADER

TypePrecision
gl_Positionvec4highp
gl_PointSizefloatmediump

FRAGMENT SHADER

TypePrecision
gl_FragCoordvec4mediump
gl_FrontFacingbool
gl_FragColorvec4mediump
gl_FragData[gl_MaxDrawBuffers]vec4mediump
gl_PointCoordvec2mediump