GLSL built-in function
roundEven()
Rounds to nearest integer, breaking ties toward the even integer.
Demo version: GLSL ES 3.00 / WebGL 2Demo stage: Fragment
Syntax
genType roundEven(genType x)genType means float / vec2 / vec3 / vec4; matching placeholders use the same type.
Parameters
- x
- Input value or left-hand vector
Return value
An integer-valued float per component, nearest to x; exact ties choose the even integer.
Live example
Edit the code and the preview updates as you type.
What roundEven does
Rounds to nearest integer, breaking ties toward the even integer.
Read the preview
roundEven(x*4.0)/4.0 creates quarter-unit plateaus. Changing both scale factors to 8.0 produces twice as many, half-height steps.
Core call
roundEven(x*4.0)/4.0;
2.5 becomes 2 and 3.5 becomes 4; the rule also applies to negatives.
Experiment
Compare roundEven(2.5)/4.0 with roundEven(3.5)/4.0. The first draws y = 0.5 and the second y = 1, demonstrating the even-integer tie rule.