Color Management: fixed color management-less texture rendering
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 10 Oct 2012 05:56:49 +0000 (05:56 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 10 Oct 2012 05:56:49 +0000 (05:56 +0000)
There was a missing check for whether color management enabled or not when
converting byte textures to linear space.

This commit also fixes wrong texture preview rendering, which was applying
sRGB transform twice, making procedural textures bright. This will make
float textures being previewed dark (in a linear space) but that's how it
used to behave in pre-OCIO color management.

source/blender/editors/render/render_preview.c
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/envmap.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_texture.c

index 817067422afb685b88e0dca0d52e67a541ec40bf..96276d5eb1bf99da575e8b273f8e0b5c36dcf73e 100644 (file)
@@ -273,16 +273,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                
                /* exception: don't apply render part of display transform for texture previews or icons */
                if ((id && sp->pr_method == PR_ICON_RENDER) || id_type == ID_TE) {
-                       ColorManagedDisplaySettings *display_settings = &sce->display_settings;
-                       ColorManagedViewSettings *view_settings = &sce->view_settings;
-
-                       const char *default_view_name = IMB_colormanagement_view_get_default_name(display_settings->display_device);
-
-                       view_settings->exposure = 0.0f;
-                       view_settings->gamma = 1.0f;
-                       view_settings->flag &= ~COLORMANAGE_VIEW_USE_CURVES;
-
-                       BLI_strncpy(view_settings->view_transform, default_view_name, sizeof(view_settings->view_transform));
+                       BKE_scene_disable_color_management(sce);
                }
                
                if ((id && sp->pr_method == PR_ICON_RENDER) && id_type != ID_WO)
@@ -550,7 +541,7 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
                                         *            color managed as well?
                                         */
                                        IMB_buffer_byte_from_float(rect_byte, rres.rectf,
-                                                                  4, dither, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB, do_predivide,
+                                                                  4, dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, do_predivide,
                                                                   rres.rectx, rres.recty, rres.rectx, rres.rectx);
                                }
 
index 85dbd9356f4813af5377868e441940e67b5e9bd1..8474d9ff09e7c1dc106213070a941981a2d8e262 100644 (file)
@@ -120,6 +120,9 @@ struct Render
        /* state settings */
        short flag, osa, ok, result_ok;
        
+       /* due to performance issues, getting initialized from color management settings once on Render initialization */
+       short scene_color_manage;
+       
        /* result of rendering */
        RenderResult *result;
        /* if render with single-layer option, other rendered layers are stored here */
index 03eb21dfa232a9adee3afd0b558ef4b103807fec..96b33a0bf1aa10b7b1408509208d67cb6dfa6732 100644 (file)
@@ -154,6 +154,7 @@ static Render *envmap_render_copy(Render *re, EnvMap *env)
        
        RE_InitState(envre, NULL, &envre->r, NULL, cuberes, cuberes, NULL);
        envre->scene = re->scene;    /* unsure about this... */
+       envre->scene_color_manage = re->scene_color_manage;
        envre->lay = re->lay;
 
        /* view stuff in env render */
index 1859de0039d4c09220b64484c1e135a87e05947a..84d57aa7d099fc222e7738a0715b07642aec34ff 100644 (file)
@@ -1519,6 +1519,7 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree)
        
        re->main = bmain;
        re->scene = sce;
+       re->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
        
        /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */
        
@@ -2014,6 +2015,7 @@ static int render_initialize_from_main(Render *re, Main *bmain, Scene *scene, Sc
        
        re->main = bmain;
        re->scene = scene;
+       re->scene_color_manage = BKE_scene_check_color_management_enabled(scene);
        re->camera_override = camera_override;
        re->lay = lay;
        
@@ -2352,6 +2354,7 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
 
        re->main = bmain;
        re->scene = sce;
+       re->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
        re->lay = sce->lay;
 
        camera = RE_GetCamera(re);
@@ -2396,6 +2399,7 @@ int RE_ReadRenderResult(Scene *scene, Scene *scenode)
                re = RE_NewRender(scene->id.name);
        RE_InitState(re, NULL, &scene->r, NULL, winx, winy, &disprect);
        re->scene = scene;
+       re->scene_color_manage = BKE_scene_check_color_management_enabled(scene);
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
        success = render_result_exr_file_read(re, 0);
index 0511b03b42d5821829ff5e2e1be9ec6c7df9a272..3e2ce95af50ecae6e35f0b7e81ae463fcebabb8d 100644 (file)
@@ -1234,7 +1234,7 @@ int multitex_nodes(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex,
                                ImBuf *ibuf = BKE_image_get_ibuf(tex->ima, &tex->iuser);
                                
                                /* don't linearize float buffers, assumed to be linear */
-                               if (ibuf && !(ibuf->rect_float))
+                               if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
                                        IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace);
                        }
                }
@@ -2384,7 +2384,7 @@ void do_material_tex(ShadeInput *shi, Render *re)
                                        ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser);
                                        
                                        /* don't linearize float buffers, assumed to be linear */
-                                       if (ibuf && !(ibuf->rect_float))
+                                       if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
                                                IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace);
                                }
                                
@@ -2896,7 +2896,7 @@ void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
                        ImBuf *ibuf = BKE_image_get_ibuf(ima, &mtex->tex->iuser);
                        
                        /* don't linearize float buffers, assumed to be linear */
-                       if (ibuf && !(ibuf->rect_float))
+                       if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
                                IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace);
                }
 
@@ -3115,7 +3115,7 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h
                                        ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser);
                                        
                                        /* don't linearize float buffers, assumed to be linear */
-                                       if (ibuf && !(ibuf->rect_float))
+                                       if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
                                                IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace);
                                }
 
@@ -3329,7 +3329,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r
                                        ImBuf *ibuf = BKE_image_get_ibuf(ima, &tex->iuser);
                                        
                                        /* don't linearize float buffers, assumed to be linear */
-                                       if (ibuf && !(ibuf->rect_float))
+                                       if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
                                                IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace);
                                }