Fix for image transparency backwards compatibility. Now the texture datablock has
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 4 Mar 2013 13:18:14 +0000 (13:18 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 4 Mar 2013 13:18:14 +0000 (13:18 +0000)
a Use Alpha option again. This makes the case where you enabled Premultiply on the
image and disabled Use Alpha on the texture work again.

That's mostly useful when you have a straight alpha image file which has no useful
RGB colors in zero alpha regions (e.g. renders). Then sometimes you don't want to
use the alpha for the texture stack mixing, but you still want to multiply it into
the RGB channels to avoid a blocky transition into zero alpha regions.

This also removes the version patch that copied image datablocks because it's not
reliable and might be causing bug #34434. This does mean we are no longer backwards
compatible for cases where two different texture datablocks with Use Alpha enabled
and disabled where using the same image.

release/scripts/startup/bl_ui/properties_texture.py
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/intern/texture.c
source/blender/blenloader/intern/readfile.c
source/blender/gpu/intern/gpu_material.c
source/blender/makesdna/DNA_texture_types.h
source/blender/makesrna/intern/rna_texture.c
source/blender/render/intern/source/imagetexture.c

index dd30627..2d06440 100644 (file)
@@ -448,6 +448,9 @@ class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
 
         col = split.column()
         col.label(text="Alpha:")
+        row = col.row()
+        row.active = tex.image and tex.image.use_alpha
+        row.prop(tex, "use_alpha", text="Use")
         col.prop(tex, "use_calculate_alpha", text="Calculate")
         col.prop(tex, "invert_alpha", text="Invert")
         col.separator()
index d669094..74f20e2 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         266
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
index 55a0f37..2ae76ea 100644 (file)
@@ -440,7 +440,7 @@ void default_tex(Tex *tex)
        tex->type = TEX_CLOUDS;
        tex->stype = 0;
        tex->flag = TEX_CHECKER_ODD;
-       tex->imaflag = TEX_INTERPOL | TEX_MIPMAP;
+       tex->imaflag = TEX_INTERPOL | TEX_MIPMAP | TEX_USEALPHA;
        tex->extend = TEX_REPEAT;
        tex->cropxmin = tex->cropymin = 0.0;
        tex->cropxmax = tex->cropymax = 1.0;
index 9c6e82c..48e2814 100644 (file)
@@ -8663,8 +8663,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
        if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 5)) {
                Scene *scene;
-               Image *image, *nimage;
-               Tex *tex, *otex;
+               Image *image;
+               Tex *tex;
                bNodeTreeType *ntreetype;
                bNodeTree *ntree;
 
@@ -8711,67 +8711,17 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        else {
                                BKE_image_alpha_mode_from_extension(image);
                        }
-
-                       image->flag &= ~IMA_DONE_TAG;
                }
 
-               /* use alpha flag moved from texture to image datablock */
                for (tex = main->tex.first; tex; tex = tex->id.next) {
                        if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
                                image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
 
-                               /* skip if no image or already tested */
-                               if (!image || (image->flag & (IMA_DONE_TAG|IMA_IGNORE_ALPHA)))
-                                       continue;
-
-                               image->flag |= IMA_DONE_TAG;
-
-                               /* we might have some textures using alpha and others not, so we check if
-                                * they exist and duplicate the image datablock if necessary */
-                               for (otex = main->tex.first; otex; otex = otex->id.next)
-                                       if (otex->type == TEX_IMAGE && (otex->imaflag & TEX_USEALPHA))
-                                               if (image == blo_do_versions_newlibadr(fd, otex->id.lib, otex->ima))
-                                                       break;
-
-                               /* no duplication if the texture and image datablock are not
-                                * from the same .blend file, the image datablock may not have
-                                * been loaded from a library file otherwise */
-                               if (otex && (tex->id.lib == image->id.lib)) {
-                                       /* copy image datablock */
-                                       nimage = BKE_image_copy(main, image);
-                                       nimage->flag |= IMA_IGNORE_ALPHA|IMA_DONE_TAG;
-                                       nimage->id.us--;
-
-                                       /* we need to do some trickery to make file loading think
-                                        * this new datablock is part of file we're loading */
-                                       blo_do_versions_oldnewmap_insert(fd->libmap, nimage, nimage, 0);
-                                       nimage->id.lib = image->id.lib;
-                                       nimage->id.flag |= (image->id.flag & LIB_NEED_LINK);
-
-                                       /* assign new image, and update the users counts accordingly */
-                                       for (otex = main->tex.first; otex; otex = otex->id.next) {
-                                               if (otex->type == TEX_IMAGE && (otex->imaflag & TEX_USEALPHA) == 0) {
-                                                       if (image == blo_do_versions_newlibadr(fd, otex->id.lib, otex->ima)) {
-                                                               if (!(otex->id.flag & LIB_NEED_LINK)) {
-                                                                       image->id.us--;
-                                                                       nimage->id.us++;
-                                                               }
-                                                               otex->ima = nimage;
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                               }
-                               else {
-                                       /* no other textures using alpha, just set the flag */
+                               if (image && (image->flag & IMA_DO_PREMUL) == 0)
                                        image->flag |= IMA_IGNORE_ALPHA;
-                               }
                        }
                }
 
-               for (image = main->image.first; image; image = image->id.next)
-                       image->flag &= ~IMA_DONE_TAG;
-
                ntreetype = ntreeGetType(NTREE_COMPOSIT);
                if (ntreetype && ntreetype->foreach_nodetree)
                        ntreetype->foreach_nodetree(main, fd, do_version_node_straight_image_alpha_workaround);
@@ -8779,6 +8729,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
                        do_version_node_straight_image_alpha_workaround(fd, NULL, ntree);
        }
+       else if (main->versionfile < 266 || (main->versionfile == 266 && main->subversionfile < 1)) {
+               /* texture use alpha was removed for 2.66 but added back again for 2.66a,
+               * for compatibility all textures assumed it to be enabled */
+               Tex *tex;
+
+               for (tex = main->tex.first; tex; tex = tex->id.next)
+                       if (tex->type == TEX_IMAGE)
+                               tex->imaflag |= TEX_USEALPHA;
+       }
 
        if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
                Curve *cu;
index d7ac6fe..636c44d 100644 (file)
@@ -1035,7 +1035,7 @@ static void do_material_tex(GPUShadeInput *shi)
                                GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, FALSE), &tin, &trgb);
                                rgbnor= TEX_RGB;
 
-                               talpha = (tex->ima->flag & IMA_IGNORE_ALPHA) == 0;
+                               talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0);
                        }
                        else {
                                continue;
index ea4f281..dd63e6a 100644 (file)
@@ -340,7 +340,7 @@ typedef struct ColorMapping {
 
 /* imaflag */
 #define TEX_INTERPOL   1
-#define TEX_USEALPHA   2 /* deprecated, used for versioning only */
+#define TEX_USEALPHA   2
 #define TEX_MIPMAP             4
 #define TEX_IMAROT             16
 #define TEX_CALCALPHA  32
index e007fe6..2d1b75a 100644 (file)
@@ -1196,6 +1196,11 @@ static void rna_def_texture_image(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Flip Axis", "Flip the texture's X and Y axis");
        RNA_def_property_update(prop, 0, "rna_Texture_update");
 
+       prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_USEALPHA);
+       RNA_def_property_ui_text(prop, "Use Alpha", "Use the alpha channel information in the image");
+       RNA_def_property_update(prop, 0, "rna_Texture_update");
+
        prop = RNA_def_property(srna, "use_calculate_alpha", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_CALCALPHA);
        RNA_def_property_ui_text(prop, "Calculate Alpha", "Calculate an alpha channel based on RGB values in the image");
index 12286fc..60f5546 100644 (file)
@@ -224,7 +224,7 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul
        }
 
        /* keep this before interpolation [#29761] */
-       if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+       if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
                if ((tex->imaflag & TEX_CALCALPHA) == 0) {
                        texres->talpha = TRUE;
                }
@@ -1098,7 +1098,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex
        /* mipmap test */
        image_mipmap_test(tex, ibuf);
        
-       if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+       if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
                if ((tex->imaflag & TEX_CALCALPHA) == 0)
                        texres->talpha = 1;
        }
@@ -1514,7 +1514,7 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
        /* mipmap test */
        image_mipmap_test(tex, ibuf);
 
-       if (tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
+       if ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0) {
                if ((tex->imaflag & TEX_CALCALPHA) == 0) {
                        texres->talpha = TRUE;
                }