diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2019-05-17 17:57:31 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-17 18:59:26 +0300 |
commit | bc3139d79226896cf6c2b0813a1188eda70fad09 (patch) | |
tree | e5c7f1f878b4769def10e2ddbc75aacebda4afd5 /source/blender/blenloader/intern/versioning_cycles.c | |
parent | 043299ab69ca47a42fc8ca4f629727f8a6a2dd31 (diff) |
Cycles/Eevee: unify depth of field settings for cameras
There is now a checkbox to enable/disable depth of field per camera. For Eevee
this replace the scene level setting. For Cycles there is now only an F-Stop
value, no longer a Radius.
Existing files are converted based on Cycles or Eevee being set in the scene.
Differential Revision: https://developer.blender.org/D4882
Diffstat (limited to 'source/blender/blenloader/intern/versioning_cycles.c')
-rw-r--r-- | source/blender/blenloader/intern/versioning_cycles.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/source/blender/blenloader/intern/versioning_cycles.c b/source/blender/blenloader/intern/versioning_cycles.c index 3fc6d982e0f..81a2dd8e0ce 100644 --- a/source/blender/blenloader/intern/versioning_cycles.c +++ b/source/blender/blenloader/intern/versioning_cycles.c @@ -32,6 +32,7 @@ #include "DNA_light_types.h" #include "DNA_node_types.h" #include "DNA_particle_types.h" +#include "DNA_camera_types.h" #include "BKE_colortools.h" #include "BKE_idprop.h" @@ -67,12 +68,26 @@ static float cycles_property_float(IDProperty *idprop, const char *name, float d return (prop) ? IDP_Float(prop) : default_value; } +static float 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) { IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT); return (prop) ? IDP_Int(prop) : default_value; } +static const char *cycles_property_string(IDProperty *idprop, + const char *name, + const char *default_value) +{ + IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_STRING); + return (prop) ? IDP_String(prop) : default_value; +} + static void displacement_node_insert(bNodeTree *ntree) { bool need_update = false; @@ -398,7 +413,7 @@ void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bm } if (!MAIN_VERSION_ATLEAST(bmain, 280, 68)) { - /* Unify Cycles and EEVEE Film Transparency. */ + /* Unify Cycles and Eevee film transparency. */ for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { if (STREQ(scene->r.engine, RE_engine_id_CYCLES)) { IDProperty *cscene = cycles_properties_from_ID(&scene->id); @@ -410,6 +425,47 @@ void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bm } } } + + if (!MAIN_VERSION_ATLEAST(bmain, 280, 69)) { + /* Unify Cycles and Eevee depth of field. */ + Scene *scene = bmain->scenes.first; + const char *engine = (scene) ? scene->r.engine : "CYCLES"; + + if (STREQ(engine, RE_engine_id_CYCLES)) { + for (Camera *camera = bmain->cameras.first; camera; camera = camera->id.next) { + IDProperty *ccamera = cycles_properties_from_ID(&camera->id); + if (ccamera) { + const char *aperture_type = cycles_property_string(ccamera, "aperture_type", "RADIUS"); + + camera->dof.aperture_fstop = cycles_property_float(ccamera, "aperture_fstop", 5.6f); + camera->dof.aperture_blades = cycles_property_int(ccamera, "aperture_blades", 0); + camera->dof.aperture_rotation = cycles_property_float(ccamera, "aperture_rotation", 0.0); + camera->dof.aperture_ratio = cycles_property_float(ccamera, "aperture_ratio", 1.0f); + camera->dof.flag |= CAM_DOF_ENABLED; + + float aperture_size = cycles_property_float(ccamera, "aperture_size", 0.0f); + + if (STREQ(aperture_type, "RADIUS") && aperture_size > 0.0f) { + if (camera->type == CAM_ORTHO) { + camera->dof.aperture_fstop = 1.0f / (2.0f * aperture_size); + } + else { + camera->dof.aperture_fstop = (camera->lens * 1e-3f) / (2.0f * aperture_size); + } + + continue; + } + } + + /* No depth of field, set default settings. */ + camera->dof.aperture_fstop = 5.6f; + camera->dof.aperture_blades = 0; + camera->dof.aperture_rotation = 0.0f; + camera->dof.aperture_ratio = 1.0f; + camera->dof.flag &= ~CAM_DOF_ENABLED; + } + } + } } void do_versions_after_linking_cycles(Main *bmain) |