Bugfix #24335
authorTon Roosendaal <ton@blender.org>
Fri, 12 Nov 2010 14:59:01 +0000 (14:59 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 12 Nov 2010 14:59:01 +0000 (14:59 +0000)
ZCombine node in compositor ignored alpha values. Enabling it
would break compatibility though, so it's a tickbox option now.

Patch provided by reporter, Martin Lubich. Thanks!

source/blender/editors/space_node/drawnode.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/makesrna/rna_cleanup/rna_properties.txt
source/blender/nodes/intern/CMP_nodes/CMP_zcombine.c

index 6293605..85c1daf 100644 (file)
@@ -776,6 +776,15 @@ static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C),
        uiItemR(col, ptr, "premul", 0, NULL, 0);
 }
 
+static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{      
+       uiLayout *col;
+       
+       col =uiLayoutColumn(layout, 1);
+       uiItemR(col, ptr, "use_alpha", 0, NULL, 0);
+}
+
+
 static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
        uiLayout *col;
@@ -1149,6 +1158,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                case CMP_NODE_HUECORRECT:
                        ntype->uifunc=node_composit_buts_huecorrect;
                         break;
+               case CMP_NODE_ZCOMBINE:
+                       ntype->uifunc=node_composit_buts_zcombine;
+                        break;
                default:
                        ntype->uifunc= NULL;
        }
index 52a19c6..325362d 100644 (file)
@@ -2034,6 +2034,16 @@ static void def_cmp_huecorrect(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 }
 
+static void def_cmp_zcombine(StructRNA *srna)
+{
+       PropertyRNA *prop;
+       
+       prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "custom1", 0);
+       RNA_def_property_ui_text(prop, "Use Alpha", "Takes Alpha channel into account when doing the Z operation");
+       RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+}
+
 
 /* -- Texture Nodes --------------------------------------------------------- */
 
index f824f6f..679a5fc 100644 (file)
@@ -71,7 +71,7 @@ DefNode( CompositorNode, CMP_NODE_COMPOSITE,      0,                      "COMPO
 DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    def_cmp_output_file,    "OUTPUT_FILE",    OutputFile,       "Output File",       ""              )
 DefNode( CompositorNode, CMP_NODE_TEXTURE,        def_texture,            "TEXTURE",        Texture,          "Texture",           ""              )
 DefNode( CompositorNode, CMP_NODE_TRANSLATE,      0,                      "TRANSLATE",      Translate,        "Translate",         ""              )
-DefNode( CompositorNode, CMP_NODE_ZCOMBINE,       0,                      "ZCOMBINE",       Zcombine,         "Z Combine",         ""              )
+DefNode( CompositorNode, CMP_NODE_ZCOMBINE,       def_cmp_zcombine,              "ZCOMBINE",       Zcombine,         "Z Combine",         ""              )
 DefNode( CompositorNode, CMP_NODE_COMBRGBA,       0,                      "COMBRGBA",       CombRGBA,         "Combine RGBA",      ""              )
 DefNode( CompositorNode, CMP_NODE_DILATEERODE,    def_cmp_dilate_erode,   "DILATEERODE",    DilateErode,      "Dilate/Erode",      ""              )
 DefNode( CompositorNode, CMP_NODE_ROTATE,         def_cmp_rotate,         "ROTATE",         Rotate,           "Rotate",            ""              )
index 92adbf4..df833d8 100644 (file)
 #+ * Node|CompositorNode.type -> type:   enum,  "(read-only)"
 #+ * Node|CompositorNode|CompositorNodeAlphaOver.premul -> premul:   float  "Mix Factor"
 #Node|CompositorNode|CompositorNodeAlphaOver.use_premultiply -> use_premultiply:   boolean  "NO DESCRIPTION"
+#Node|CompositorNode|CompositorNodeZcombine.use_alpha -> use_alpha:   boolean  "NO DESCRIPTION"
 #+ * Node|CompositorNode|CompositorNodeBilateralblur.iterations -> iterations:   int  "NO DESCRIPTION"
 #+ * Node|CompositorNode|CompositorNodeBilateralblur.sigma_color -> sigma_color:   float  "NO DESCRIPTION"
 #+ * Node|CompositorNode|CompositorNodeBilateralblur.sigma_space -> sigma_space:   float  "NO DESCRIPTION"
index 80989fe..17d8854 100644 (file)
@@ -31,7 +31,7 @@
 
 
 /* **************** Z COMBINE ******************** */
-       /* lazy coder note: node->custom1 is abused to send signal */
+       /* lazy coder note: node->custom2 is abused to send signal */
 static bNodeSocketType cmp_node_zcombine_in[]= {
        {       SOCK_RGBA, 1, "Image",          0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
        {       SOCK_VALUE, 1, "Z",                     0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 10000.0f},
@@ -47,13 +47,40 @@ static bNodeSocketType cmp_node_zcombine_out[]= {
 
 static void do_zcombine(bNode *node, float *out, float *src1, float *z1, float *src2, float *z2)
 {
+       float alpha;
+       float malpha;
+       
        if(*z1 <= *z2) {
-               QUATCOPY(out, src1);
+               if (node->custom1) {
+                       // use alpha in combine operation
+                       alpha= src1[3];
+                       malpha= 1.0f - alpha;
+                       out[0]= malpha*src2[0] + alpha*src1[0];
+                       out[1]= malpha*src2[1] + alpha*src1[1];
+                       out[2]= malpha*src2[2] + alpha*src1[2];
+                       out[3]= malpha*src2[3] + alpha*src1[3];
+               }
+               else {
+                       // do combination based solely on z value
+                       QUATCOPY(out, src1);
+               }
        }
        else {
-               QUATCOPY(out, src2);
+               if (node->custom1) {
+                       // use alpha in combine operation
+                       alpha= src2[3];
+                       malpha= 1.0f - alpha;
+                       out[0]= malpha*src1[0] + alpha*src2[0];
+                       out[1]= malpha*src1[1] + alpha*src2[1];
+                       out[2]= malpha*src1[2] + alpha*src2[2];
+                       out[3]= malpha*src1[3] + alpha*src2[3];
+               }
+               else {
+                       // do combination based solely on z value
+                       QUATCOPY(out, src1);
+               }
                
-               if(node->custom1)
+               if(node->custom2)
                        *z1= *z2;
        }
 }
@@ -62,20 +89,49 @@ static void do_zcombine_mask(bNode *node, float *out, float *z1, float *z2)
 {
        if(*z1 > *z2) {
                *out= 1.0f;
-               if(node->custom1)
+               if(node->custom2)
                        *z1= *z2;
        }
 }
 
-static void do_zcombine_add(bNode *UNUSED(node), float *out, float *col1, float *col2, float *acol)
+static void do_zcombine_add(bNode *node, float *out, float *col1, float *col2, float *acol)
 {
-       float alpha= *acol;
-       float malpha= 1.0f - alpha;
-       
-       out[0]= malpha*col1[0] + alpha*col2[0];
-       out[1]= malpha*col1[1] + alpha*col2[1];
-       out[2]= malpha*col1[2] + alpha*col2[2];
-       out[3]= malpha*col1[3] + alpha*col2[3];
+       float alpha;
+       float malpha;
+
+       if (node->custom1) {
+               // use alpha in combine operation, antialiased mask in used here just as hint for the z value
+               if (*acol>0.0f) {
+                       alpha= col2[3];
+                       malpha= 1.0f - alpha;
+               
+               
+                       out[0]= malpha*col1[0] + alpha*col2[0];
+                       out[1]= malpha*col1[1] + alpha*col2[1];
+                       out[2]= malpha*col1[2] + alpha*col2[2];
+                       out[3]= malpha*col1[3] + alpha*col2[3];
+               }
+               else {
+                       alpha= col1[3];
+                       malpha= 1.0f - alpha;
+               
+               
+                       out[0]= malpha*col2[0] + alpha*col1[0];
+                       out[1]= malpha*col2[1] + alpha*col1[1];
+                       out[2]= malpha*col2[2] + alpha*col1[2];
+                       out[3]= malpha*col2[3] + alpha*col1[3];
+               }
+       }
+       else {
+               // do combination based solely on z value but with antialiased mask
+               alpha = *acol;
+               malpha= 1.0f - alpha;
+               
+               out[0]= malpha*col1[0] + alpha*col2[0];
+               out[1]= malpha*col1[1] + alpha*col2[1];
+               out[2]= malpha*col1[2] + alpha*col2[2];
+               out[3]= malpha*col1[3] + alpha*col2[3];
+       }
 }
 
 static void node_composit_exec_zcombine(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
@@ -107,11 +163,11 @@ static void node_composit_exec_zcombine(void *data, bNode *node, bNodeStack **in
                                *zval= in[1]->vec[0];
                }
                /* lazy coder hack */
-               node->custom1= 1;
+               node->custom2= 1;
                out[1]->data= zbuf;
        }
        else {
-               node->custom1= 0;
+               node->custom2= 0;
                zbuf= in[1]->data;
        }