Last active
August 13, 2022 18:17
-
-
Save Mikeysax/3765079f62b5cd8e779ce9fb53c61ba5 to your computer and use it in GitHub Desktop.
Hex colors to Godot Vec4 Uniforms
This file contains 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
// Uses Apollo Color Pallete By Default: https://lospec.com/palette-list/apollo | |
var hexColors = [ | |
'#172038', | |
'#253a5e', | |
'#3c5e8b', | |
'#4f8fba', | |
'#73bed3', | |
'#a4dddb', | |
'#19332d', | |
'#25562e', | |
'#468232', | |
'#75a743', | |
'#a8ca58', | |
'#d0da91', | |
'#4d2b32', | |
'#7a4841', | |
'#ad7757', | |
'#c09473', | |
'#d7b594', | |
'#e7d5b3', | |
'#341c27', | |
'#602c2c', | |
'#884b2b', | |
'#be772b', | |
'#de9e41', | |
'#e8c170', | |
'#241527', | |
'#411d31', | |
'#752438', | |
'#a53030', | |
'#cf573c', | |
'#da863e', | |
'#1e1d39', | |
'#402751', | |
'#7a367b', | |
'#a23e8c', | |
'#c65197', | |
'#df84a5', | |
'#090a14', | |
'#10141f', | |
'#151d28', | |
'#202e37', | |
'#394a50', | |
'#577277', | |
'#819796', | |
'#a8b5b2', | |
'#c7cfcc', | |
'#ebede9', | |
]; | |
function hexToGodotVec4ShaderUniform(hexColor, alpha, index) { | |
var red_channel = hexChannelToFloat(hexColor, 'red'); | |
var green_channel = hexChannelToFloat(hexColor, 'green'); | |
var blue_channel = hexChannelToFloat(hexColor, 'blue'); | |
return `uniform vec4 color_${(index + 1)} = vec4(${red_channel}, ${green_channel}, ${blue_channel}, ${(alpha || 1.0).toFixed(1)});`; | |
} | |
function hexChannelToFloat(hexColor, channel) { | |
var hexSliceDigits; | |
if (channel === 'red') hexSliceDigits = [1, 3]; | |
if (channel === 'green') hexSliceDigits = [3, 5]; | |
if (channel === 'blue') hexSliceDigits = [5, 7]; | |
return parseInt(hexColor.slice(hexSliceDigits[0], hexSliceDigits[1]), 16) / 256; | |
}; | |
var shaderColors = hexColors.map(function(hexColor, index) { | |
return hexToGodotVec4ShaderUniform(hexColor, 1.0, index) | |
}); | |
console.log(shaderColors.join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment