Cleanup: refactoring of bake code in preparation of vertex color baking
Split of internal/external image bake target code off into smaller functions and refactor associated data structures for clarity. Designed so that a vertex color bake target is easy to fit in. Also avoid passing in a huge number of arguments into the main baking function, pass a struct instead.
This commit is contained in:
parent
58c697a9ec
commit
0b4fae7a51
File diff suppressed because it is too large
Load Diff
|
@ -39,11 +39,23 @@ typedef struct BakeImage {
|
|||
size_t offset;
|
||||
} BakeImage;
|
||||
|
||||
typedef struct BakeImages {
|
||||
BakeImage *data; /* all the images of an object */
|
||||
int *lookup; /* lookup table from Material to BakeImage */
|
||||
int size;
|
||||
} BakeImages;
|
||||
typedef struct BakeTargets {
|
||||
/* All images of the object. */
|
||||
BakeImage *images;
|
||||
int num_images;
|
||||
|
||||
/* Lookup table from Material number to BakeImage. */
|
||||
int *material_to_image;
|
||||
int num_materials;
|
||||
|
||||
/* Pixel buffer to bake to. */
|
||||
float *result;
|
||||
int num_pixels;
|
||||
int num_channels;
|
||||
|
||||
/* Baking to non-color data image. */
|
||||
bool is_noncolor;
|
||||
} BakeTargets;
|
||||
|
||||
typedef struct BakePixel {
|
||||
int primitive_id, object_id;
|
||||
|
@ -70,8 +82,7 @@ bool RE_bake_engine(struct Render *re,
|
|||
struct Object *object,
|
||||
const int object_id,
|
||||
const BakePixel pixel_array[],
|
||||
const BakeImages *bake_images,
|
||||
const int depth,
|
||||
const BakeTargets *targets,
|
||||
const eScenePassType pass_type,
|
||||
const int pass_filter,
|
||||
float result[]);
|
||||
|
@ -95,7 +106,7 @@ bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low,
|
|||
void RE_bake_pixels_populate(struct Mesh *me,
|
||||
struct BakePixel *pixel_array,
|
||||
const size_t num_pixels,
|
||||
const struct BakeImages *bake_images,
|
||||
const struct BakeTargets *targets,
|
||||
const char *uv_layer);
|
||||
|
||||
void RE_bake_mask_fill(const BakePixel pixel_array[], const size_t num_pixels, char *mask);
|
||||
|
|
|
@ -691,7 +691,7 @@ static void bake_differentials(BakeDataZSpan *bd,
|
|||
void RE_bake_pixels_populate(Mesh *me,
|
||||
BakePixel pixel_array[],
|
||||
const size_t num_pixels,
|
||||
const BakeImages *bake_images,
|
||||
const BakeTargets *targets,
|
||||
const char *uv_layer)
|
||||
{
|
||||
const MLoopUV *mloopuv;
|
||||
|
@ -709,7 +709,7 @@ void RE_bake_pixels_populate(Mesh *me,
|
|||
|
||||
BakeDataZSpan bd;
|
||||
bd.pixel_array = pixel_array;
|
||||
bd.zspan = MEM_callocN(sizeof(ZSpan) * bake_images->size, "bake zspan");
|
||||
bd.zspan = MEM_callocN(sizeof(ZSpan) * targets->num_images, "bake zspan");
|
||||
|
||||
/* initialize all pixel arrays so we know which ones are 'blank' */
|
||||
for (int i = 0; i < num_pixels; i++) {
|
||||
|
@ -717,8 +717,8 @@ void RE_bake_pixels_populate(Mesh *me,
|
|||
pixel_array[i].object_id = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
for (int i = 0; i < targets->num_images; i++) {
|
||||
zbuf_alloc_span(&bd.zspan[i], targets->images[i].width, targets->images[i].height);
|
||||
}
|
||||
|
||||
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
|
||||
|
@ -731,13 +731,13 @@ void RE_bake_pixels_populate(Mesh *me,
|
|||
const MPoly *mp = &me->mpoly[lt->poly];
|
||||
float vec[3][2];
|
||||
int mat_nr = mp->mat_nr;
|
||||
int image_id = bake_images->lookup[mat_nr];
|
||||
int image_id = targets->material_to_image[mat_nr];
|
||||
|
||||
if (image_id < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bd.bk_image = &bake_images->data[image_id];
|
||||
bd.bk_image = &targets->images[image_id];
|
||||
bd.primitive_id = i;
|
||||
|
||||
for (int a = 0; a < 3; a++) {
|
||||
|
@ -755,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 (int i = 0; i < bake_images->size; i++) {
|
||||
for (int i = 0; i < targets->num_images; i++) {
|
||||
zbuf_free_span(&bd.zspan[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -663,8 +663,7 @@ bool RE_bake_engine(Render *re,
|
|||
Object *object,
|
||||
const int object_id,
|
||||
const BakePixel pixel_array[],
|
||||
const BakeImages *bake_images,
|
||||
const int depth,
|
||||
const BakeTargets *targets,
|
||||
const eScenePassType pass_type,
|
||||
const int pass_filter,
|
||||
float result[])
|
||||
|
@ -707,14 +706,14 @@ bool RE_bake_engine(Render *re,
|
|||
type->update(engine, re->main, engine->depsgraph);
|
||||
}
|
||||
|
||||
for (int i = 0; i < bake_images->size; i++) {
|
||||
const BakeImage *image = bake_images->data + i;
|
||||
for (int i = 0; i < targets->num_images; i++) {
|
||||
const BakeImage *image = targets->images + i;
|
||||
|
||||
engine->bake.pixels = pixel_array + image->offset;
|
||||
engine->bake.result = result + image->offset * depth;
|
||||
engine->bake.result = result + image->offset * targets->num_channels;
|
||||
engine->bake.width = image->width;
|
||||
engine->bake.height = image->height;
|
||||
engine->bake.depth = depth;
|
||||
engine->bake.depth = targets->num_channels;
|
||||
engine->bake.object_id = object_id;
|
||||
|
||||
type->bake(
|
||||
|
|
Loading…
Reference in New Issue