UKismetMathLibrary::Conv_ColorToLinearColor
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticBlueprintPureBlueprintAutocast
Description
Converts an FColor (sRGB, 0–255 per channel) to an FLinearColor (linear, 0.0–1.0 per channel) by applying sRGB gamma decoding. This is the correct path when sending a color from UI or asset data into a material or light.
Caveats & Gotchas
- • The conversion applies sRGB gamma decoding (approximately pow(x/255, 2.2)), NOT a simple divide-by-255. If you just want to divide by 255 without gamma correction, use FLinearColor(R/255.f, G/255.f, B/255.f, A/255.f) manually.
- • FColor's alpha channel is copied as-is divided by 255 without gamma correction — only RGB components are gamma-decoded. This is the standard convention but can cause subtle errors if you're using alpha to encode linear intensity.
- • FColor stores bytes in BGRA order on most platforms, while FLinearColor stores floats in RGBA order. This function handles the reordering, but direct byte-cast tricks between the two types will give wrong channel assignments.
Signature
static UE_INL_API FLinearColor Conv_ColorToLinearColor(FColor InColor) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InColor | FColor | The sRGB 8-bit-per-channel colour to convert. | — |
Return Type
FLinearColor Example
Set a dynamic material parameter from an asset colour C++
FColor AssetColor = MyDataAsset->TintColor; // sRGB FColor from an asset
FLinearColor LinearTint = UKismetMathLibrary::Conv_ColorToLinearColor(AssetColor);
MaterialInstance->SetVectorParameterValue(TEXT("Tint"), LinearTint); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?