What does Mathf.LinearToGammaSpace(float value) actually do? - What is the conversion process?

I find myself unable to predict the outcome of running this function.

I’m using HDR lighting with colour emission values set between 1.5 and 4 across the board. However when I run this function to blend colours together, the emission value either skyrockets to 14 or plummets to below 1, resulting in a non-HDR emission, meaning no surrounding objects absorb the colour.

if I could predict what the result of the conversion would be, I could create an offset in order to keep the emission within a range I like.

To re-iterate, my question is: What does Mathf.LinearToGammaSpace(float value) actually do?
Similarly, I would like to know what Mathf.GammaToLinearSpace(float value) does as well.

Thank you for taking the time to read this! I haven’t been able to find an answer and the API definition is lacklustre to say the least.

Did my answer help? Did it answer your question? I'm just asking back since you haven't yet replied or accepted any answers so we have to assume the question is still open?

1 Answer

1

Well, i suggest you read this article which should cover most of it:

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html

So it calculates:

float GammaToLinearSpace(float f)
{
    return Mathf.Pow(f, 2.2f);
}
float LinearToGammaSpace(float f)
{
    return Mathf.Pow(f, 1f / 2.2f);
}

However since Pow is a quite expensive function they might use a lookup table to speed it up but the exact implementation we might never know. I’ve printed the graphs of my implementation next to Unity’s and they only differ slighly. The values are expected to be in range [0…1]