The 2D hypot function for GLSL
sqrt(x * x + y * y) is easy, but it's subject to overflow and underflow in an environment with already limited precision. This function returns the length of a vec2 while avoiding overflow/underflow. Most of the time though, you're almost certainly fine without this.
#pragma glslify: hypot = require(glsl-hypot)
attribute vec3 position;
void main () {
gl_FragColor = vec4(vec3(hypot(position.xy)), 1.0);
}© 2016 Ricky Reusser. MIT License.