Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2013-02-20 19:06:13 +0400
committerAntony Riakiotakis <kalast@gmail.com>2013-02-20 19:06:13 +0400
commitb9333b304ca78cc7abccfd84222b022e214ada41 (patch)
treeeb8f8b9fa40fbbc1cc3505dc81eeaf5fb51a97fd
parent7175549de618a88b8f08678b7003a2a6565b3370 (diff)
Fix visible seams on normal map bake due to clear colour being black:
This is a special case, tangent space normal maps should be cleared to 0.5, 0.5, 1.0. This is good practice but there's no reason why not to automate this (for artists whose bump map fu may be a bit shallow). Thanks to Morten Mikkelsen for reporting.
-rw-r--r--source/blender/editors/object/object_bake.c25
-rw-r--r--source/blender/render/intern/source/bake.c11
2 files changed, 29 insertions, 7 deletions
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index 322ba99593e..a680230fb32 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -257,11 +257,18 @@ static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *l
return dm;
}
-static void clear_images(MTFace *mtface, int totface)
+typedef enum ClearFlag {
+ CLEAR_NORMAL = 1
+} ClearFlag;
+
+
+static void clear_images(MTFace *mtface, int totface, ClearFlag flag)
{
int a;
const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f};
const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f};
+ const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f};
for (a = 0; a < totface; a++)
mtface[a].tpage->id.flag &= ~LIB_DOIT;
@@ -272,7 +279,11 @@ static void clear_images(MTFace *mtface, int totface)
if ((ima->id.flag & LIB_DOIT) == 0) {
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
+ if (flag == CLEAR_NORMAL)
+ IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
+ else
+ IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
+
ima->id.flag |= LIB_DOIT;
BKE_image_release_ibuf(ima, ibuf, NULL);
@@ -300,7 +311,10 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
ob = base->object;
me = (Mesh *)ob->data;
- clear_images(me->mtface, me->totface);
+ if (scene->r.bake_mode == RE_BAKE_NORMALS && scene->r.bake_normal_space == R_BAKE_SPACE_TANGENT)
+ clear_images(me->mtface, me->totface, CLEAR_NORMAL);
+ else
+ clear_images(me->mtface, me->totface, 0);
}
CTX_DATA_END;
}
@@ -395,7 +409,10 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
DerivedMesh *dm = data->lores_dm;
MTFace *mtface = CustomData_get_layer(&dm->faceData, CD_MTFACE);
- clear_images(mtface, dm->getNumTessFaces(dm));
+ if (bkj->mode == RE_BAKE_NORMALS)
+ clear_images(mtface, dm->getNumTessFaces(dm), CLEAR_NORMAL);
+ else
+ clear_images(mtface, dm->getNumTessFaces(dm), 0);
}
}
diff --git a/source/blender/render/intern/source/bake.c b/source/blender/render/intern/source/bake.c
index cb6f9611bfd..7c5d6038e0a 100644
--- a/source/blender/render/intern/source/bake.c
+++ b/source/blender/render/intern/source/bake.c
@@ -648,6 +648,8 @@ static int get_next_bake_face(BakeShade *bs)
ImBuf *ibuf = NULL;
const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f};
const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f};
+ const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f};
tface = RE_vlakren_get_tface(obr, vlr, obr->bakemtface, NULL, 0);
@@ -684,9 +686,12 @@ static int get_next_bake_face(BakeShade *bs)
if (ibuf->rect_float)
imb_freerectImBuf(ibuf);
/* clear image */
- if (R.r.bake_flag & R_BAKE_CLEAR)
- IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
-
+ if (R.r.bake_flag & R_BAKE_CLEAR) {
+ if (R.r.bake_mode == RE_BAKE_NORMALS && R.r.bake_normal_space == R_BAKE_SPACE_TANGENT)
+ IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
+ else
+ IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
+ }
/* might be read by UI to set active image for display */
R.bakebuf = ima;
}