Page MenuHome

32 bit Float normal map are baked in sRGB instead of Linear
Closed, ResolvedPublic

Description

When baking an image in 32 bit Float in Cycles or Blender render instead of baking it automatically in Linear like the 8 bit image, Blender bakes it in sRGB so it's unusable by game engines. That's not the only problem, compositing it by fixing the gamma to convert it into Linear generates some artefacts worse than directly baking a 8 bit image.

Related Objects

Event Timeline

Sergey Sharybin (sergey) closed this task as Archived.Aug 10 2017, 2:34 PM
Sergey Sharybin (sergey) claimed this task.

Bake sets raw pixel values. What's most likely happening here is that your 32bit image color space is set to Linear, which would apply Linear to sRGB conversion on display. To properly see your normal map you should set color space to Non-Color.

Brecht Van Lommel (brecht) lowered the priority of this task from Needs Triage by Developer to Needs Information from User.Aug 10 2017, 2:45 PM

@Sergey Sharybin (sergey), saving a generated float non-color data image to PNG seems to change the color space to sRGB though.

I think we can fix that like this:

1diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
2index 03f71b5..1f3be8d 100644
3--- a/source/blender/imbuf/intern/colormanagement.c
4+++ b/source/blender/imbuf/intern/colormanagement.c
5@@ -2565,6 +2565,14 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index)
6
7 void IMB_colormanagment_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf)
8 {
9+ /* Don't modify non-color data space, it does not change with file type. */
10+ ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
11+
12+ if (colorspace && colorspace->is_data) {
13+ return;
14+ }
15+
16+ /* Get color space from file type. */
17 const ImFileType *type;
18
19 for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
20diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
21index 390f250..388c273 100644
22--- a/source/blender/imbuf/intern/jp2.c
23+++ b/source/blender/imbuf/intern/jp2.c
24@@ -588,7 +588,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
25 img_fol_t img_fol; /* only needed for cinema presets */
26 memset(&img_fol, 0, sizeof(img_fol_t));
27
28- if (ibuf->float_colorspace) {
29+ if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
30 /* float buffer was managed already, no need in color space conversion */
31 chanel_colormanage_cb = channel_colormanage_noop;
32 }
33diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
34index 503e63a..dded0f7 100644
35--- a/source/blender/imbuf/intern/png.c
36+++ b/source/blender/imbuf/intern/png.c
37@@ -152,7 +152,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
38 compression = (int)(((float)(ibuf->foptions.quality) / 11.1111f));
39 compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression);
40
41- if (ibuf->float_colorspace) {
42+ if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
43 /* float buffer was managed already, no need in color space conversion */
44 chanel_colormanage_cb = channel_colormanage_noop;
45 }
46diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
47index 4368a42..8e5cf80 100644
48--- a/source/blender/imbuf/intern/tiff.c
49+++ b/source/blender/imbuf/intern/tiff.c
50@@ -822,7 +822,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
51 /* convert from float source */
52 float rgb[4];
53
54- if (ibuf->float_colorspace) {
55+ if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
56 /* float buffer was managed already, no need in color space conversion */
57 copy_v3_v3(rgb, &fromf[from_i]);
58 }

@Brecht Van Lommel (brecht), this is reasonable to not change color space, just technically not a bug. If you tested the code, please commit it.

Maybe not technically a bug, but without it you can't save 32 bit float baked normals maps as an 8 bit image as far as I can tell.

Thank you for the clarification. And yes if I set the image to Raw i see it displayed linearly but when i save it it's converted in sRGB i don't know why. Also if I bake in Raw and switch the color space and go back to raw it's displayed like the sRGB version.

It should be fixed in tomorrow's build on builder.blender.org, if you use Non-Color as the color space. Don't use Raw, that's something else.

Why am I experiencing this in Blender 2.78? Is this truly resolved?

EDIT: Nevermind, I misread the time stamp thinking this was resolved in 2010. I should update to 2.79 or the version of this commit.

Needed this to work correctly for some multi-layer normal map blending workflow for material authoring.