src/math/Color.cpp
// Convert from float to RGBE as outlined in Gregory Ward's Real Pixels article, Graphics Gems II, page 80.
Convert from float to RGBE as outlined in Gregory Ward's Real Pixels article, Graphics Gems II, page 80.
Convert from float to RGBE as outlined in Gregory Ward ' s Real Pixels article Graphics Gems II page 80 .
FColor FLinearColor::ToRGBE() const
	{
		const float	Primary = FMath::Max(r, g, b);
		FColor	Color;
		if (Primary < 1E-32)
		{
			Color = FColor(0, 0, 0, 0);
		}
		else
		{
			int	Exponent;
			const float Scale = frexp(Primary, &Exponent) / Primary * 255.f;
			Color.r = FMath::Clamp(FMath::TruncToInt(r * Scale), 0, 255);
			Color.g = FMath::Clamp(FMath::TruncToInt(g * Scale), 0, 255);
			Color.b = FMath::Clamp(FMath::TruncToInt(b * Scale), 0, 255);
			Color.a = FMath::Clamp(FMath::TruncToInt(Exponent), -128, 127) + 128;
		}
		return Color;
	}
FColor FLinearColor :: ToRGBE ( ) const { const float Primary = FMath :: Max ( r , g , b ) ; FColor Color ; if ( Primary < 1E-32 ) { Color = FColor ( 0 , 0 , 0 , 0 ) ; } else { int Exponent ; const float Scale = frexp ( Primary , & Exponent ) / Primary * 255.f ; Color . r = FMath :: Clamp ( FMath :: TruncToInt ( r * Scale ) , 0 , 255 ) ; Color . g = FMath :: Clamp ( FMath :: TruncToInt ( g * Scale ) , 0 , 255 ) ; Color . b = FMath :: Clamp ( FMath :: TruncToInt ( b * Scale ) , 0 , 255 ) ; Color . a = FMath :: Clamp ( FMath :: TruncToInt ( Exponent ) , -128 , 127 ) + 128 ; } return Color ; }
Convert from float to RGBE as outlined in Gregory Ward's Real Pixels article, Graphics Gems II, page 80.
Convert from float to RGBE as outlined in Gregory Ward ' s Real Pixels article Graphics Gems II page 80 .