Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_bake_api.c
| Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | if (sa && sa->spacetype == SPACE_IMAGE) { /* in case the user changed while baking */ | ||||
| if (sima) | if (sima) | ||||
| sima->image = image; | sima->image = image; | ||||
| } | } | ||||
| } | } | ||||
| static bool write_internal_bake_pixels( | static bool write_internal_bake_pixels( | ||||
| Image *image, BakePixel pixel_array[], float *buffer, | Image *image, BakePixel pixel_array[], float *buffer, | ||||
| const int width, const int height, const int margin, | const int width, const int height, const int margin, | ||||
| const bool is_clear, const bool is_noncolor) | const bool is_clear, const bool is_noncolor, const float dither) | ||||
| { | { | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| void *lock; | void *lock; | ||||
| bool is_float; | bool is_float; | ||||
| char *mask_buffer = NULL; | char *mask_buffer = NULL; | ||||
| const size_t num_pixels = (size_t)width * (size_t)height; | const size_t num_pixels = (size_t)width * (size_t)height; | ||||
| ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); | ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); | ||||
| Show All 21 Lines | else | ||||
| to_colorspace = IMB_colormanagement_get_rect_colorspace(ibuf); | to_colorspace = IMB_colormanagement_get_rect_colorspace(ibuf); | ||||
| if (from_colorspace != to_colorspace) | if (from_colorspace != to_colorspace) | ||||
| IMB_colormanagement_transform(buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, to_colorspace, false); | IMB_colormanagement_transform(buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, to_colorspace, false); | ||||
| } | } | ||||
| /* populates the ImBuf */ | /* populates the ImBuf */ | ||||
| if (is_clear) { | if (is_clear) { | ||||
| ibuf->dither = (is_noncolor ? 0.0f : dither); | |||||
| if (is_float) { | if (is_float) { | ||||
| IMB_buffer_float_from_float( | IMB_buffer_float_from_float( | ||||
| ibuf->rect_float, buffer, ibuf->channels, | ibuf->rect_float, buffer, ibuf->channels, | ||||
| IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false, | IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false, | ||||
| ibuf->x, ibuf->y, ibuf->x, ibuf->y); | ibuf->x, ibuf->y, ibuf->x, ibuf->y); | ||||
| } | } | ||||
| else { | else { | ||||
| IMB_buffer_byte_from_float( | IMB_buffer_byte_from_float( | ||||
| ▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | static int bake( | ||||
| const bool is_noncolor = is_noncolor_pass(pass_type); | const bool is_noncolor = is_noncolor_pass(pass_type); | ||||
| const int depth = RE_pass_depth(pass_type); | const int depth = RE_pass_depth(pass_type); | ||||
| BakeImages bake_images = {NULL}; | BakeImages bake_images = {NULL}; | ||||
| size_t num_pixels; | size_t num_pixels; | ||||
| int tot_materials; | int tot_materials; | ||||
| int i; | int i; | ||||
| const float dither = scene->r.dither_intensity; | |||||
| RE_bake_engine_set_engine_parameters(re, bmain, scene); | RE_bake_engine_set_engine_parameters(re, bmain, scene); | ||||
| if (!RE_bake_has_engine(re)) { | if (!RE_bake_has_engine(re)) { | ||||
| BKE_report(reports, RPT_ERROR, "Current render engine does not support baking"); | BKE_report(reports, RPT_ERROR, "Current render engine does not support baking"); | ||||
| goto cleanup; | goto cleanup; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | for (i = 0; i < bake_images.size; i++) { | ||||
| BakeImage *bk_image = &bake_images.data[i]; | BakeImage *bk_image = &bake_images.data[i]; | ||||
| if (is_save_internal) { | if (is_save_internal) { | ||||
| ok = write_internal_bake_pixels( | ok = write_internal_bake_pixels( | ||||
| bk_image->image, | bk_image->image, | ||||
| pixel_array_low + bk_image->offset, | pixel_array_low + bk_image->offset, | ||||
| result + bk_image->offset * depth, | result + bk_image->offset * depth, | ||||
| bk_image->width, bk_image->height, | bk_image->width, bk_image->height, | ||||
| margin, is_clear, is_noncolor); | margin, is_clear, is_noncolor, dither); | ||||
| /* might be read by UI to set active image for display */ | /* might be read by UI to set active image for display */ | ||||
| bake_update_image(sa, bk_image->image); | bake_update_image(sa, bk_image->image); | ||||
| if (!ok) { | if (!ok) { | ||||
| BKE_reportf(reports, RPT_ERROR, | BKE_reportf(reports, RPT_ERROR, | ||||
| "Problem saving the bake map internally for object \"%s\"", ob_low->id.name + 2); | "Problem saving the bake map internally for object \"%s\"", ob_low->id.name + 2); | ||||
| op_result = OPERATOR_CANCELLED; | op_result = OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 453 Lines • Show Last 20 Lines | |||||