Scalar Operations

Accidentally vectorising a calculation can produce a performance hit

It is very easy to accidentally vectorise a calculation. Be wary of vectorising scalar operations where it cost more cycles for the same output. For example:

highp vec4 v1, v2;
highp float x, y;
// Bad
v2 = (v1 * x) * y; // vector * scalar followed by vector * scalar totals eight scalar muladds
// Good
v2 = v1 * (x * y); // scalar * scalar followed by vector * scalar totals five scalar muladds