[Bf-blender-cvs] [993f316] bake-cycles: Cycles-Bake: "Clear" option fully supported
Dalai Felinto
noreply at git.blender.org
Sat Apr 26 02:45:58 CEST 2014
Commit: 993f316d79171973399cbfbf2379b78004943369
Author: Dalai Felinto
Date: Fri Apr 25 21:44:57 2014 -0300
https://developer.blender.org/rB993f316d79171973399cbfbf2379b78004943369
Cycles-Bake: "Clear" option fully supported
===================================================================
M source/blender/editors/object/object_bake_api.c
M source/blender/render/extern/include/RE_bake.h
M source/blender/render/intern/source/bake_api.c
===================================================================
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index 54eb267..077e8e8 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -123,40 +123,71 @@ static int bake_break(void *UNUSED(rjv))
static bool write_internal_bake_pixels(
Image *image, BakePixel pixel_array[], float *buffer,
- const int width, const int height, const bool is_linear, const int margin)
+ const int width, const int height, const bool is_linear,
+ const int margin, const bool is_clear)
{
ImBuf *ibuf;
void *lock;
bool is_float;
+ char *mask_buffer = NULL;
+ const int num_pixels = width * height;
ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
if (!ibuf)
return false;
- is_float = false;
+ is_float = (ibuf->flags & IB_rectfloat);
+
+ if (margin > 0 || !is_clear) {
+ mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "Bake Mask");
+ RE_bake_mask_fill(pixel_array, num_pixels, mask_buffer);
+ }
/* populates the ImBuf */
- if (is_float) {
- IMB_buffer_float_from_float(
- ibuf->rect_float, buffer, ibuf->channels,
- IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
- ibuf->x, ibuf->y, ibuf->x, ibuf->y
- );
+ if (is_clear) {
+ if (is_float) {
+ IMB_buffer_float_from_float(
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y
+ );
+ }
+ else {
+ IMB_buffer_byte_from_float(
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
+ );
+ }
}
else {
- IMB_buffer_byte_from_float(
- (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
- (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
- false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
- );
+ if (is_float) {
+ IMB_buffer_float_from_float_mask(
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y, mask_buffer
+ );
+ }
+ else {
+ IMB_buffer_byte_from_float_mask(
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x, mask_buffer
+ );
+ }
}
/* margins */
- RE_bake_margin(pixel_array, ibuf, margin, width, height);
+ if (margin > 0)
+ RE_bake_margin(ibuf, mask_buffer, margin);
ibuf->userflags |= IB_BITMAPDIRTY;
BKE_image_release_ibuf(image, ibuf, NULL);
+
+ if (mask_buffer)
+ MEM_freeN(mask_buffer);
+
return true;
}
@@ -173,27 +204,38 @@ static bool write_external_bake_pixels(
/* create a new ImBuf */
ibuf = IMB_allocImBuf(width, height, im_format->planes, (is_float ? IB_rectfloat : IB_rect));
+
if (!ibuf)
return false;
/* populates the ImBuf */
if (is_float) {
IMB_buffer_float_from_float(
- ibuf->rect_float, buffer, ibuf->channels,
- IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
- ibuf->x, ibuf->y, ibuf->x, ibuf->y
- );
+ ibuf->rect_float, buffer, ibuf->channels,
+ IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false,
+ ibuf->x, ibuf->y, ibuf->x, ibuf->y
+ );
}
else {
IMB_buffer_byte_from_float(
- (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
- (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
- false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
- );
+ (unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither,
+ (is_linear ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB), IB_PROFILE_LINEAR_RGB,
+ false, ibuf->x, ibuf->y, ibuf->x, ibuf->x
+ );
}
/* margins */
- RE_bake_margin(pixel_array, ibuf, margin, width, height);
+ if (margin > 0) {
+ char *mask_buffer = NULL;
+ int num_pixels = width * height;
+
+ mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "Bake Mask");
+ RE_bake_mask_fill(pixel_array, num_pixels, mask_buffer);
+ RE_bake_margin(ibuf, mask_buffer, margin);
+
+ if (mask_buffer)
+ MEM_freeN(mask_buffer);
+ }
if ((ok = BKE_imbuf_write(ibuf, filepath, im_format))) {
#ifndef WIN32
@@ -611,7 +653,7 @@ static int bake_exec(bContext *C, wmOperator *op)
BakeImage *image = &images[i];
if (is_save_internal) {
- ok = write_internal_bake_pixels(image->image, pixel_array_low + image->offset, result + image->offset * depth, image->width, image->height, is_linear, margin);
+ ok = write_internal_bake_pixels(image->image, pixel_array_low + image->offset, result + image->offset * depth, image->width, image->height, is_linear, margin, is_clear);
if (!ok) {
BKE_report(op->reports, RPT_ERROR, "Problem saving the bake map internally, make sure there is a Texture Image node in the current object material");
diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h
index 5eee739..d589c42 100644
--- a/source/blender/render/extern/include/RE_bake.h
+++ b/source/blender/render/extern/include/RE_bake.h
@@ -78,7 +78,9 @@ void RE_populate_bake_pixels_from_objects(struct Mesh *me_low, BakePixel pixel_a
void RE_populate_bake_pixels(struct Mesh *me, struct BakePixel *pixel_array, const int num_pixels, const struct BakeImage *images);
-void RE_bake_margin(const BakePixel pixel_array[], struct ImBuf *ibuf, const int margin, const int width, const int height);
+void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask);
+
+void RE_bake_margin(struct ImBuf *ibuf, char *mask, const int margin);
void RE_normal_world_to_object(const BakePixel pixel_array[], const int num_pixels, const int depth, float result[], struct Object *ob, const BakeNormalSwizzle normal_swizzle[3]);
void RE_normal_world_to_tangent(const BakePixel pixel_array[], const int num_pixels, const int depth, float result[], struct Mesh *me, const BakeNormalSwizzle normal_swizzle[3]);
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index 998ca13..fbe72d4 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -125,32 +125,28 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v)
0.0f;
}
-void RE_bake_margin(const BakePixel pixel_array[], ImBuf *ibuf, const int margin, const int width, const int height)
+void RE_bake_mask_fill(const BakePixel pixel_array[], const int num_pixels, char *mask)
{
- char *mask_buffer = NULL;
- const int num_pixels = width * height;
int i;
-
- if (margin < 1)
+ if (!mask)
return;
- mask_buffer = MEM_callocN(sizeof(char) * num_pixels, "BakeMask");
-
/* only extend to pixels outside the mask area */
for (i = 0; i < num_pixels; i++) {
if (pixel_array[i].primitive_id != -1) {
- mask_buffer[i] = FILTER_MASK_USED;
+ mask[i] = FILTER_MASK_USED;
}
}
+}
+void RE_bake_margin(ImBuf *ibuf, char *mask, const int margin)
+{
/* margin */
- IMB_filter_extend(ibuf, mask_buffer, margin);
+ IMB_filter_extend(ibuf, mask, margin);
if (ibuf->planes != R_IMF_PLANES_RGBA)
/* clear alpha added by filtering */
IMB_rectfill_alpha(ibuf, 1.0f);
-
- MEM_freeN(mask_buffer);
}
/*
More information about the Bf-blender-cvs
mailing list