src/math/Color.cpp
/** Converts an HSV color to a linear space RGB color */
Converts an HSV color to a linear space RGB color
Converts an HSV color to a linear space RGB color
FLinearColor FLinearColor::HSVToLinearRGB() const
	{
		const float Hue = r;
		const float Saturation = g;
		const float Value = b;
		const float HDiv60 = Hue / 60.0f;
		const float HDiv60_Floor = floorf(HDiv60);
		const float HDiv60_Fraction = HDiv60 - HDiv60_Floor;
		const float RGBValues[4] = {
			Value,
			Value * (1.0f - Saturation),
			Value * (1.0f - (HDiv60_Fraction * Saturation)),
			Value * (1.0f - ((1.0f - HDiv60_Fraction) * Saturation)),
		};
		const uint32_t RGBSwizzle[6][3] = {
			{0, 3, 1},
			{2, 0, 1},
			{1, 0, 3},
			{1, 2, 0},
			{3, 1, 0},
			{0, 1, 2},
		};
		const uint32_t SwizzleIndex = ((uint32_t)HDiv60_Floor) % 6;
		return FLinearColor(RGBValues[RGBSwizzle[SwizzleIndex][0]],
			RGBValues[RGBSwizzle[SwizzleIndex][1]],
			RGBValues[RGBSwizzle[SwizzleIndex][2]],
			a);
	}
FLinearColor FLinearColor :: HSVToLinearRGB ( ) const { const float Hue = r ; const float Saturation = g ; const float Value = b ; const float HDiv60 = Hue / 60.0f ; const float HDiv60_Floor = floorf ( HDiv60 ) ; const float HDiv60_Fraction = HDiv60 - HDiv60_Floor ; const float RGBValues [ 4 ] = { Value , Value * ( 1.0f - Saturation ) , Value * ( 1.0f - ( HDiv60_Fraction * Saturation ) ) , Value * ( 1.0f - ( ( 1.0f - HDiv60_Fraction ) * Saturation ) ) , } ; const uint32_t RGBSwizzle [ 6 ] [ 3 ] = { { 0 , 3 , 1 } , { 2 , 0 , 1 } , { 1 , 0 , 3 } , { 1 , 2 , 0 } , { 3 , 1 , 0 } , { 0 , 1 , 2 } , } ; const uint32_t SwizzleIndex = ( ( uint32_t ) HDiv60_Floor ) % 6 ; return FLinearColor ( RGBValues [ RGBSwizzle [ SwizzleIndex ] [ 0 ] ] , RGBValues [ RGBSwizzle [ SwizzleIndex ] [ 1 ] ] , RGBValues [ RGBSwizzle [ SwizzleIndex ] [ 2 ] ] , a ) ; }
Converts an HSV color to a linear space RGB color
Converts an HSV color to a linear space RGB color
// In this color, r = H, g = S, b = V