Last active
August 14, 2018 17:10
-
-
Save bricevdm/35d860d132f539e3e9741dcce4e5f551 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
// http://graphicrants.blogspot.com/2009/04/rgbm-color-encoding.html | |
float4 RGBMEncode( float3 color ) { | |
float4 rgbm; | |
color *= 1.0 / 6.0; | |
rgbm.a = saturate( max( max( color.r, color.g ), max( color.b, 1e-6 ) ) ); | |
rgbm.a = ceil( rgbm.a * 255.0 ) / 255.0; | |
rgbm.rgb = color / rgbm.a; | |
return rgbm; | |
} | |
float3 RGBMDecode( float4 rgbm ) { | |
return 6.0 * rgbm.rgb * rgbm.a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment