Created
December 25, 2021 17:41
-
-
Save workhorsy/08ffca0396cf09d6730b87031a3c38de to your computer and use it in GitHub Desktop.
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
| vec4 int_to_vec4(const int data) { | |
| int mask = shift_left(shift_right(data, 8), 8); | |
| float r = float(data - mask) / 255.0; | |
| mask = shift_left(shift_right(data, 16), 16); | |
| float g = float(shift_right(data - mask, 8)) / 255.0; | |
| mask = shift_left(shift_right(data, 24), 24); | |
| float b = float(shift_right(data - mask, 16)) / 255.0; | |
| float a = float(shift_right(data, 24)) / 255.0; | |
| return vec4(r, g, b, a); | |
| } | |
| int shift_right(int data, int times) { | |
| if (times > 0) { | |
| return data / int(pow(2.0, float(times))); | |
| } else { | |
| return data; | |
| } | |
| } | |
| int shift_left(int data, const int times) { | |
| if (times > 0) { | |
| return data * int(pow(2.0, float(times))); | |
| } else { | |
| return data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment