Skip to content

Instantly share code, notes, and snippets.

@workhorsy
Created December 25, 2021 17:41
Show Gist options
  • Select an option

  • Save workhorsy/08ffca0396cf09d6730b87031a3c38de to your computer and use it in GitHub Desktop.

Select an option

Save workhorsy/08ffca0396cf09d6730b87031a3c38de to your computer and use it in GitHub Desktop.
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