FLinearColor는 구조체 자체가 GetLuminance() 라는 함수를 제공한다.
FORCEINLINE float GetLuminance() const
{
return R * 0.3f + G * 0.59f + B * 0.11f;
}
근사값이긴 한데 소수점까지 정확한 계산은 아래와 같다.
https://www.w3.org/TR/AERT/#color-contrast
Color brightness is determined by the following formula:
((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
Note: This algorithm is taken from a formula for converting RGB values to YIQ values. This brightness value gives a perceived brightness for a color.
WWW
FORCEINLINE float CalculateLuminance(FLinearColor& InColor)
{
return InColor.R * 0.299f + InColor.G * 0.587f + InColor.B * 0.114f;
}
RGB 컬러인 FColor 기준에서는 계산식이 조금 다르다.
https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
FORCEINLINE float CalculateRGBtoLuminance(FColor& InColor)
{
//https://en.wikipedia.org/wiki/Relative_luminance
return 0.2126f * InColor.R + 0.7152 * InColor.G + 0.0722 * InColor.B;
}
이렇게 나온 값은 uint8 (8bit) 최대 범위인 0~255 사이로 나오게 된다.
이때, 0~1 로 일반화 하고 싶다면, 아래와 같이 하면 된다.
//일반화
UKismetMathLibrary::NormalizeToRange(Luminance,0,255);