The issue I came across is that when importing models in a Blender scene, Blender assumes that the color values are linear, so the imported models get in with washed out colors.
This happens both with external formats (dae fbx obj 3ds etc) and even with old Blender formats (2.49 and before).
I opened a thread at blender.org for this issue and they say the problem is that i/o scripts are not CM aware so Blender fails importing srgb colors. They will add CM capabilities to i/o scripts in a future release. see https://developer.blender.org/T43025
But meanwhile, since I need a way to use my old models in actual Blender scenes, does anyone know of a fast way to convert srgb to linear ? Actually I have to correct every single color by hand and this is a real PITA. Thank you in advance for any help you could provide.
The issue I came across is that when importing models in a Blender scene, Blender assumes that the color values are linear, so the imported models get in with washed out colors.
This happens both with external formats (dae fbx obj 3ds etc) and even with old Blender formats (2.49 and before).
I opened a thread at blender.org for this issue and they say the problem is that i/o scripts are not CM aware so Blender fails importing srgb colors. They will add CM capabilities to i/o scripts in a future release. see https://developer.blender.org/T43025
But meanwhile, since I need a way to use my old models in actual Blender scenes, does anyone know of a fast way to convert srgb to linear ? Actually I have to correct every single color by hand and this is a real PITA. Thank you in advance for any help you could provide.
best regards, Alessandro
p.s. just found a link for srgb-linear conversion math, don’t know if this could be useful to write a script http://entropymine.com/imageworsener/srgbformula/
Actually I just copy and paste the HEX values between none and srgb display device and this works fine, but as I said I have to do it by hand for every color and it’s a PITA.
print ('Color S RGB to Linear RFB')
print ()
def s2lin(x):
a = 0.055
if x <=0.04045 :
y = x * (1.0 / 12.92)
else:
y = pow( (x + a) * (1.0 / (1 + a)), 2.4)
return y
x = 0.1
z = s2lin(x)
print ('x =', x, 'z =',z)
print ()
print ('Linear RGB to S RGB')
print ()
def lin2s(x):
a = 0.055
if x <=0.0031308:
y = x * 12.92
else:
y = (1 + a) * pow(x, 1 / 2.4) - a
return y
x = 0.1
z = lin2s(x)
print ('x =', x, 'z =',z)
print ()
Seems very interesting !! Unfortunately I can’t write a script myself since I don’t know python and/or the Blender API. So I’m looking for a kind coder who could solve the issue for the community. It would be enough to have two scripts:
srgb_to_linear: to convert srgb values of current selection to linear values
linear_to_srgb: to convert back
These two scripts alone could provide the artist with a powerful tool to fix any import/export issue Blender actually has. Are you a coder ? Could any of you please code those scripts ?
p.s. just found a link for srgb-linear conversion math, don’t know if this could be useful to write a script http://entropymine.com/imageworsener/srgbformula/
Actually I just copy and paste the HEX values between none and srgb display device and this works fine, but as I said I have to do it by hand for every color and it’s a PITA.
p.p.s. so actually my workflow to convert from srgb to linear is
turn off CM by setting display device to none
import the srgb model into the scene (dae, fbx, obj etc)
copy the HEX color values for every material in the model
turn on CM by setting display device to srgb
paste back the color values into the HEX slots
as I said this works fine but it’s SLOOOOW way … …
as far as I can understand in the link above vars are rgb values, for example
0 ≤ S ≤ 0.04045 => L = S/12.92
means that when red, green or blue value of srgb (S) is below 0.04045 (from 0 to 1 scale) then the corresponding linear value (L) is S/12.92
for every color I mean the rgb values of every material in the model. For example if the model has 10 materials then I have 10 rgb values to convert.
I’m not sure what you mean for stand alone script. It should be a script that the user could run on the current selection, so inside blender. The script should find all the materials in the current selection and convert the rgb values appropriately.
Cycles or not doesn’t matter at all, it is a CM issue and it affects any render engine you use, cycles, BI and even the opengl render. And it affects material colors only, since srgb textures are already handled the correct way (CM managed)
Please let me know if you need more info … if you could write those scripts it would be very very useful indeed … and of course let me know if I can help in any way
for last link with S L vars
what these represent is RGB ?
S = R L = G and what about B
well I hope someone else has a script already made for that cause
if you have to do that for all Bl mat and may be texture color and what about image color ?
then above that you have all the world colors and then all the cycles mat
and which color is it the one for Diffuse or Spec ?
that is not so easy it is possible but lot’s of work
S is the srgb value of red,green,blue components and L is the linear value of red,green,blue components
What needs to be converted is only the diffuse value of all materials. Cycles or BI doesn’t matter, it is a CM issue so it affects every render engine you use. Textures are already handled fine and don’t need any conversion.
The conversion should be made on selected objects only, so the user can leave alone objects that don’t need any conversion.
Basically, the two scripts should convert the diffuse value of all the materials in the selected objects.
Please let me know if you need more info and if I can help in any way. And thank you very much for your reply. I understand that writing a script is not so easy and takes a lot of time …
I did another small script to change BL diffuse color or spec color
now this is only for material color
and what you said about color is wrong the fact of changing the diffuse won’t affect any other color somewhere else or in cycles!
anyway I can upload the material change script but this does not tell me how to modify the RGB color !
I will try to add this to a small panel in tool pro panel so it is easier to use!
I can read the RGB values but then what do u do with the algo?
do you need to get the HSV and modify the H value ?
if you can work on those scripts it is more than amazing !!
I can’t understand why you say that changing the diffuse color doesn’t affect cycles
or may be I don’t understand what you mean
anyway, this is the math, hope it is clear enough
/* SRGB TO LINEAR
/* this assumes red,green,blue values from 0 to 1
/* and convert srgb red to linear red
/* you need to do the same for green and blue
S = red
if S <= 0.04045 then L = S/12.92 else L = ((S+0.055)/1.055)^2.4
red = L
/* LINEAR TO SRGB
/* this assumes red,green,blue values from 0 to 1
/* and convert linear red to srgb red
/* you need to do the same for green and blue
L = red
if L <= 0.0031308 then S = L12.92 else S = 1.055(L^(1/2.4))-0.055
red = S
If I check the materials on the two cubes they stay at the same colors they had before running the script. Do I have to do something different for testing ? How does the script work ?
for your easy testing 0.5 srgb (80 hex) = 0.216 linear
so if you
turn display device to none
set material to dark red (0.5,0,0)
run the srgb_to_linear script
if the script works well then you should get rgb changed to 0.216,0,0
please let me know if you need more info and/or if I can help … and thank you so much for your work so far !!
what do you mean by turn display device to none
how to do that and where ?
to run the script
select one cube
then text editor run script
after look in tool pro panel - there is a new panel
select menu and select first or second option
then click on the bottom button call custom object
have to find a better name for this run button
after you do that you should see a new cube added with the converted color !
Well !! The script works fine with a one color cube the first time I use it. It converts the color just fine !!
If I use the script more than one time on the same source cube, then the generated cube becomes darker and darker. But may be in this first version you didn’t planned a multiple use of the script.
Also, the script works odd with the 3 colors cube you provide in the scene. If I run the script on the 3 colors cube it generates a blue cube. But may be in this first version you didn’t support a multiple materials object.
The effect you see when importing a 2.49 object is the CM issue Blender suffers right now and it is the reason why your script is needed. Blender 2.5x-2.7x reads the 2.49 colors as linear values, while 2.49 uses srgb values. This also applies to any imported format (dae,fbx,obj,3ds etc). Blender always reads colors as linear values, and this is wrong since those formats use srgb values.
So to import an object you have to
turn off CM by setting display device to none
import the object (blender 2.49,dae,fbx,obj,3ds etc)
run the srgb_to_linear script
turn on CM by setting display device to srgb
You can find the display device settings in: scene tab > color management > display device
I am ready to test your next script versions ! And good job so far !