I play a game called Ark: Survival Evolved. I have recently come across the export function in game that allows a print out of a creatures stats, including color codes.
A following is an example of what is output upon export.
[Colorization]
ColorSet[0]=(R=0.002428,G=0.088656,B=0.124772,A=0.000000)
ColorSet[1]=(R=0.100000,G=0.020000,B=0.020000,A=0.000000)
ColorSet[2]=(R=1.000000,G=0.215861,B=0.000000,A=0.000000)
ColorSet[3]=(R=0.002428,G=0.088656,B=0.124772,A=0.000000)
ColorSet[4]=(R=0.225000,G=0.011337,B=0.005625,A=0.000000)
ColorSet[5]=(R=1.000000,G=0.391573,B=0.039546,A=0.000000)
Upon further digging I've realized that this is a Unreal color value, and can not be easily converted to an HTML acceptable RGB/RGBA/Hexidecimal datatype. There is a program that is already made called ArkStatsExtractor that parses the data from the creatures exported file to that program that makes it easily readable.
Looking into their code, I have found this function (in this file) that appears to do the heavy lifting of converting this value into an RGB color code.
/// <summary>
/// Convert the color definition of the unreal engine to default RGB-values
/// </summary>
/// <param name="lc"></param>
/// <returns></returns>
private static int LinearColorComponentToColorComponentClamped(double lc)
{
//int v = (int)(255.999f * (lc <= 0.0031308f ? lc * 12.92f : Math.Pow(lc, 1.0f / 2.4f) * 1.055f - 0.055f)); // this formula is only used since UE4.15
// ARK uses this simplified formula
int v = (int)(255.999f * Math.Pow(lc, 1f / 2.2f));
if (v > 255) return 255;
if (v < 0) return 0;
return v;
}
I'm using PHP as the servers backend to do this conversion. So, I understand the basic functionality of this method. V
is equal to value, and the equation is type casted to an integer value, then does some math. However my understanding of C# is absolutely nothing, and I don't understand how the method gets the final value.
I basically need this line here, made into a PHP function that returns the RGB, or one portion of RGB (0-255) that I can then use to formulate the actual RGB value, and pass that along to my database.
int v = (int)(255.999f * Math.Pow(lc, 1f / 2.2f));
Some of my questions are:
- Why is there a letter
f
after some of the values in this mathematical equation? - What exactly does Math.Pow do? Is this a Unreal function, or is this a function that is custom made by the owner of the repo.
- Is there more information needed to complete this conversion? Something in another file maybe?