Fix T78745: Cycles error baking with multiple materials

This commit is contained in:
Brecht Van Lommel 2020-07-09 12:20:07 +02:00
parent 8ddf7556a5
commit 544c435fdd
Notes: blender-bot 2023-02-13 22:20:49 +01:00
Referenced by issue #78745, Emit Baking Bug_2.83.1
1 changed files with 9 additions and 15 deletions

View File

@ -694,14 +694,7 @@ void RE_bake_pixels_populate(Mesh *me,
const BakeImages *bake_images,
const char *uv_layer)
{
BakeDataZSpan bd;
size_t i;
int a, p_id;
const MLoopUV *mloopuv;
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *looptri;
if ((uv_layer == NULL) || (uv_layer[0] == '\0')) {
mloopuv = CustomData_get_layer(&me->ldata, CD_MLOOPUV);
}
@ -714,25 +707,26 @@ void RE_bake_pixels_populate(Mesh *me,
return;
}
BakeDataZSpan bd;
bd.pixel_array = pixel_array;
bd.zspan = MEM_callocN(sizeof(ZSpan) * bake_images->size, "bake zspan");
/* initialize all pixel arrays so we know which ones are 'blank' */
for (i = 0; i < num_pixels; i++) {
for (int i = 0; i < num_pixels; i++) {
pixel_array[i].primitive_id = -1;
pixel_array[i].object_id = 0;
}
for (i = 0; i < bake_images->size; i++) {
for (int i = 0; i < bake_images->size; i++) {
zbuf_alloc_span(&bd.zspan[i], bake_images->data[i].width, bake_images->data[i].height);
}
looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
MLoopTri *looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri);
p_id = -1;
for (i = 0; i < tottri; i++) {
for (int i = 0; i < tottri; i++) {
const MLoopTri *lt = &looptri[i];
const MPoly *mp = &me->mpoly[lt->poly];
float vec[3][2];
@ -744,9 +738,9 @@ void RE_bake_pixels_populate(Mesh *me,
}
bd.bk_image = &bake_images->data[image_id];
bd.primitive_id = ++p_id;
bd.primitive_id = i;
for (a = 0; a < 3; a++) {
for (int a = 0; a < 3; a++) {
const float *uv = mloopuv[lt->tri[a]].uv;
/* Note, workaround for pixel aligned UVs which are common and can screw up our
@ -761,7 +755,7 @@ void RE_bake_pixels_populate(Mesh *me,
zspan_scanconvert(&bd.zspan[image_id], (void *)&bd, vec[0], vec[1], vec[2], store_bake_pixel);
}
for (i = 0; i < bake_images->size; i++) {
for (int i = 0; i < bake_images->size; i++) {
zbuf_free_span(&bd.zspan[i]);
}