[Bf-blender-cvs] [dd1a880] bake-cycles: Cycles-Bake: Cycles-Bake: Margin (image bleeding)
Dalai Felinto
noreply at git.blender.org
Wed Apr 23 02:47:10 CEST 2014
Commit: dd1a880462f919b6bf2b57932a0702011c4350ba
Author: Dalai Felinto
Date: Mon Feb 10 17:54:38 2014 -0200
https://developer.blender.org/rBdd1a880462f919b6bf2b57932a0702011c4350ba
Cycles-Bake: Cycles-Bake: Margin (image bleeding)
===================================================================
M intern/cycles/kernel/kernel_displace.h
M source/blender/editors/object/object_bake_new.c
M source/blender/render/extern/include/RE_bake.h
M source/blender/render/intern/source/bake_new.c
===================================================================
diff --git a/intern/cycles/kernel/kernel_displace.h b/intern/cycles/kernel/kernel_displace.h
index 2e06d13..260ba60 100644
--- a/intern/cycles/kernel/kernel_displace.h
+++ b/intern/cycles/kernel/kernel_displace.h
@@ -104,8 +104,6 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
/* write output */
if (type == SHADER_EVAL_NORMAL)
output[i] = make_float4(0.5f, 0.5f, 1.f, 0.0f);
- else if (type == SHADER_EVAL_AO)
- output[i] = make_float4(1.0f, 1.0f, 1.0f, 1.0f);
else
output[i] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
return;
diff --git a/source/blender/editors/object/object_bake_new.c b/source/blender/editors/object/object_bake_new.c
index b3b77cb..3ab587d 100644
--- a/source/blender/editors/object/object_bake_new.c
+++ b/source/blender/editors/object/object_bake_new.c
@@ -122,7 +122,7 @@ static int bake_break(void *UNUSED(rjv))
return 0;
}
-static bool write_external_bake_pixels(const char *filepath, float *buffer, const int width, const int height, const int depth, bool is_linear)
+static bool write_external_bake_pixels(const char *filepath, BakePixel pixel_array[], float *buffer, const int width, const int height, const int depth, bool is_linear, const int margin)
{
ImBuf *ibuf = NULL;
short ok = FALSE;
@@ -154,6 +154,9 @@ static bool write_external_bake_pixels(const char *filepath, float *buffer, cons
/* setup the Imbuf*/
ibuf->ftype = PNG;
+ /* margins */
+ RE_bake_margin(pixel_array, ibuf, margin, width, height);
+
if ((ok=IMB_saveiff(ibuf, filepath, IB_rect))) {
#ifndef WIN32
chmod(filepath, S_IRUSR | S_IWUSR);
@@ -197,6 +200,7 @@ static int bake_exec(bContext *C, wmOperator *op)
const int height = RNA_int_get(op->ptr, "height");
const int num_pixels = width * height;
const int depth = RE_pass_depth(pass_type);
+ const int margin = RNA_int_get(op->ptr, "margin");
const bool is_external = RNA_boolean_get(op->ptr, "is_save_external");
const bool is_linear = is_data_pass(pass_type);
char filepath[FILE_MAX];
@@ -263,7 +267,7 @@ static int bake_exec(bContext *C, wmOperator *op)
/* save the result */
if (is_external) {
/* save it externally */
- ok = write_external_bake_pixels(filepath, result, width, height, depth, is_linear);
+ ok = write_external_bake_pixels(filepath, pixel_array, result, width, height, depth, is_linear, margin);
if (!ok) {
char *error = NULL;
error = BLI_sprintfN("Problem saving baked map in \"%s\".", filepath);
@@ -371,4 +375,5 @@ void OBJECT_OT_bake(wmOperatorType *ot)
ot->prop = RNA_def_string_file_path(ot->srna, "filepath", "", FILE_MAX, "Path", "Image filepath to use when saving externally");
ot->prop = RNA_def_int(ot->srna, "width", 512, 1, INT_MAX, "Width", "Horizontal dimension of the baking map", 64, 4096);
ot->prop = RNA_def_int(ot->srna, "height", 512, 1, INT_MAX, "Height", "Vertical dimension of the baking map", 64, 4096);
+ ot->prop = RNA_def_int(ot->srna, "margin", 16, 0, INT_MAX, "Margin", "Extends the baked result as a post process filter", 0, 64);
}
diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h
index f2bf179..71e82c0 100644
--- a/source/blender/render/extern/include/RE_bake.h
+++ b/source/blender/render/extern/include/RE_bake.h
@@ -52,4 +52,6 @@ bool RE_internal_bake(struct Render *re, struct Object *object, struct BakePixel
void RE_populate_bake_pixels(struct Object *object, struct BakePixel pixel_array[], const int width, const int height);
+void RE_bake_margin(struct BakePixel pixel_array[], struct ImBuf *ibuf, const int margin, const int width, const int height);
+
#endif
diff --git a/source/blender/render/intern/source/bake_new.c b/source/blender/render/intern/source/bake_new.c
index 1920521..88be967 100644
--- a/source/blender/render/intern/source/bake_new.c
+++ b/source/blender/render/intern/source/bake_new.c
@@ -101,6 +101,29 @@ static void store_bake_pixel(void *handle, int x, int y, float u, float v)
0.f;
}
+void RE_bake_margin(BakePixel pixel_array[], ImBuf *ibuf, const int margin, const int width, const int height)
+{
+ char *mask_buffer = NULL;
+ const int num_pixels = width * height;
+ int i;
+
+ if (margin < 1)
+ 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;
+ }
+ }
+
+ RE_bake_ibuf_filter(ibuf, mask_buffer, margin);
+
+ MEM_freeN(mask_buffer);
+}
+
void RE_populate_bake_pixels(Object *object, BakePixel pixel_array[], const int width, const int height)
{
BakeData bd;
More information about the Bf-blender-cvs
mailing list