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 !
I use RGB-Linear2.blend, that should be version 2.
Yes, if you can make a script that changes the colors directly on the selected object I guess it is more easy to test.
Setting the display device (none, srgb, rec709) is needed to correctly use the CM. If you don’t need the CM then you can leave display device to none.
2.4x uses the srgb space, while 2.7x can use srgb or rec709 depending on the display device you use.
ok let me till this night
will make a new version
sorry never really look at this bug for color
have a lot of old 2.49 files but I always add my own cycles mat !
so no color problems !
srgb to linear works just fine, I can import any srgb model and convert it to linear values !
unfortunately linear to srgb seems to have some problems, it doesn’t convert well
test it yourself with the dark red value
dark red srgb = 0.5,0,0
dark red linear = 0.214,0,0
so if you convert 0.5,0,0 from srgb to linear you get 0.214,0,0 that is right
while if you convert 0.214,0,0 from linear to srgb you get 0.95,0,0 that is wrong since you should get 0.5,0,0
may be you didn’t code correctly the math in python …
/* 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
the order of evaluation is important:
you first need to do 1/2.4 that is about 0.4166
then power 0.214 (L) by 0.4166 that is about 0.5260
then multiply 0.5260 by 1.055 that is about 0.5549
then subtract 0.055 from 0.5549 that is about 0.5