Created
September 7, 2011 04:50
-
-
Save aras-p/1199797 to your computer and use it in GitHub Desktop.
Encoding to RGBM
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
// 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