Fix #32404: GLSL normal maps using float images were incorrectly getting
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 30 Aug 2012 17:42:04 +0000 (17:42 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 30 Aug 2012 17:42:04 +0000 (17:42 +0000)
color managed.

12 files changed:
source/blender/editors/space_view3d/drawmesh.c
source/blender/gpu/GPU_draw.h
source/blender/gpu/GPU_extensions.h
source/blender/gpu/GPU_material.h
source/blender/gpu/intern/gpu_codegen.c
source/blender/gpu/intern/gpu_codegen.h
source/blender/gpu/intern/gpu_draw.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/gpu/intern/gpu_material.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

index 5069c4219c3934a4d0e8f79f2f0a296a3a753019..1894dd1ac4efbc1af43d5f663d6e7814dcbb85ad 100644 (file)
@@ -871,7 +871,7 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
        if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) {
                /* get openl texture */
                int mipmap = 1;
-               int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0;
+               int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, FALSE) : 0;
                float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 
                if (bindcode) {
index 7a71f33d3d0bb55592bbf772e503150f2f43240f..467adbe10b8db2afab427156ad089673dab3d87f 100644 (file)
@@ -122,7 +122,7 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap);
 void GPU_paint_update_image(struct Image *ima, int x, int y, int w, int h, int mipmap);
 void GPU_update_images_framechange(void);
 int GPU_update_image_time(struct Image *ima, double time);
-int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap);
+int GPU_verify_image(struct Image *ima, struct ImageUser *iuser, int tftile, int compare, int mipmap, int ncd);
 void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float *frect, int rectw, int recth, int mipmap, int use_hight_bit_depth, struct Image *ima);
 void GPU_create_gl_tex_compressed(unsigned int *bind, unsigned int *pix, int x, int y, int mipmap, struct Image *ima, struct ImBuf *ibuf);
 int GPU_upload_dxt_texture(struct ImBuf *ibuf);
index b04da04258e0a1ad0244c2a6d0e2e937823d3c9e..198d002ff0da57f7f2ed1608afaf952ef6d81ca6 100644 (file)
@@ -111,7 +111,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels);
 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
 GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
 GPUTexture *GPU_texture_from_blender(struct Image *ima,
-       struct ImageUser *iuser, double time, int mipmap);
+       struct ImageUser *iuser, int ncd, double time, int mipmap);
 void GPU_texture_free(GPUTexture *tex);
 
 void GPU_texture_ref(GPUTexture *tex);
index a725ff4385d6fa953a9fa979fd5b3dd93201043d..856b1f83001fe084f51a407d55fa019e054bca4d 100644 (file)
@@ -107,7 +107,7 @@ typedef struct GPUNodeStack {
 GPUNodeLink *GPU_attribute(int type, const char *name);
 GPUNodeLink *GPU_uniform(float *num);
 GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data);
-GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int ncd);
 GPUNodeLink *GPU_texture(int size, float *pixels);
 GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data);
 GPUNodeLink *GPU_socket(GPUNodeStack *sock);
index a88a075383d4d28768ca9d8e1298ad41ad3121bb..25990e8fc6e57a5331cb42492338b988331f6993 100644 (file)
@@ -761,7 +761,7 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
        /* now bind the textures */
        for (input=inputs->first; input; input=input->next) {
                if (input->ima)
-                       input->tex = GPU_texture_from_blender(input->ima, input->iuser, time, mipmap);
+                       input->tex = GPU_texture_from_blender(input->ima, input->iuser, input->imagencd, time, mipmap);
 
                if (input->tex && input->bindtex) {
                        GPU_texture_bind(input->tex, input->texid);
@@ -917,6 +917,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
 
                input->ima = link->ptr1;
                input->iuser = link->ptr2;
+               input->imagencd = link->imagencd;
                input->textarget = GL_TEXTURE_2D;
                input->textype = GPU_TEX2D;
                MEM_freeN(link);
@@ -1109,13 +1110,14 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data)
        return link;
 }
 
-GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser)
+GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, int ncd)
 {
        GPUNodeLink *link = GPU_node_link_create(0);
 
        link->image= 1;
        link->ptr1= ima;
        link->ptr2= iuser;
+       link->imagencd= ncd;
 
        return link;
 }
index db334b8bf19cc0cbdf0c34ff5d2e2f9fe76d779c..3010937a2f391819f1d98bc2d4fcd39d8eb9caa0 100644 (file)
@@ -91,6 +91,7 @@ struct GPUNodeLink {
        const char *attribname;
 
        int image;
+       int imagencd;
 
        int texture;
        int texturesize;
@@ -137,6 +138,7 @@ typedef struct GPUInput {
 
        struct Image *ima;              /* image */
        struct ImageUser *iuser;/* image user */
+       int imagencd;                   /* image does not contain color data */
        float *dynamicvec;              /* vector data in case it is dynamic */
        int dynamictype;                /* origin of the dynamic uniform (GPUDynamicType) */
        void *dynamicdata;              /* data source of the dynamic uniform */
index d03913af417e2c2d08953232233b366b3c7e82d7..4314a784511c784c7b67c57dbbe75e5dfc2610f0 100644 (file)
@@ -422,7 +422,7 @@ static void gpu_verify_reflection(Image *ima)
        }
 }
 
-int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap)
+int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int mipmap, int ncd)
 {
        ImBuf *ibuf = NULL;
        unsigned int *bind = NULL;
@@ -492,7 +492,7 @@ int GPU_verify_image(Image *ima, ImageUser *iuser, int tftile, int compare, int
                }
 
                /* TODO unneeded when float images are correctly treated as linear always */
-               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+               if (!ncd && ibuf->profile == IB_PROFILE_LINEAR_RGB)
                        do_color_management = TRUE;
 
                if (ibuf->rect==NULL)
@@ -807,7 +807,7 @@ int GPU_set_tpage(MTFace *tface, int mipmap, int alphablend)
        gpu_verify_alpha_blend(alphablend);
        gpu_verify_reflection(ima);
 
-       if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap)) {
+       if (GPU_verify_image(ima, NULL, tface->tile, 1, mipmap, FALSE)) {
                GTS.curtile= GTS.tile;
                GTS.curima= GTS.ima;
                GTS.curtilemode= GTS.tilemode;
index 4974d57d64cd32545d3506c9267d90ea858fab8a..c5f427fbcab54b889fb361a5c0e1e7eb5ccd60ca 100644 (file)
@@ -522,7 +522,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
        return tex;
 }
 
-GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time, int mipmap)
+GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int ncd, double time, int mipmap)
 {
        GPUTexture *tex;
        GLint w, h, border, lastbindcode, bindcode;
@@ -530,7 +530,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, double time,
        glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
 
        GPU_update_image_time(ima, time);
-       bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap);
+       bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, ncd);
 
        if (ima->gputexture) {
                ima->gputexture->bindcode = bindcode;
index efb243757297eb2a55db77ce4a2e8e829327ea88..81b80b831660fdf6b2a7d11942b906941b9469d4 100644 (file)
@@ -645,7 +645,7 @@ static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **
 
                        GPU_link(mat, "shade_light_texture",
                                GPU_builtin(GPU_VIEW_POSITION),
-                               GPU_image(mtex->tex->ima, &mtex->tex->iuser),
+                               GPU_image(mtex->tex->ima, &mtex->tex->iuser, FALSE),
                                GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
                                &tex_rgb);
                        texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb); 
@@ -1028,7 +1028,7 @@ static void do_material_tex(GPUShadeInput *shi)
                        talpha = 0;
 
                        if (tex && tex->type == TEX_IMAGE && tex->ima) {
-                               GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser), &tin, &trgb);
+                               GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb);
                                rgbnor= TEX_RGB;
 
                                if (tex->imaflag & TEX_USEALPHA)
@@ -1104,7 +1104,7 @@ static void do_material_tex(GPUShadeInput *shi)
 
                                        if (tex->imaflag & TEX_NORMALMAP) {
                                                /* normalmap image */
-                                               GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser), &tnor);
+                                               GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, TRUE), &tnor);
                                                
                                                if (mtex->norfac < 0.0f)
                                                        GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor);
@@ -1234,26 +1234,26 @@ static void do_material_tex(GPUShadeInput *shi)
                                                
                                                if (found_deriv_map) {
                                                        GPU_link(mat, "mtex_bump_deriv",
-                                                                texco, GPU_image(tex->ima, &tex->iuser), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
+                                                                texco, GPU_image(tex->ima, &tex->iuser, TRUE), GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
                                                                 &dBs, &dBt );
                                                }
                                                else if ( mtex->texflag & MTEX_3TAP_BUMP)
                                                        GPU_link(mat, "mtex_bump_tap3",
-                                                                texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+                                                                texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
                                                                 &dBs, &dBt );
                                                else if ( mtex->texflag & MTEX_5TAP_BUMP)
                                                        GPU_link(mat, "mtex_bump_tap5",
-                                                                texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+                                                                texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
                                                                 &dBs, &dBt );
                                                else if ( mtex->texflag & MTEX_BICUBIC_BUMP ) {
                                                        if (GPU_bicubic_bump_support()) {
                                                                GPU_link(mat, "mtex_bump_bicubic",
-                                                                        texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+                                                                        texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
                                                                         &dBs, &dBt);
                                                        }
                                                        else {
                                                                GPU_link(mat, "mtex_bump_tap5",
-                                                                        texco, GPU_image(tex->ima, &tex->iuser), tnorfac,
+                                                                        texco, GPU_image(tex->ima, &tex->iuser, TRUE), tnorfac,
                                                                         &dBs, &dBt);
                                                        }
                                                }
@@ -1263,7 +1263,7 @@ static void do_material_tex(GPUShadeInput *shi)
                                                        float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x;
                                                        GPU_link(mat, "mtex_bump_apply_texspace",
                                                                 fDet, dBs, dBt, vR1, vR2,
-                                                                GPU_image(tex->ima, &tex->iuser), texco,
+                                                                GPU_image(tex->ima, &tex->iuser, TRUE), texco,
                                                                 GPU_uniform(&imag_tspace_dimension_x), GPU_uniform(&imag_tspace_dimension_y), vNacc,
                                                                 &vNacc, &shi->vn );
                                                }
index 572f06e007b621a1aaa5f632fa68d736ccaff696..e857d0571cdca5926cbf419a5a12257c26843328 100644 (file)
@@ -58,6 +58,8 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod
 {
        Image *ima= (Image*)node->id;
        ImageUser *iuser= NULL;
+       NodeTexImage *tex = node->storage;
+       int ncd = tex->color_space == SHD_COLORSPACE_NONE;
 
        if (!ima)
                return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
@@ -67,7 +69,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNod
 
        node_shader_gpu_tex_mapping(mat, node, in, out);
 
-       return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser));
+       return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, ncd));
 }
 
 /* node type definition */
index 176c50bcabbd500f127b3610887805a3ba76592d..c492fe9efc78b05838bf2fcab32182dcc7cb2dd2 100644 (file)
@@ -58,6 +58,8 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack
 {
        Image *ima= (Image*)node->id;
        ImageUser *iuser= NULL;
+       NodeTexImage *tex = node->storage;
+       int ncd = tex->color_space == SHD_COLORSPACE_NONE;
 
        if (!ima)
                return GPU_stack_link(mat, "node_tex_image_empty", in, out);
@@ -67,7 +69,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack
 
        node_shader_gpu_tex_mapping(mat, node, in, out);
 
-       return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser));
+       return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, ncd));
 }
 
 /* node type definition */
index 3f90d4fbcd5a104da5ce4da73a0ab276aa8a1dad..73c3b846fe3cb80ce82681c4c155aa139ed8bf0d 100644 (file)
@@ -122,7 +122,7 @@ 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);
+               GPUNodeLink *texlink = GPU_image(tex->ima, NULL, FALSE);
                return GPU_stack_link(mat, "texture_image", in, out, texlink);
        }
        else