I’ve looked into this for days now, and can’t figure it out even after extensive googling and looking through blenders sourcecode.
My objective is to take a HEX color and translate that to blender-rgb through a python-script.
So far, I’ve tried calculating the blender-RGB-value (3 decimals ranging from 0 to 1) from the hex color by converting HEX to normal RGB (0 to 255) first, and then dividing it by 255, as such:
[TABLE=“class: grid, width: 500”]
Original input ( a nice shade of blue ):
0033ff
Converting this to normal RGB (0-255):
0, 51, 255
Dividing each number through 255 to get blenderRGB:
0, 0.2, 1
[/TABLE]
However the blender-RGB: (0, 0.2, 1) isn’t the same color as where we started off from. Any suggestions? What am I missing?
If I input the HEX-color ‘0033ff’ in blenders colorpicker directly, it translated to (0, 0.0331, 1), which IS the right color. Only problem is… I need to do it programatically. Please help me, I ran into a mountain here.
See attachment for the color difference (left: wrong color, right: correct color (0033ff)).
Thank you for your reply, I think your idea that it’s gamma correction is spot on, since in the blender color picker it says; “gamma corrected”. I don’t know C, but i’ll try to figure out if the calculation is different from mine. Do you reckon it’s this function that holds the secret?:
Can i ask why blender uses this weird system for color numbers. Why do we need to convert them, almost all applications use regular RGB numbers not a divided version of 255???
1 Like
B.Y.O.B
(Node Preview and LuxCore Addon Developer)
8
Can i ask why blender uses this weird system for color numbers.
a) expressing colors as floats in the range 0…1 is pretty common, not weird.
b) In Blender, it makes sense in some places to be able to enter color values higher than 1.0 (which is called HDR)
But i dont understand why one would use float numbers for these. If you check items from other apps you always need to convert this to a number. Ridiculous!