Skip to content

Instantly share code, notes, and snippets.

@bricevdm
Last active August 14, 2018 17:10
Show Gist options
  • Save bricevdm/35d860d132f539e3e9741dcce4e5f551 to your computer and use it in GitHub Desktop.
Save bricevdm/35d860d132f539e3e9741dcce4e5f551 to your computer and use it in GitHub Desktop.
// 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