Skip to content

Instantly share code, notes, and snippets.



Created Sep 7, 2011
What would you like to do?
Encoding to RGBM
// in our case,
const float kRGBMMaxRange = 8.0f;
const float kOneOverRGBMMaxRange = 1.0f / kRGBMMaxRange;
// encode to RGBM, c = ARGB colors in 0..1 floats
float r = c[1] * kOneOverRGBMMaxRange;
float g = c[2] * kOneOverRGBMMaxRange;
float b = c[3] * kOneOverRGBMMaxRange;
float a = max(max(r, g), max(b, 1e-6f));
a = ceilf(a * 255.0f) / 255.0f;
c[0] = min(a, 1.0f);
c[1] = min(r / a, 1.0f);
c[2] = min(g / a, 1.0f);
c[3] = min(b / a, 1.0f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.