32 bit Float normal map are baked in sRGB instead of Linear #52334

Closed
opened 2017-08-10 12:51:54 +02:00 by Danyl Bekhoucha · 17 comments

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.

linear normal.png

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. ![linear normal.png](https://archive.blender.org/developer/F703525/linear_normal.png)

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @DanylBekhoucha

Added subscriber: @DanylBekhoucha

This issue was referenced by e786ea6419

This issue was referenced by e786ea6419ce92d1e02eb80da990db7aca20b0ab

Added subscriber: @Sergey

Added subscriber: @Sergey

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2017-08-10 14:34:48 +02:00

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.

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.

Added subscriber: @brecht

Added subscriber: @brecht

@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:
P520: (An Untitled Masterwork)

diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 03f71b5..1f3be8d 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -2565,6 +2565,14 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index)
 
 void IMB_colormanagment_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf)
 {
+	/* Don't modify non-color data space, it does not change with file type. */
+	ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
+
+	if (colorspace && colorspace->is_data) {
+		return;
+	}
+
+	/* Get color space from file type. */
 	const ImFileType *type;
 
 	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index 390f250..388c273 100644
--- a/source/blender/imbuf/intern/jp2.c
+++ b/source/blender/imbuf/intern/jp2.c
@@ -588,7 +588,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
 	img_fol_t img_fol; /* only needed for cinema presets */
 	memset(&img_fol, 0, sizeof(img_fol_t));
 	
-	if (ibuf->float_colorspace) {
+	if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
 		/* float buffer was managed already, no need in color space conversion */
 		chanel_colormanage_cb = channel_colormanage_noop;
 	}
diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c
index 503e63a..dded0f7 100644
--- a/source/blender/imbuf/intern/png.c
+++ b/source/blender/imbuf/intern/png.c
@@ -152,7 +152,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 	compression = (int)(((float)(ibuf->foptions.quality) / 11.1111f));
 	compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression);
 
-	if (ibuf->float_colorspace) {
+	if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
 		/* float buffer was managed already, no need in color space conversion */
 		chanel_colormanage_cb = channel_colormanage_noop;
 	}
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index 4368a42..8e5cf80 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -822,7 +822,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
 				/* convert from float source */
 				float rgb[4];
 				
-				if (ibuf->float_colorspace) {
+				if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) {
 					/* float buffer was managed already, no need in color space conversion */
 					copy_v3_v3(rgb, &fromf[from_i]);
 				}

@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: [P520: (An Untitled Masterwork)](https://archive.blender.org/developer/P520.txt) ```diff diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 03f71b5..1f3be8d 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -2565,6 +2565,14 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index) void IMB_colormanagment_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf) { + /* Don't modify non-color data space, it does not change with file type. */ + ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name); + + if (colorspace && colorspace->is_data) { + return; + } + + /* Get color space from file type. */ const ImFileType *type; for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 390f250..388c273 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -588,7 +588,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) img_fol_t img_fol; /* only needed for cinema presets */ memset(&img_fol, 0, sizeof(img_fol_t)); - if (ibuf->float_colorspace) { + if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) { /* float buffer was managed already, no need in color space conversion */ chanel_colormanage_cb = channel_colormanage_noop; } diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 503e63a..dded0f7 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -152,7 +152,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) compression = (int)(((float)(ibuf->foptions.quality) / 11.1111f)); compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression); - if (ibuf->float_colorspace) { + if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) { /* float buffer was managed already, no need in color space conversion */ chanel_colormanage_cb = channel_colormanage_noop; } diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 4368a42..8e5cf80 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -822,7 +822,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) /* convert from float source */ float rgb[4]; - if (ibuf->float_colorspace) { + if (ibuf->float_colorspace || (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA)) { /* float buffer was managed already, no need in color space conversion */ copy_v3_v3(rgb, &fromf[from_i]); } ```

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

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

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'

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.

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.

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.

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.

Added subscriber: @BrentLiu

Added subscriber: @BrentLiu

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.

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.

Added subscriber: @IngmarFranz

Added subscriber: @IngmarFranz

This comment was removed by @IngmarFranz

*This comment was removed by @IngmarFranz*
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#52334
No description provided.