Support for baking vertex colors to textures.
authorAntony Riakiotakis <kalast@gmail.com>
Thu, 10 Oct 2013 11:00:12 +0000 (11:00 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Thu, 10 Oct 2013 11:00:12 +0000 (11:00 +0000)
It allows effects such as baking vertex dirt maps to textures.
Also vertex based painting painting may be faster in the future,
so this is useful to have.

Thanks to Sergey for the review!

source/blender/makesrna/intern/rna_scene.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/bake.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/shadeinput.c

index 573175e57e5f36998f2009c33f71e246574e3f8b..738ccb50c47fbbd4baf21a91821098e4bd9d5a28 100644 (file)
@@ -4089,6 +4089,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
                {RE_BAKE_TEXTURE, "TEXTURE", 0, "Textures", "Bake textures"},
                {RE_BAKE_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Bake displacement"},
                {RE_BAKE_DERIVATIVE, "DERIVATIVE", 0, "Derivative", "Bake derivative map"},
+               {RE_BAKE_VERTEX_COLORS, "VERTEX_COLORS", 0, "Vertex Colors", "Bake vertex colors"},
                {RE_BAKE_EMIT, "EMIT", 0, "Emission", "Bake Emit values (glow)"},
                {RE_BAKE_ALPHA, "ALPHA", 0, "Alpha", "Bake Alpha values (transparency)"},
                {RE_BAKE_MIRROR_INTENSITY, "MIRROR_INTENSITY", 0, "Mirror Intensity", "Bake Mirror values"},
index 35d971ab976054f477fd342d9c80576f34f8c179..19757ff083ae5af14867a84c317d586e0a273ce9 100644 (file)
@@ -281,7 +281,8 @@ int RE_seq_render_active(struct Scene *scene, struct RenderData *rd);
 #define RE_BAKE_MIRROR_INTENSITY       10
 #define RE_BAKE_ALPHA                          11
 #define RE_BAKE_EMIT                           12
-#define RE_BAKE_DERIVATIVE             13
+#define RE_BAKE_DERIVATIVE                     13
+#define RE_BAKE_VERTEX_COLORS          14
 
 void RE_Database_Baking(struct Render *re, struct Main *bmain, struct Scene *scene, unsigned int lay, const int type, struct Object *actob);
 
index 42dc9bcdfb23a4400c3cc3711d66e033dc9e64de..92ec891c3df4a053a46da0bfe170f6bbb69a4545 100644 (file)
@@ -621,6 +621,7 @@ typedef struct LampRen {
 #define R_BAKE_TRACE   32
 #define R_BAKING               64
 #define R_ANIMATION            128
+#define R_NEED_VCOL            256
 
 /* vlakren->flag (vlak = face in dutch) char!!! */
 #define R_SMOOTH               1
index f4bbdb6add87ddbc76d026b90ba2f23f6965065f..70659e09ab10641fd2278fa3879e7862b50be1b1 100644 (file)
@@ -168,7 +168,7 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua
        else {
                if (bs->type == RE_BAKE_SHADOW) /* Why do shadows set the color anyhow?, ignore material color for baking */
                        shi->r = shi->g = shi->b = 1.0f;
-       
+
                shade_input_set_shade_texco(shi);
                
                /* only do AO for a full bake (and obviously AO bakes)
@@ -260,6 +260,10 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(qua
                        copy_v3_fl(shr.combined, shi->emit);
                        shr.alpha = 1.0f;
                }
+               else if (bs->type == RE_BAKE_VERTEX_COLORS) {
+                       copy_v3_v3(shr.combined, shi->vcol);
+                       shr.alpha = 1.0;
+               }
        }
        
        if (bs->rect_float && !bs->vcol) {
index b5377a078481ab0658db5c31a45177d21eef18d7..6ab61343c081919d229663fc49e76a465cc0e811 100644 (file)
@@ -5982,6 +5982,7 @@ void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned
  * RE_BAKE_NORMALS:for baking, no lamps and only selected objects
  * RE_BAKE_AO:     for baking, no lamps, but all objects
  * RE_BAKE_TEXTURE:for baking, no lamps, only selected objects
+ * RE_BAKE_VERTEX_COLORS:for baking, no lamps, only selected objects
  * RE_BAKE_DISPLACEMENT:for baking, no lamps, only selected objects
  * RE_BAKE_DERIVATIVE:for baking, no lamps, only selected objects
  * RE_BAKE_SHADOW: for baking, only shadows, but all objects
@@ -5991,8 +5992,8 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay,
        Object *camera;
        float mat[4][4];
        float amb[3];
-       const short onlyselected= !ELEM4(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW, RE_BAKE_AO);
-       const short nolamps= ELEM4(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE);
+       const short onlyselected= !ELEM5(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW, RE_BAKE_AO, RE_BAKE_VERTEX_COLORS);
+       const short nolamps= ELEM5(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS);
 
        re->main= bmain;
        re->scene= scene;
@@ -6010,8 +6011,11 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay,
 
        if (type==RE_BAKE_NORMALS && re->r.bake_normal_space==R_BAKE_SPACE_TANGENT)
                re->flag |= R_NEED_TANGENT;
-       
-       if (!actob && ELEM5(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
+
+       if (type==RE_BAKE_VERTEX_COLORS)
+               re->flag |=  R_NEED_VCOL;
+
+       if (!actob && ELEM6(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS)) {
                re->r.mode &= ~R_SHADOW;
                re->r.mode &= ~R_RAYTRACE;
        }
index 2dcb55f1f5d5778d1c711c18a4347bb14fb68730..bc9ba348c6277b6d02171cae97a088bebcba5713 100644 (file)
@@ -1002,7 +1002,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
        }
 
        /* pass option forces UV calc */
-       if (shi->passflag & SCE_PASS_UV)
+       if ((shi->passflag & SCE_PASS_UV) || (R.flag & R_NEED_VCOL))
                texco |= (NEED_UV | TEXCO_UV);
        
        /* texture coordinates. shi->dxuv shi->dyuv have been set */
@@ -1056,7 +1056,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                        }
                }
                                
-               if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE))) {
+               if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) || (R.flag & R_NEED_VCOL)) {
                        VlakRen *vlr = shi->vlr;
                        MTFace *tface;
                        MCol *mcol;
@@ -1071,7 +1071,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                        shi->actuv = obr->actmtface;
                        shi->actcol = obr->actmcol;
 
-                       if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) {
+                       if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) || (R.flag & R_NEED_VCOL)) {
                                for (i = 0; (mcol = RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) {
                                        ShadeInputCol *scol = &shi->col[i];
                                        char *cp1, *cp2, *cp3;
@@ -1213,7 +1213,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                        }
 
                                        if ((mode & MA_FACETEXTURE) && i == obr->actmtface) {
-                                               if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) {
+                                               if (((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) && ((R.flag & R_NEED_VCOL) == 0)) {
                                                        shi->vcol[0] = 1.0f;
                                                        shi->vcol[1] = 1.0f;
                                                        shi->vcol[2] = 1.0f;
@@ -1299,7 +1299,7 @@ void shade_input_set_shade_texco(ShadeInput *shi)
         * else un-initialized values are used
         */
        if (shi->do_manage) {
-               if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) {
+               if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) || (R.flag & R_NEED_VCOL)) {
                        srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol);
                }
        }