Refactor: Consolidate baking settings into BakeData

Almost all settings were duplicated between BakeData and RenderData.
The only missing field was the bake type, which is stored as a custom
property in Cycles.

This change:
- Removes unused bake_samples and bake_biasdist.
- Migrates settings like bake_margin to BakeData.
- Switches multires baker to use bake_margin.
- Introduces bake type in the BakeData, the same way how it was
  defined in RenderData::bake_mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/144984
This commit is contained in:
Sergey Sharybin
2025-08-22 19:18:03 +02:00
committed by Sergey Sharybin
parent 1028879ffa
commit 628f53a28c
14 changed files with 139 additions and 217 deletions

View File

@@ -2012,19 +2012,18 @@ class CYCLES_RENDER_PT_bake(CyclesButtonsPanel, Panel):
scene = context.scene
cscene = scene.cycles
cbk = scene.render.bake
rd = scene.render
if rd.use_bake_multires:
if cbk.use_multires:
layout.operator("object.bake_image", icon='RENDER_STILL')
layout.prop(rd, "use_bake_multires")
layout.prop(rd, "bake_type")
layout.prop(cbk, "use_multires")
layout.prop(cbk, "type")
else:
layout.operator("object.bake", icon='RENDER_STILL').type = cscene.bake_type
layout.prop(rd, "use_bake_multires")
layout.prop(cbk, "use_multires")
layout.prop(cscene, "bake_type")
if not rd.use_bake_multires and cscene.bake_type not in {
if not scene.render.bake.use_multires and cscene.bake_type not in {
"AO", "POSITION", "NORMAL", "UV", "ROUGHNESS", "ENVIRONMENT"}:
row = layout.row()
row.prop(cbk, "view_from")
@@ -2042,7 +2041,7 @@ class CYCLES_RENDER_PT_bake_influence(CyclesButtonsPanel, Panel):
scene = context.scene
cscene = scene.cycles
rd = scene.render
if rd.use_bake_multires == False and cscene.bake_type in {
if scene.render.bake.use_multires == False and cscene.bake_type in {
'NORMAL', 'COMBINED', 'DIFFUSE', 'GLOSSY', 'TRANSMISSION'}:
return True
@@ -2097,7 +2096,7 @@ class CYCLES_RENDER_PT_bake_selected_to_active(CyclesButtonsPanel, Panel):
def poll(cls, context):
scene = context.scene
rd = scene.render
return rd.use_bake_multires == False
return rd.bake.use_multires == False
def draw_header(self, context):
scene = context.scene
@@ -2142,14 +2141,12 @@ class CYCLES_RENDER_PT_bake_output(CyclesButtonsPanel, Panel):
layout.use_property_decorate = False # No animation.
scene = context.scene
cscene = scene.cycles
cbk = scene.render.bake
rd = scene.render
if rd.use_bake_multires:
layout.prop(rd, "use_bake_clear", text="Clear Image")
if rd.bake_type in {'DISPLACEMENT', 'VECTOR_DISPLACEMENT'}:
layout.prop(rd, "use_bake_lores_mesh")
if cbk.use_multires:
layout.prop(cbk, "use_clear", text="Clear Image")
if cbk.type in {'DISPLACEMENT', 'VECTOR_DISPLACEMENT'}:
layout.prop(cbk, "use_lores_mesh")
else:
layout.prop(cbk, "target")
if cbk.target == 'IMAGE_TEXTURES':
@@ -2176,22 +2173,14 @@ class CYCLES_RENDER_PT_bake_output_margin(CyclesButtonsPanel, Panel):
scene = context.scene
cscene = scene.cycles
cbk = scene.render.bake
rd = scene.render
if (cscene.bake_type == 'NORMAL' and cbk.normal_space == 'TANGENT') or cscene.bake_type == 'UV':
if rd.use_bake_multires:
layout.prop(rd, "bake_margin", text="Size")
else:
if cbk.target == 'IMAGE_TEXTURES':
layout.prop(cbk, "margin", text="Size")
if cbk.use_multires or cbk.target == 'IMAGE_TEXTURES':
layout.prop(cbk, "margin", text="Size")
else:
if rd.use_bake_multires:
layout.prop(rd, "bake_margin_type", text="Type")
layout.prop(rd, "bake_margin", text="Size")
else:
if cbk.target == 'IMAGE_TEXTURES':
layout.prop(cbk, "margin_type", text="Type")
layout.prop(cbk, "margin", text="Size")
if cbk.use_multires or cbk.target == 'IMAGE_TEXTURES':
layout.prop(cbk, "margin_type", text="Type")
layout.prop(cbk, "margin", text="Size")
class CYCLES_RENDER_PT_debug(CyclesDebugButtonsPanel, Panel):

View File

@@ -27,7 +27,7 @@
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 61
#define BLENDER_FILE_SUBVERSION 62
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -2230,10 +2230,6 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain)
if (scene->ed) {
blender::seq::for_each_callback(&scene->ed->seqbase, strip_set_alpha_mode_cb, nullptr);
}
if (scene->r.bake_samples == 0) {
scene->r.bake_samples = 256;
}
}
LISTBASE_FOREACH (Image *, image, &bmain->images) {

View File

@@ -3292,8 +3292,6 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
if (STR_ELEM(scene->r.engine, "BLENDER_RENDER", "BLENDER_GAME")) {
STRNCPY_UTF8(scene->r.engine, RE_engine_id_BLENDER_EEVEE);
}
scene->r.bake_mode = 0;
}
LISTBASE_FOREACH (Tex *, tex, &bmain->textures) {

View File

@@ -2301,6 +2301,20 @@ void blo_do_versions_500(FileData * /*fd*/, Library * /*lib*/, Main *bmain)
FOREACH_NODETREE_END;
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 500, 62)) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
if (scene->r.bake_flag & R_BAKE_MULTIRES) {
scene->r.bake.type = scene->r.bake_mode;
scene->r.bake.flag |= (scene->r.bake_flag & (R_BAKE_MULTIRES | R_BAKE_LORES_MESH));
scene->r.bake.margin_type = scene->r.bake_margin_type;
scene->r.bake.margin = scene->r.bake_margin;
}
else {
scene->r.bake.type = R_BAKE_NORMALS;
}
}
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.

View File

@@ -1834,17 +1834,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
}
}
}
if (bmain->subversionfile < 4) {
for (sce = static_cast<Scene *>(bmain->scenes.first); sce;
sce = static_cast<Scene *>(sce->id.next))
{
sce->r.bake_mode = 1; /* prevent to include render stuff here */
sce->r.bake_margin = 16;
sce->r.bake_margin_type = R_BAKE_ADJACENT_FACES;
sce->r.bake_flag = R_BAKE_CLEAR;
}
}
}
if (bmain->versionfile <= 243) {

View File

@@ -94,11 +94,9 @@ struct MultiresBakeJob {
/** margin type */
char bake_margin_type;
/** mode of baking (displacement, normals, AO) */
short mode;
eBakeType type;
/** Use low-resolution mesh when baking displacement maps */
bool use_low_resolution_mesh;
/** Bias between object and start ray point when doing AO baking */
float bias;
};
static bool multiresbake_check(bContext *C, wmOperator *op)
@@ -278,17 +276,17 @@ static wmOperatorStatus multiresbake_image_exec_locked(bContext *C, wmOperator *
return OPERATOR_CANCELLED;
}
if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */
if (scene->r.bake.flag & R_BAKE_CLEAR) { /* clear images */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
Object &object = *base->object;
BLI_assert(object.type == OB_MESH);
ClearFlag clear_flag = ClearFlag(0);
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
if (scene->r.bake.type == R_BAKE_NORMALS) {
clear_flag = CLEAR_TANGENT_NORMAL;
}
else if (scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
else if (scene->r.bake.type == R_BAKE_DISPLACEMENT) {
clear_flag = CLEAR_DISPLACEMENT;
}
@@ -309,16 +307,15 @@ static wmOperatorStatus multiresbake_image_exec_locked(bContext *C, wmOperator *
multires_flush_sculpt_updates(&object);
/* Copy data stored in job descriptor. */
bake.bake_margin = scene->r.bake_margin;
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
bake.bake_margin = scene->r.bake.margin;
if (scene->r.bake.type == R_BAKE_NORMALS) {
bake.bake_margin_type = R_BAKE_EXTEND;
}
else {
bake.bake_margin_type = eBakeMarginType(scene->r.bake_margin_type);
bake.bake_margin_type = eBakeMarginType(scene->r.bake.margin_type);
}
bake.mode = scene->r.bake_mode;
bake.use_low_resolution_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
bake.bias = scene->r.bake_biasdist;
bake.type = eBakeType(scene->r.bake.type);
bake.use_low_resolution_mesh = scene->r.bake.flag & R_BAKE_LORES_MESH;
bake.ob_image = bake_object_image_get_array(object);
@@ -347,17 +344,16 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
/* backup scene settings, so their changing in UI would take no effect on baker */
bkj->scene = scene;
bkj->bake_margin = scene->r.bake_margin;
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
bkj->bake_margin = scene->r.bake.margin;
if (scene->r.bake.type == R_BAKE_NORMALS) {
bkj->bake_margin_type = R_BAKE_EXTEND;
}
else {
bkj->bake_margin_type = scene->r.bake_margin_type;
bkj->bake_margin_type = eBakeMarginType(scene->r.bake.margin_type);
}
bkj->mode = scene->r.bake_mode;
bkj->use_low_resolution_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR;
bkj->bias = scene->r.bake_biasdist;
bkj->type = eBakeType(scene->r.bake.type);
bkj->use_low_resolution_mesh = scene->r.bake.flag & R_BAKE_LORES_MESH;
bkj->bake_clear = scene->r.bake.flag & R_BAKE_CLEAR;
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
Object &object = *base->object;
@@ -388,10 +384,10 @@ static void multiresbake_startjob(void *bkv, wmJobWorkerStatus *worker_status)
LISTBASE_FOREACH (MultiresBakerJobData *, data, &bkj->data) {
ClearFlag clear_flag = ClearFlag(0);
if (bkj->mode == RE_BAKE_NORMALS) {
if (bkj->type == R_BAKE_NORMALS) {
clear_flag = CLEAR_TANGENT_NORMAL;
}
else if (bkj->mode == RE_BAKE_DISPLACEMENT) {
else if (bkj->type == R_BAKE_DISPLACEMENT) {
clear_flag = CLEAR_DISPLACEMENT;
}
@@ -405,7 +401,7 @@ static void multiresbake_startjob(void *bkv, wmJobWorkerStatus *worker_status)
/* copy data stored in job descriptor */
bake.bake_margin = bkj->bake_margin;
bake.bake_margin_type = eBakeMarginType(bkj->bake_margin_type);
bake.mode = bkj->mode;
bake.type = bkj->type;
bake.use_low_resolution_mesh = bkj->use_low_resolution_mesh;
bake.ob_image = data->ob_image;
@@ -420,8 +416,6 @@ static void multiresbake_startjob(void *bkv, wmJobWorkerStatus *worker_status)
bake.do_update = &worker_status->do_update;
bake.progress = &worker_status->progress;
bake.bias = bkj->bias;
RE_multires_bake_images(bake);
data->images = bake.images;
@@ -515,13 +509,13 @@ static wmOperatorStatus objects_bake_render_modal(bContext *C,
static bool is_multires_bake(Scene *scene)
{
if (ELEM(scene->r.bake_mode,
RE_BAKE_NORMALS,
RE_BAKE_DISPLACEMENT,
RE_BAKE_VECTOR_DISPLACEMENT,
RE_BAKE_AO))
if (ELEM(scene->r.bake.type,
R_BAKE_NORMALS,
R_BAKE_DISPLACEMENT,
R_BAKE_VECTOR_DISPLACEMENT,
R_BAKE_AO))
{
return scene->r.bake_flag & R_BAKE_MULTIRES;
return scene->r.bake.flag & R_BAKE_MULTIRES;
}
return false;

View File

@@ -29,6 +29,7 @@
{ \
.im_format = _DNA_DEFAULT_ImageFormatData, \
.filepath = "//", \
.type = R_BAKE_NORMALS, \
.flag = R_BAKE_CLEAR, \
.pass_filter = R_BAKE_PASS_FILTER_ALL, \
.width = 512, \
@@ -89,13 +90,6 @@
\
.gauss = 1.5, \
.dither_intensity = 1.0f, \
\
.bake_mode = 0, \
.bake_margin = 16, \
.bake_margin_type = R_BAKE_ADJACENT_FACES, \
.bake_flag = R_BAKE_CLEAR, \
.bake_samples = 256, \
.bake_biasdist = 0.001f, \
\
/* BakeData */ \
.bake = _DNA_DEFAULT_BakeData, \

View File

@@ -653,6 +653,8 @@ typedef struct BakeData {
char filepath[/*FILE_MAX*/ 1024];
int type;
short width, height;
short margin, flag;
@@ -667,11 +669,33 @@ typedef struct BakeData {
char save_mode;
char margin_type;
char view_from;
char _pad[4];
struct Object *cage_object;
} BakeData;
/** #BakeData::type */
typedef enum eBakeType {
R_BAKE_NORMALS = 0,
R_BAKE_DISPLACEMENT = 1,
R_BAKE_AO = 2,
R_BAKE_VECTOR_DISPLACEMENT = 3,
} eBakeType;
/** #BakeData::flag */
enum {
R_BAKE_CLEAR = 1 << 0,
// R_BAKE_OSA = 1 << 1, /* Deprecated. */
R_BAKE_TO_ACTIVE = 1 << 2,
// R_BAKE_NORMALIZE = 1 << 3, /* Deprecated. */
R_BAKE_MULTIRES = 1 << 4,
R_BAKE_LORES_MESH = 1 << 5,
// R_BAKE_VCOL = 1 << 6, /* Deprecated. */
// R_BAKE_USERSCALE = 1 << 7, /* Deprecated. */
R_BAKE_CAGE = 1 << 8,
R_BAKE_SPLIT_MAT = 1 << 9,
R_BAKE_AUTO_NAME = 1 << 10,
};
/** #BakeData::margin_type (char). */
typedef enum eBakeMarginType {
R_BAKE_ADJACENT_FACES = 0,
@@ -720,6 +744,14 @@ typedef enum eBakePassFilter {
R_BAKE_PASS_FILTER_COLOR = (1 << 8),
} eBakePassFilter;
/** #BakeData::normal_space */
enum {
R_BAKE_SPACE_CAMERA = 0,
R_BAKE_SPACE_WORLD = 1,
R_BAKE_SPACE_OBJECT = 2,
R_BAKE_SPACE_TANGENT = 3,
};
#define R_BAKE_PASS_FILTER_ALL (~0)
/** \} */
@@ -849,13 +881,11 @@ typedef struct RenderData {
/** Dither noise intensity. */
float dither_intensity;
/* Bake Render options. */
short bake_mode, bake_flag;
short bake_margin, bake_samples;
short bake_margin_type;
char _pad9[6];
float bake_biasdist;
char _pad10[4];
/** Legacy Bake Render options. */
short bake_mode DNA_DEPRECATED;
short bake_flag DNA_DEPRECATED;
short bake_margin DNA_DEPRECATED;
short bake_margin_type DNA_DEPRECATED;
/**
* Path to render output.
@@ -904,7 +934,7 @@ typedef struct RenderData {
/** Performance Options. */
short perf_flag;
/** Cycles baking. */
/** Baking. */
struct BakeData bake;
int _pad8;
@@ -2329,30 +2359,6 @@ enum {
R_COLOR_MANAGEMENT_UNUSED_1 = (1 << 1),
};
/* bake_mode: same as RE_BAKE_xxx defines. */
/** #RenderData::bake_flag */
enum {
R_BAKE_CLEAR = 1 << 0,
// R_BAKE_OSA = 1 << 1, /* Deprecated. */
R_BAKE_TO_ACTIVE = 1 << 2,
// R_BAKE_NORMALIZE = 1 << 3, /* Deprecated. */
R_BAKE_MULTIRES = 1 << 4,
R_BAKE_LORES_MESH = 1 << 5,
// R_BAKE_VCOL = 1 << 6, /* Deprecated. */
// R_BAKE_USERSCALE = 1 << 7, /* Deprecated. */
R_BAKE_CAGE = 1 << 8,
R_BAKE_SPLIT_MAT = 1 << 9,
R_BAKE_AUTO_NAME = 1 << 10,
};
/** #RenderData::bake_normal_space */
enum {
R_BAKE_SPACE_CAMERA = 0,
R_BAKE_SPACE_WORLD = 1,
R_BAKE_SPACE_OBJECT = 2,
R_BAKE_SPACE_TANGENT = 3,
};
/** #RenderData::line_thickness_mode */
enum {
R_LINE_THICKNESS_ABSOLUTE = 1,

View File

@@ -5832,6 +5832,22 @@ void rna_def_freestyle_settings(BlenderRNA *brna)
static void rna_def_bake_data(BlenderRNA *brna)
{
static const EnumPropertyItem bake_type_items[] = {
//{R_BAKE_AO, "AO", 0, "Ambient Occlusion", "Bake ambient occlusion"},
{R_BAKE_NORMALS, "NORMALS", 0, "Normals", "Bake normals"},
{R_BAKE_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Bake displacement"},
/* TODO(sergey): Uncomment once tangent space displacement is supported. */
/* Use C++ style comment because #if 0 breaks indentation. */
// {RE_BAKE_VECTOR_DISPLACEMENT,
// "VECTOR_DISPLACEMENT",
// 0,
// "Vector Displacement",
// "Bake vector displacement"},
{0, nullptr, 0, nullptr, nullptr},
};
StructRNA *srna;
PropertyRNA *prop;
@@ -5841,6 +5857,11 @@ static void rna_def_bake_data(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Bake Data", "Bake data for a Scene data-block");
RNA_def_struct_path_func(srna, "rna_BakeSettings_path");
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, bake_type_items);
RNA_def_property_ui_text(prop, "Bake Type", "Choose shading information to bake into the image");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "cage_object", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(
prop,
@@ -6014,6 +6035,17 @@ static void rna_def_bake_data(BlenderRNA *brna)
RNA_def_property_enum_items(prop, rna_enum_bake_pass_filter_type_items);
RNA_def_property_ui_text(prop, "Pass Filter", "Passes to include in the active baking pass");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_multires", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", R_BAKE_MULTIRES);
RNA_def_property_ui_text(prop, "Bake from Multires", "Bake directly from multires object");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "use_lores_mesh", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", R_BAKE_LORES_MESH);
RNA_def_property_ui_text(
prop, "Low Resolution Mesh", "Calculate heights against unsubdivided low resolution mesh");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
}
static void rna_def_view_layers(BlenderRNA *brna, PropertyRNA *cprop)
@@ -6748,33 +6780,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
/* Bake */
static const EnumPropertyItem bake_mode_items[] = {
//{RE_BAKE_AO, "AO", 0, "Ambient Occlusion", "Bake ambient occlusion"},
{RE_BAKE_NORMALS, "NORMALS", 0, "Normals", "Bake normals"},
{RE_BAKE_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Bake displacement"},
/* TODO(sergey): Uncomment once tangent space displacement is supported. */
/* Use C++ style comment because #if 0 breaks indentation. */
// {RE_BAKE_VECTOR_DISPLACEMENT,
// "VECTOR_DISPLACEMENT",
// 0,
// "Vector Displacement",
// "Bake vector displacement"},
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem bake_margin_type_items[] = {
{R_BAKE_ADJACENT_FACES,
"ADJACENT_FACES",
0,
"Adjacent Faces",
"Use pixels from adjacent faces across UV seams"},
{R_BAKE_EXTEND, "EXTEND", 0, "Extend", "Extend border pixels outwards"},
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem pixel_size_items[] = {
{0, "AUTO", 0, "Automatic", "Automatic pixel size, depends on the user interface scale"},
{1, "1", 0, "1" BLI_STR_UTF8_MULTIPLICATION_SIGN, "Render at full resolution"},
@@ -7259,63 +7264,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
"Note: affects indirectly rendered scenes)");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
/* Bake */
prop = RNA_def_property(srna, "bake_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, nullptr, "bake_mode");
RNA_def_property_enum_items(prop, bake_mode_items);
RNA_def_property_ui_text(prop, "Bake Type", "Choose shading information to bake into the image");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "use_bake_selected_to_active", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "bake_flag", R_BAKE_TO_ACTIVE);
RNA_def_property_ui_text(prop,
"Selected to Active",
"Bake shading on the surface of selected objects to the active object");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "use_bake_clear", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "bake_flag", R_BAKE_CLEAR);
RNA_def_property_ui_text(prop, "Clear", "Clear Images before baking");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "bake_margin", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, nullptr, "bake_margin");
RNA_def_property_range(prop, 0, 64);
RNA_def_property_ui_text(prop, "Margin", "Extends the baked result as a post process filter");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "bake_margin_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, nullptr, "bake_margin_type");
RNA_def_property_enum_items(prop, bake_margin_type_items);
RNA_def_property_ui_text(prop, "Margin Type", "Algorithm to generate the margin");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "bake_bias", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, nullptr, "bake_biasdist");
RNA_def_property_range(prop, 0.0, 1000.0);
RNA_def_property_ui_text(
prop, "Bias", "Bias towards faces further away from the object (in Blender units)");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "use_bake_multires", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "bake_flag", R_BAKE_MULTIRES);
RNA_def_property_ui_text(prop, "Bake from Multires", "Bake directly from multires object");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "use_bake_lores_mesh", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "bake_flag", R_BAKE_LORES_MESH);
RNA_def_property_ui_text(
prop, "Low Resolution Mesh", "Calculate heights against unsubdivided low resolution mesh");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
prop = RNA_def_property(srna, "bake_samples", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, nullptr, "bake_samples");
RNA_def_property_range(prop, 64, 1024);
RNA_def_property_ui_text(
prop, "Samples", "Number of samples used for ambient occlusion baking from multires");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, nullptr);
/* stamp */
prop = RNA_def_property(srna, "use_stamp_time", PROP_BOOLEAN, PROP_NONE);

View File

@@ -28,7 +28,7 @@ struct MultiresBakeRender {
int bake_margin = 0;
eBakeMarginType bake_margin_type = R_BAKE_ADJACENT_FACES;
short mode = RE_BAKE_NORMALS;
eBakeType type = R_BAKE_NORMALS;
/* Use low-resolution mesh when baking displacement maps.
* When true displacement is calculated between the final position in the SubdivCCG and the
@@ -41,9 +41,6 @@ struct MultiresBakeRender {
/* Material aligned image array (for per-face bake image), */
blender::Vector<Image *> ob_image;
/* Bias between object and start ray point when doing AO baking. */
float bias = 0;
blender::Set<Image *> images;
int num_total_objects = 0;

View File

@@ -488,12 +488,6 @@ void RE_pass_set_buffer_data(struct RenderPass *pass, float *data);
blender::gpu::Texture *RE_pass_ensure_gpu_texture_cache(struct Render *re,
struct RenderPass *rpass);
/* shaded view or baking options */
#define RE_BAKE_NORMALS 0
#define RE_BAKE_DISPLACEMENT 1
#define RE_BAKE_AO 2
#define RE_BAKE_VECTOR_DISPLACEMENT 3
void RE_GetCameraWindow(struct Render *re, const struct Object *camera, float r_winmat[4][4]);
/**
* Must be called after #RE_GetCameraWindow(), does not change `re->winmat`.

View File

@@ -473,7 +473,7 @@ static float2 get_tile_uv(Image &image, ImageTile &tile)
static bool need_tangent(const MultiresBakeRender &bake)
{
return bake.mode == RE_BAKE_NORMALS;
return bake.type == R_BAKE_NORMALS;
}
/** \} */
@@ -823,13 +823,16 @@ static std::unique_ptr<MultiresBaker> create_baker(const MultiresBakeRender &bak
const ImBuf &ibuf,
ExtraBuffers &extra_buffers)
{
switch (bake.mode) {
case RE_BAKE_NORMALS:
switch (bake.type) {
case R_BAKE_NORMALS:
return std::make_unique<MultiresNormalsBaker>(subdiv_ccg);
case RE_BAKE_DISPLACEMENT:
case R_BAKE_DISPLACEMENT:
return std::make_unique<MultiresDisplacementBaker>(subdiv_ccg, ibuf, extra_buffers);
case RE_BAKE_VECTOR_DISPLACEMENT:
case R_BAKE_VECTOR_DISPLACEMENT:
return std::make_unique<MultiresVectorDisplacementBaker>(subdiv_ccg);
case R_BAKE_AO:
/* Not implemented, should not be used. */
break;
}
BLI_assert_unreachable();
return nullptr;
@@ -1427,7 +1430,7 @@ static void bake_single_image(MultiresBakeRender &bake,
ExtraBuffers &extra_buffers,
MultiresBakeResult &result)
{
if (ELEM(bake.mode, RE_BAKE_DISPLACEMENT, RE_BAKE_VECTOR_DISPLACEMENT) &&
if (ELEM(bake.type, R_BAKE_DISPLACEMENT, R_BAKE_VECTOR_DISPLACEMENT) &&
!bake.use_low_resolution_mesh &&
bake.multires_modifier->lvl != bake.multires_modifier->totlvl)
{
@@ -1569,7 +1572,7 @@ static void finish_images(MultiresBakeRender &bake,
const Mesh &bake_level_mesh,
MultiresBakeResult &result)
{
const bool use_displacement_buffer = bake.mode == RE_BAKE_DISPLACEMENT;
const bool use_displacement_buffer = bake.type == R_BAKE_DISPLACEMENT;
for (BakedImBuf &baked_ibuf : result.baked_ibufs) {
Image *image = baked_ibuf.image;

View File

@@ -23,7 +23,7 @@ def bake(context):
scene.render.bake.target = 'IMAGE_TEXTURES'
cscene.bake_type = 'COMBINED'
if scene.render.use_bake_multires:
if scene.render.bake.use_multires:
# Multires baking calls a different function to bake images.
bpy.ops.object.bake_image()
else: