Dynamic Paint:
authorMiika Hamalainen <blender@miikah.org>
Sun, 24 Jul 2011 17:03:33 +0000 (17:03 +0000)
committerMiika Hamalainen <blender@miikah.org>
Sun, 24 Jul 2011 17:03:33 +0000 (17:03 +0000)
* Added alpha support renderer for vertex colors. You can now easily render Dynamic Paint produced vertex colors by checking "Vertex Color" in material options.
* Added "Vertex Alpha" socket for "Geometry" material node.
* Fixed vertex surface color output issues.

source/blender/blenkernel/intern/dynamicpaint.c
source/blender/nodes/intern/SHD_nodes/SHD_geom.c
source/blender/nodes/intern/SHD_util.h
source/blender/render/extern/include/RE_shader_ext.h
source/blender/render/intern/source/shadeinput.c
source/blender/render/intern/source/shadeoutput.c

index f2b4cc7d351ef81904ca75833ad1682381c0722b..ab0e7f8a90d98908c85067ea5d21103786ce7405 100644 (file)
@@ -1272,7 +1272,7 @@ struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, S
                                                /* save layer data to output layer */
 
                                                /* paint layer */
-                                               col = CustomData_get_layer_named(&dm->faceData, CD_MCOL, surface->output_name);
+                                               col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name);
                                                if (col) {
                                                        #pragma omp parallel for schedule(static)
                                                        for (i=0; i<numOfFaces; i++) {
@@ -1288,10 +1288,11 @@ struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, S
                                                                }
                                                        }
                                                }
+                                               
                                                MEM_freeN(fcolor);
 
                                                /* wet layer */
-                                               col = CustomData_get_layer_named(&dm->faceData, CD_MCOL, surface->output_name2);
+                                               col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name2);
                                                if (col) {
                                                        #pragma omp parallel for schedule(static)
                                                        for (i=0; i<numOfFaces; i++) {
index 379f54bec57a2c729f4c3cbd58d0025c07e3ab5b..b349406932ef72068e6e56f3bd6906bc7f88a75d 100644 (file)
@@ -47,6 +47,7 @@ static bNodeSocketType sh_node_geom_out[]= {
        {       SOCK_VECTOR, 0, "UV",   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
        {       SOCK_VECTOR, 0, "Normal",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
        {       SOCK_RGBA,   0, "Vertex Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_VALUE,   0, "Vertex Alpha", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
        {       SOCK_VALUE,   0, "Front/Back", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
        {       -1, 0, ""       }
 };
@@ -93,10 +94,14 @@ static void node_shader_exec_geom(void *data, bNode *node, bNodeStack **UNUSED(i
                        }
 
                        VECCOPY(out[GEOM_OUT_VCOL]->vec, scol->col);
-                       out[GEOM_OUT_VCOL]->vec[3]= 1.0f;
+                       out[GEOM_OUT_VCOL]->vec[3]= scol->col[3];
+
+                       out[GEOM_OUT_VCOL_ALPHA]->vec[0]= scol->col[3];
                }
-               else
+               else {
                        memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol));
+                       out[GEOM_OUT_VCOL_ALPHA]->vec[0]= 1.0f;
+               }
                
                if(shi->osatex) {
                        out[GEOM_OUT_GLOB]->data= shi->dxgl;
index e6b1377067d79c024c1555c69085e2d20dbf2274..d137b1d7d87f2beeca921f02fd25ccd64222e213 100644 (file)
@@ -94,6 +94,7 @@ typedef struct ShaderCallData {
 #define GEOM_OUT_NORMAL        5
 #define GEOM_OUT_VCOL  6
 #define GEOM_OUT_FRONTBACK     7
+#define GEOM_OUT_VCOL_ALPHA    8
 
 
 /* input socket defines */
index 8df9e707dc7c4d4c77dda1b06134609c34b6877e..13c9706ddc0305c167e1ef6cd2cf7e7e8f012ea7 100644 (file)
@@ -92,7 +92,7 @@ typedef struct ShadeInputUV {
 } ShadeInputUV;
 
 typedef struct ShadeInputCol {
-       float col[3];
+       float col[4];
        char *name;
 } ShadeInputCol;
 
index eab66aaf2ec166fbb16480bba7d4c68e94c86a21..5ef340be89b7c024909b32d8bd2dc65fb9c0781e 100644 (file)
@@ -473,17 +473,20 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert
                                        scol->col[0]= cp[3]/255.0f;
                                        scol->col[1]= cp[2]/255.0f;
                                        scol->col[2]= cp[1]/255.0f;
+                                       scol->col[3]= cp[0]/255.0f;
                                }
 
                                if(shi->totcol) {
                                        shi->vcol[0]= shi->col[shi->actcol].col[0];
                                        shi->vcol[1]= shi->col[shi->actcol].col[1];
                                        shi->vcol[2]= shi->col[shi->actcol].col[2];
+                                       shi->vcol[3]= shi->col[shi->actcol].col[3];
                                }
                                else {
                                        shi->vcol[0]= 0.0f;
                                        shi->vcol[1]= 0.0f;
                                        shi->vcol[2]= 0.0f;
+                                       shi->vcol[3]= 0.0f;
                                }
                        }
 
@@ -516,6 +519,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert
                                                shi->vcol[0]= 1.0f;
                                                shi->vcol[1]= 1.0f;
                                                shi->vcol[2]= 1.0f;
+                                               shi->vcol[3]= 1.0f;
                                        }
                                }
                        }
@@ -532,6 +536,7 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert
                                        shi->vcol[0]= 1.0f;
                                        shi->vcol[1]= 1.0f;
                                        shi->vcol[2]= 1.0f;
+                                       shi->vcol[3]= 1.0f;
                                }
                        }
 
@@ -1111,13 +1116,14 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                        scol->col[0]= (l*((float)cp3[3]) - u*((float)cp1[3]) - v*((float)cp2[3]))/255.0f;
                                        scol->col[1]= (l*((float)cp3[2]) - u*((float)cp1[2]) - v*((float)cp2[2]))/255.0f;
                                        scol->col[2]= (l*((float)cp3[1]) - u*((float)cp1[1]) - v*((float)cp2[1]))/255.0f;
+                                       scol->col[3]= (l*((float)cp3[0]) - u*((float)cp1[0]) - v*((float)cp2[0]))/255.0f;
                                }
 
                                if(shi->totcol) {
                                        shi->vcol[0]= shi->col[shi->actcol].col[0];
                                        shi->vcol[1]= shi->col[shi->actcol].col[1];
                                        shi->vcol[2]= shi->col[shi->actcol].col[2];
-                                       shi->vcol[3]= 1.0f;
+                                       shi->vcol[3]= shi->col[shi->actcol].col[3];
                                }
                                else {
                                        shi->vcol[0]= 0.0f;
index 7f921d210411cac3001a0b752c7b55b9f0bd5331..5f6efcbcf1a119f8f424ae99050240982ed814c9 100644 (file)
@@ -865,13 +865,19 @@ void shade_color(ShadeInput *shi, ShadeResult *shr)
 {
        Material *ma= shi->mat;
 
-       if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) {
+       if(ma->mode & (MA_FACETEXTURE)) {
                shi->r= shi->vcol[0];
                shi->g= shi->vcol[1];
                shi->b= shi->vcol[2];
                if(ma->mode & (MA_FACETEXTURE_ALPHA))
                        shi->alpha= shi->vcol[3];
        }
+       else if(ma->mode & (MA_VERTEXCOLP)) {
+               float inv_alpha = 1.0f - shi->vcol[3];
+               shi->r= shi->r*inv_alpha + shi->vcol[0]*shi->vcol[3];
+               shi->g= shi->g*inv_alpha + shi->vcol[1]*shi->vcol[3];
+               shi->b= shi->b*inv_alpha + shi->vcol[2]*shi->vcol[3];
+       }
        
        if(ma->texco)
                do_material_tex(shi);
@@ -1649,12 +1655,18 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
        
        /* material color itself */
        if(passflag & (SCE_PASS_COMBINED|SCE_PASS_RGBA)) {
-               if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) {
+               if(ma->mode & (MA_FACETEXTURE)) {
                        shi->r= shi->vcol[0];
                        shi->g= shi->vcol[1];
                        shi->b= shi->vcol[2];
                        if(ma->mode & (MA_FACETEXTURE_ALPHA))
-                               shi->alpha= (shi->mode & MA_TRANSP) ? shi->vcol[3] : 1.0f;
+                               shi->alpha= shi->vcol[3];
+               }
+               else if(ma->mode & (MA_VERTEXCOLP)) {
+                       float inv_alpha = 1.0f - shi->vcol[3];
+                       shi->r= shi->r*inv_alpha + shi->vcol[0]*shi->vcol[3];
+                       shi->g= shi->g*inv_alpha + shi->vcol[1]*shi->vcol[3];
+                       shi->b= shi->b*inv_alpha + shi->vcol[2]*shi->vcol[3];
                }
                if(ma->texco){
                        do_material_tex(shi);