3
$\begingroup$

I am trying to create a set of textures for Web Colors via Python.

The materials I create are plain BSDF with only a color input.

If I look at the colors via the RGB values everything looks fine - they map to the values I used in generating them.

enter image description here

However the HEX value gets gamma corrected,

enter image description here

enter image description here

and does not look consistent with what I would expect (pulled from Wikipedia)

enter image description here

So how can I avoid gamma correction only for specific colors?

$\endgroup$
1

2 Answers 2

4
$\begingroup$

You should put the hex code instead, in your case 800000.

In web sRGB is used, and in Blender - linear colors. Hex color is equal to web color, if you put here hex code of the color it will be converted to linear and R value will be lowered less than 0.5 automatically. Then you can get this values to use in Python.

Linear colors lighter in mid-ranges:

enter image description here

$\endgroup$
2
$\begingroup$

I used a ShareX's Screen Color Picker to find out the color of the maroon stripe you posted:

800000 got copied to clipboard.

Now I create a new project in Blender, go to Shading, and set this color for the cube:

the red component is $0.216$ which in 0-255 scale is $0.216 \times 255 = 55.08$, quite far from 128. But this is actually what you want to happen - Blender converts sRGB color space (BTW, it assumes you measured your color in sRGB color space which is not necessarily correct assumption) to linear color space, because while sRGB is perception-oriented, linear is physical-oriented, and Blender tries its best to be physically accurate. This accuracy is related to things like conservation of energy, however, the color you input is supposed to be the same when you output (render) your image.

...So why isn't it the same when you use a color picker on the cube?

The red is neither 128 nor ~55! The reason is the output is converted from linear color space to yet another, Filmic. To change it, go to Render Properties > Color Management and change View Transform to Standard

Now the color picker shows the same value. You can see it twitching and sometimes being off by 1 - this is due to dithering:

Why does Blender output noise even when rendering only flat colors?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.