Skip to content

Instantly share code, notes, and snippets.

@jorovipe97
Last active November 10, 2019 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorovipe97/852abc6f3959d5c90888ffd5177338e2 to your computer and use it in GitHub Desktop.
Save jorovipe97/852abc6f3959d5c90888ffd5177338e2 to your computer and use it in GitHub Desktop.
Converts a color in hex format to decimal vector, similar to the ones used on glsl or unity
function hexToGlslColor(hexColor) {
var r = +hexColor >> 16;
r /= 255;
var g = (+hexColor & 0x00FF00) >> 8;
g /= 255;
var b = (+hexColor & 0x0000FF);
b /= 255;
return `vec4(${r.toFixed(5)}, ${g.toFixed(5)}, ${b.toFixed(5)}, 1.0)`
}
// example of usage:
// note that we shouldn't pass a string but a number, then remove the (#)e056fd if
// you copied the css color
// hexToGlslColor(0xe056fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment