Last active
November 10, 2019 00:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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