Fix #32930: texture colors in material nodes (blender internal) are brighter than...
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 22 Oct 2012 17:34:06 +0000 (17:34 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 22 Oct 2012 17:34:06 +0000 (17:34 +0000)
There was a missing byte buffer linearization for shader nodes.

Also fixed incorrect image input color space refresh when image is packed.

source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/imbuf/IMB_colormanagement.h
source/blender/imbuf/intern/colormanagement.c
source/blender/makesrna/intern/rna_color.c
source/blender/nodes/shader/nodes/node_shader_tex_environment.c
source/blender/nodes/shader/nodes/node_shader_tex_image.c
source/blender/nodes/shader/nodes/node_shader_texture.c
source/blender/render/intern/source/render_texture.c

index 5e5f58f73fe8ea1cd555b8ac04890674fe7f0d9f..1875fd666289703c5e9dfd7a5b807c44f44249ea 100644 (file)
@@ -127,6 +127,7 @@ enum {
 #define IMA_SIGNAL_SRC_CHANGE       5
 /* image-user gets a new image, check settings */
 #define IMA_SIGNAL_USER_NEW_IMAGE   6
+#define IMA_SIGNAL_COLORMANAGE      7
 
 #define IMA_CHAN_FLAG_BW    1
 #define IMA_CHAN_FLAG_RGB   2
index d291380b9419c7c46bb807c660722fe9585a4e8f..037f7331f3fd6ccab8c0541eaf934e8a3ece6c67 100644 (file)
@@ -2142,6 +2142,15 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
                                }
                        }
                        break;
+               case IMA_SIGNAL_COLORMANAGE:
+                       image_free_buffers(ima);
+
+                       ima->ok = 1;
+
+                       if (iuser)
+                               iuser->ok = 1;
+
+                       break;
        }
 
        /* don't use notifiers because they are not 100% sure to succeeded
index 0653956e1130d035f61ef0e9b7f492a18039f102..12f23e832c72e05c246aa38ddf5988cf91a81229 100644 (file)
@@ -62,6 +62,8 @@ void IMB_colormanagement_check_is_data(struct ImBuf *ibuf, const char *name);
 void IMB_colormanagement_assign_float_colorspace(struct ImBuf *ibuf, const char *name);
 void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
 
+int IMB_colormanagement_colorspace_is_data(const char *name);
+
 /* ** Color space transformation functions ** */
 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
                                    const char *from_colorspace, const char *to_colorspace, int predivide);
index ff474d85a8c139f22ec4abc9c772f0cdd1ef161d..8cd2a707dd3771b7d604cdf25ede65e0567b36ba 100644 (file)
@@ -1113,6 +1113,13 @@ void IMB_colormanagement_assign_rect_colorspace(ImBuf *ibuf, const char *name)
                ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
 }
 
+int IMB_colormanagement_colorspace_is_data(const char *name)
+{
+       ColorSpace *colorspace = colormanage_colorspace_get_named(name);
+
+       return colorspace->is_data;
+}
+
 /*********************** Threaded display buffer transform routines *************************/
 
 typedef struct DisplayBufferThread {
index 1ba2fc1ee7e68dc51f48a331e0eb1b751dd80af6..d898a5ac5c7e6dd5f799a000bf56393b068fbfc8 100644 (file)
@@ -474,7 +474,9 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain)
        if (GS(id->name) == ID_IM) {
                Image *ima = (Image *) id;
 
-               BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
+               DAG_id_tag_update(&ima->id, 0);
+
+               BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
 
                WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
                WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
index 311ae3a90179aa5d7654e312dc1cea956ceb020e..8c3f243169fcf8009b4b08351c90d1bedb976fcc 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "../node_shader_util.h"
 
+#include "IMB_colormanagement.h"
+
 /* **************** OUTPUT ******************** */
 
 static bNodeSocketTemplate sh_node_tex_environment_in[] = {
@@ -60,6 +62,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod
        ImageUser *iuser= NULL;
        NodeTexImage *tex = node->storage;
        int ncd = tex->color_space == SHD_COLORSPACE_NONE;
+       int ret;
 
        if (!ima)
                return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
@@ -69,10 +72,17 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod
 
        node_shader_gpu_tex_mapping(mat, node, in, out);
 
-       if (out[0].link && GPU_material_do_color_management(mat))
-               GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
+       ret = GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd));
+
+       if (ret) {
+               if (GPU_material_do_color_management(mat) &&
+                   IMB_colormanagement_colorspace_is_data(ima->colorspace_settings.name) == FALSE)
+               {
+                       GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
+               }
+       }
 
-       return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd));
+        return ret;
 }
 
 /* node type definition */
index 52f8c21fbb043a17ceb84c5232168e3ce47a9d51..342e06ff05048fe8e05aa7cdd4b4cbf925f133b2 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "../node_shader_util.h"
 
+#include "IMB_colormanagement.h"
+
 /* **************** OUTPUT ******************** */
 
 static bNodeSocketTemplate sh_node_tex_image_in[] = {
@@ -60,6 +62,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack
        ImageUser *iuser= NULL;
        NodeTexImage *tex = node->storage;
        int ncd = tex->color_space == SHD_COLORSPACE_NONE;
+       int ret;
 
        if (!ima)
                return GPU_stack_link(mat, "node_tex_image_empty", in, out);
@@ -69,10 +72,17 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack
 
        node_shader_gpu_tex_mapping(mat, node, in, out);
 
-       if (out[0].link && GPU_material_do_color_management(mat))
-               GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
+       ret = GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd));
+
+       if (ret) {
+               if (GPU_material_do_color_management(mat) &&
+                   IMB_colormanagement_colorspace_is_data(ima->colorspace_settings.name) == FALSE)
+               {
+                       GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link);
+               }
+       }
 
-       return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd));
+       return ret;
 }
 
 /* node type definition */
index c27a95da5a06d45c1295c4d4c15b8fafca4b98f2..b39f0e62fa9d8da3291b0d60573cab527ffb6cf7 100644 (file)
@@ -32,6 +32,8 @@
 
 #include "DNA_texture_types.h"
 
+#include "IMB_colormanagement.h"
+
 #include "node_shader_util.h"
 
 /* **************** TEXTURE ******************** */
@@ -122,8 +124,18 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, G
        Tex *tex = (Tex*)node->id;
 
        if (tex && tex->type == TEX_IMAGE && tex->ima) {
-               GPUNodeLink *texlink = GPU_image(tex->ima, NULL, FALSE);
-               return GPU_stack_link(mat, "texture_image", in, out, texlink);
+               GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, FALSE);
+               int ret = GPU_stack_link(mat, "texture_image", in, out, texlink);
+
+               if (ret) {
+                       if (GPU_material_do_color_management(mat) &&
+                           IMB_colormanagement_colorspace_is_data(tex->ima->colorspace_settings.name) == FALSE)
+                       {
+                               GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
+                       }
+               }
+
+               return ret;
        }
        else
                return 0;
index dc99ee02a195e9e99e07fc971e5e1c666d551d2b..9cdf7da5a442381d474977abee69377d584c27a6 100644 (file)
@@ -1262,6 +1262,14 @@ int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int os
                        
                        do_2d_mapping(&localmtex, texvec_l, NULL, NULL, dxt_l, dyt_l);
                        rgbnor= multitex(tex, texvec_l, dxt_l, dyt_l, osatex, texres, thread, which_output);
+
+                       {
+                               ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser);
+
+                               /* don't linearize float buffers, assumed to be linear */
+                               if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
+                                       IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace);
+                       }
                }
 
                return rgbnor;