Good day.
0.5^(1 / 2.2) = ~0.73 * 255 = 186
This is the equation for getting a linear space value (0.5) converted to a gamma space rgb value (186)
I am having trouble doing the opposite. What I want to do is convert a RGB value in Gamma space into a 0-1 linear value
Does anyone know what the formula is?
Thanks in advance.
Cheers.
Replies
255*POWER(linearvalue/255,1/2.2)
Gamma To Linear
255 * POWER(gammavalue / 255,2.2)
That 'linear' has no relation to the data type used to represent the colour value -- whether it's represented by a normalised floating point value (0.0 ~ 1.0) or by an unsigned byte value (0 ~ 255).
Both of these data types can be used to represent both the linear-space and gamma-space RGB values. So you're dealing with two operations: how to convert back-and-forth between data types ( float <---> byte ) and how to convert back-and-forth between RGB spaces ( linear <---> gamma ).
EDIT: This all means that you don't need to convert to the byte range (i.e. multiply by 255) if you only need the result to be in floating point.
All I want to be able to do is get my color choices matching from Photoshop to Unreal engine 4 materials (RGB to 0-1). Also If I find a nice roughness value in Unreal I want to be able to paint that as my base roughness texture map in Photoshop. (0-1 to RGB)
Kryzon: I have no idea what you just said. HAH! I wish I did though.
On second thought Kryzon. That is what I am trying to do. First I need to convert the values from byte (0-255) to float value (0-1) then I need to convert RGB spaces (gamma to linear), I just did not have the proper language. Thanks!
As a side note: Does anyone know of a online converter/calculator that will convert anyRGB value in Photoshop into a Float value and also convert the RGB spaces?
Thanks again!
What you can do is go to Edit -> Colour Settings, and in "Working Spaces," select the "Monitor RGB" option in the RGB field. This turns off the Photoshop colour management and the colours that you pick now should look the same in Unreal.
Now you can click on the colour squares (in the toolbar) to open the extended colour picker, and you can see there the hex code for the currently picked colour. While the picker window is open you can also pick from your layers, you just have to click on the pixels.
Then you can copy the hex value and use it with something like this to get the float version:
http://www.corecoding.com/utilities/rgb-or-hex-to-float.php
EDIT: I think Unreal 4 already does gamma correction internally for you, so you shouldn't have to worry about it.
In any case, this article should explain more. It seems to be a texture property that you set in Unreal:
http://artbyplunkett.com/Unreal/unrealgamma.html#_Toc268114684
That might be helpful.