diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-06-01 00:49:10 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-06-24 16:17:36 +0300 |
commit | 0a3bde63006c66b8b8531ed5eccca9bdf5e5dc20 (patch) | |
tree | cf4a577e1fb0cfdaf0c47d56879ae49a21b68c1d /source/blender | |
parent | 88157b9efb2027380c4083d06e4ed61d8d109cef (diff) |
Cycles: add denoising settings to the render properties
Enabling render and viewport denoising is now both done from the render
properties. View layers still can individually be enabled/disabled for
denoising and have their own denoising parameters.
Note that the denoising engine also affects how denoising data passes are
output even if no denoising happens on the render itself, to make the passes
compatible with the engine.
This includes internal refactoring for how denoising parameters are passed
along, trying to avoid code duplication and unclear naming.
Ref T76259
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_blender_version.h | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_cycles.c | 77 |
2 files changed, 75 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 9d948dfd57b..229b5193e9c 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -40,7 +40,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 4 +#define BLENDER_FILE_SUBVERSION 5 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and show a warning if the file diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index ff3d4574561..72ee4c5ec4d 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -78,22 +78,45 @@ static IDProperty *cycles_properties_from_ID(ID *id) return (idprop) ? IDP_GetPropertyTypeFromGroup(idprop, "cycles", IDP_GROUP) : NULL; } +static IDProperty *cycles_properties_from_view_layer(ViewLayer *view_layer) +{ + IDProperty *idprop = view_layer->id_properties; + return (idprop) ? IDP_GetPropertyTypeFromGroup(idprop, "cycles", IDP_GROUP) : NULL; +} + static float cycles_property_float(IDProperty *idprop, const char *name, float default_value) { IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_FLOAT); return (prop) ? IDP_Float(prop) : default_value; } -static float cycles_property_int(IDProperty *idprop, const char *name, int default_value) +static int cycles_property_int(IDProperty *idprop, const char *name, int default_value) { IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT); return (prop) ? IDP_Int(prop) : default_value; } -static bool cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value) +static void cycles_property_int_set(IDProperty *idprop, const char *name, int value) { IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT); - return (prop) ? IDP_Int(prop) : default_value; + if (prop) { + IDP_Int(prop) = value; + } + else { + IDPropertyTemplate val = {0}; + val.i = value; + IDP_AddToGroup(idprop, IDP_New(IDP_INT, &val, name)); + } +} + +static bool cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value) +{ + return cycles_property_int(idprop, name, default_value); +} + +static void cycles_property_boolean_set(IDProperty *idprop, const char *name, bool value) +{ + cycles_property_int_set(idprop, name, value); } static void displacement_node_insert(bNodeTree *ntree) @@ -1524,4 +1547,52 @@ void do_versions_after_linking_cycles(Main *bmain) } FOREACH_NODETREE_END; } + + if (!MAIN_VERSION_ATLEAST(bmain, 290, 5)) { + /* New denoiser settings. */ + for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { + IDProperty *cscene = cycles_properties_from_ID(&scene->id); + + /* Check if any view layers had (optix) denoising enabled. */ + bool use_optix = false; + bool use_denoising = false; + for (ViewLayer *view_layer = scene->view_layers.first; view_layer; + view_layer = view_layer->next) { + IDProperty *cview_layer = cycles_properties_from_view_layer(view_layer); + if (cview_layer) { + use_denoising = use_denoising || + cycles_property_boolean(cview_layer, "use_denoising", false); + use_optix = use_optix || + cycles_property_boolean(cview_layer, "use_optix_denoising", false); + } + } + + if (cscene) { + const int DENOISER_NLM = 1; + const int DENOISER_OPTIX = 2; + + /* Enable denoiser if it was enabled for one view layer before. */ + cycles_property_int_set(cscene, "denoiser", (use_optix) ? DENOISER_OPTIX : DENOISER_NLM); + cycles_property_boolean_set(cscene, "use_denoising", use_denoising); + + /* Migrate Optix denoiser to new settings. */ + if (cycles_property_int(cscene, "preview_denoising", 0)) { + cycles_property_boolean_set(cscene, "use_preview_denoising", true); + cycles_property_boolean_set(cscene, "preview_denoiser", DENOISER_OPTIX); + } + } + + /* Enable denoising in all view layer if there was no denoising before, + * so that enabling the scene settings auto enables it for all view layers. */ + if (!use_denoising) { + for (ViewLayer *view_layer = scene->view_layers.first; view_layer; + view_layer = view_layer->next) { + IDProperty *cview_layer = cycles_properties_from_view_layer(view_layer); + if (cview_layer) { + cycles_property_boolean_set(cview_layer, "use_denoising", true); + } + } + } + } + } } |