diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fluid.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_query.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_remap.c | 43 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/main_idmap.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ocean.c | 159 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ocean_intern.h | 137 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ocean_spectrum.c | 224 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 2 |
16 files changed, 503 insertions, 167 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 0580ad55e43..c23cb9231d7 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1008,12 +1008,12 @@ void BKE_pchan_bbone_handles_compute(const BBoneSplineParameters *param, * - These properties allow users to hand-animate the * bone curve/shape, without having to resort to using * extra bones - * - The "bone" level offsets are for defining the restpose + * - The "bone" level offsets are for defining the rest-pose * shape of the bone (e.g. for curved eyebrows for example). * -> In the viewport, it's needed to define what the rest pose * looks like * -> For "rest == 0", we also still need to have it present - * so that we can "cancel out" this restpose when it comes + * so that we can "cancel out" this rest-pose when it comes * time to deform some geometry, it won't cause double transforms. * - The "pchan" level offsets are the ones that animators actually * end up animating diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 74c492573b1..67e9feac0cf 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -443,7 +443,7 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type) brush->gpencil_settings->active_smooth = ACTIVE_SMOOTH; brush->gpencil_settings->draw_angle = 0.0f; brush->gpencil_settings->draw_angle_factor = 0.0f; - brush->gpencil_settings->hardeness = 0.211f; + brush->gpencil_settings->hardeness = 0.9f; copy_v2_fl(brush->gpencil_settings->aspect_ratio, 1.0f); brush->gpencil_tool = GPAINT_TOOL_DRAW; diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 5c4636db728..d9954323594 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -89,7 +89,7 @@ static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons const Collection *collection_src = (const Collection *)id_src; BLI_assert(((collection_src->flag & COLLECTION_IS_MASTER) != 0) == - ((collection_src->id.flag & LIB_PRIVATE_DATA) != 0)); + ((collection_src->id.flag & LIB_EMBEDDED_DATA) != 0)); /* Do not copy collection's preview (same behavior as for objects). */ if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */ @@ -366,7 +366,7 @@ Collection *BKE_collection_duplicate(Main *bmain, const bool do_obdata) { /* It's not allowed to copy the master collection. */ - BLI_assert((collection->id.flag & LIB_PRIVATE_DATA) == 0); + BLI_assert((collection->id.flag & LIB_EMBEDDED_DATA) == 0); BLI_assert((collection->flag & COLLECTION_IS_MASTER) == 0); if (collection->flag & COLLECTION_IS_MASTER) { return NULL; @@ -514,7 +514,7 @@ Collection *BKE_collection_master_add() /* Not an actual datablock, but owned by scene. */ Collection *master_collection = MEM_callocN(sizeof(Collection), "Master Collection"); STRNCPY(master_collection->id.name, "GRMaster Collection"); - master_collection->id.flag |= LIB_PRIVATE_DATA; + master_collection->id.flag |= LIB_EMBEDDED_DATA; master_collection->flag |= COLLECTION_IS_MASTER; return master_collection; } diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 03c9cc7d151..9919a0d7385 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -2741,7 +2741,7 @@ static void update_flowsfluids(struct Depsgraph *depsgraph, } /* Optimization: Static liquid flow objects don't need emission computation after first * frame. - * TODO (sebbas): Also do not use static mode if inital velocities are enabled. */ + * TODO (sebbas): Also do not use static mode if initial velocities are enabled. */ if (mfs->type == FLUID_FLOW_TYPE_LIQUID && is_static && !is_first_frame && !use_velocity) { continue; } @@ -2961,7 +2961,7 @@ static void update_flowsfluids(struct Depsgraph *depsgraph, if (is_liquid && !is_first_frame) { /* Skip static liquid objects that are not on the first frame. - * TODO (sebbas): Also do not use static mode if inital velocities are enabled. */ + * TODO (sebbas): Also do not use static mode if initial velocities are enabled. */ if (is_static && !use_velocity) { continue; } @@ -3222,7 +3222,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *mds, Mesh *orgmesh, Obj float cell_size_scaled[3]; /* Assign material + flags to new mesh. - * If there are no faces in original mesj, keep materials and flags unchanged. */ + * If there are no faces in original mesh, keep materials and flags unchanged. */ MPoly *mpoly; MPoly mp_example = {0}; mpoly = orgmesh->mpoly; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 7a697f19b8b..4220408749a 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -3023,7 +3023,7 @@ Image *BKE_image_ensure_viewer(Main *bmain, int type, const char *name) /* happens on reload, imagewindow cannot be image user when hidden*/ if (ima->id.us == 0) { - id_us_plus(&ima->id); + id_us_ensure_real(&ima->id); } return ima; diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 919f249eea6..c342185d0b8 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -340,7 +340,7 @@ static int lib_id_expand_local_cb(LibraryIDLinkCallbackData *cb_data) ID *id_self = cb_data->id_self; ID **id_pointer = cb_data->id_pointer; int const cb_flag = cb_data->cb_flag; - if (cb_flag & IDWALK_CB_PRIVATE) { + if (cb_flag & IDWALK_CB_EMBEDDED) { return IDWALK_RET_NOP; } @@ -1148,7 +1148,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori ID *new_id = *r_newid; int flag = orig_flag; - const bool is_private_id_data = (id->flag & LIB_PRIVATE_DATA) != 0; + const bool is_private_id_data = (id->flag & LIB_EMBEDDED_DATA) != 0; BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL); BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0); @@ -1167,7 +1167,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori } /* The id->flag bits to copy over. */ - const int copy_idflag_mask = LIB_PRIVATE_DATA; + const int copy_idflag_mask = LIB_EMBEDDED_DATA; if ((flag & LIB_ID_CREATE_NO_ALLOCATE) != 0) { /* r_newid already contains pointer to allocated memory. */ @@ -1744,7 +1744,7 @@ static void library_make_local_copying_check(ID *id, } /* Shapekeys are considered 'private' to their owner ID here, and never tagged - * (since they cannot be linked), * so we have to switch effective parent to their owner. + * (since they cannot be linked), so we have to switch effective parent to their owner. */ if (GS(par_id->name) == ID_KE) { par_id = ((Key *)par_id)->from; diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c index ee27d0e546d..41d938e897d 100644 --- a/source/blender/blenkernel/intern/lib_query.c +++ b/source/blender/blenkernel/intern/lib_query.c @@ -137,11 +137,15 @@ enum { typedef struct LibraryForeachIDData { Main *bmain; - /* 'Real' ID, the one that might be in bmain, only differs from self_id when the later is a - * private one. */ + /** + * 'Real' ID, the one that might be in bmain, only differs from self_id when the later is a + * private one. + */ ID *owner_id; - /* ID from which the current ID pointer is being processed. It may be a 'private' ID like master - * collection or root node tree. */ + /** + * ID from which the current ID pointer is being processed. It may be an embedded ID like master + * collection or root node tree. + */ ID *self_id; int flag; @@ -343,8 +347,8 @@ static void library_foreach_layer_collection(LibraryForeachIDData *data, ListBas /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = (lc->collection != NULL && - (lc->collection->id.flag & LIB_PRIVATE_DATA) != 0) ? - IDWALK_CB_PRIVATE : + (lc->collection->id.flag & LIB_EMBEDDED_DATA) != 0) ? + IDWALK_CB_EMBEDDED : IDWALK_CB_NOP; FOREACH_CALLBACK_INVOKE(data, lc->collection, cb_flag); library_foreach_layer_collection(data, &lc->layer_collections); @@ -367,8 +371,8 @@ static void library_foreach_collection(LibraryForeachIDData *data, Collection *c /* XXX This is very weak. The whole idea of keeping pointers to private IDs is very bad * anyway... */ const int cb_flag = ((parent->collection != NULL && - (parent->collection->id.flag & LIB_PRIVATE_DATA) != 0) ? - IDWALK_CB_PRIVATE : + (parent->collection->id.flag & LIB_EMBEDDED_DATA) != 0) ? + IDWALK_CB_EMBEDDED : IDWALK_CB_NOP); FOREACH_CALLBACK_INVOKE( data, parent->collection, IDWALK_CB_NEVER_SELF | IDWALK_CB_LOOPBACK | cb_flag); @@ -484,13 +488,13 @@ static void library_foreach_screen_area(LibraryForeachIDData *data, ScrArea *are FOREACH_CALLBACK_INVOKE_ID(data, snode->from, IDWALK_CB_NOP); FOREACH_CALLBACK_INVOKE( - data, snode->nodetree, is_private_nodetree ? IDWALK_CB_PRIVATE : IDWALK_CB_USER); + data, snode->nodetree, is_private_nodetree ? IDWALK_CB_EMBEDDED : IDWALK_CB_USER); for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { /* first nodetree in path is same as snode->nodetree */ FOREACH_CALLBACK_INVOKE( - data, path->nodetree, is_private_nodetree ? IDWALK_CB_PRIVATE : IDWALK_CB_NOP); + data, path->nodetree, is_private_nodetree ? IDWALK_CB_EMBEDDED : IDWALK_CB_NOP); } else { FOREACH_CALLBACK_INVOKE(data, path->nodetree, IDWALK_CB_USER); @@ -527,10 +531,13 @@ static void library_foreach_ID_as_subdata_link(ID **id_pp, { /* Needed e.g. for callbacks handling relationships... This call shall be absolutely readonly. */ ID *id = *id_pp; - FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pp, IDWALK_CB_PRIVATE); + FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pp, IDWALK_CB_EMBEDDED); BLI_assert(id == *id_pp); - if (flag & IDWALK_RECURSE) { + if (flag & IDWALK_IGNORE_EMBEDDED_ID) { + /* Do Nothing. */ + } + else if (flag & IDWALK_RECURSE) { /* Defer handling into main loop, recursively calling BKE_library_foreach_ID_link in * IDWALK_RECURSE case is troublesome, see T49553. */ /* XXX note that this breaks the 'owner id' thing now, we likely want to handle that @@ -583,7 +590,12 @@ static void library_foreach_ID_link(Main *bmain, for (; id != NULL; id = (flag & IDWALK_RECURSE) ? BLI_LINKSTACK_POP(data.ids_todo) : NULL) { data.self_id = id; - data.owner_id = (id->flag & LIB_PRIVATE_DATA) ? id_owner : data.self_id; + /* Note that we may call this functions sometime directly on an embedded ID, without any + * knowledge of the owner ID then. + * While not great, and that should be probably sanitized at some point, we cal live with it + * for now. */ + data.owner_id = ((id->flag & LIB_EMBEDDED_DATA) != 0 && id_owner != NULL) ? id_owner : + data.self_id; /* inherit_data is non-NULL when this function is called for some sub-data ID * (like root nodetree of a material). diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c index d4b7696074a..1a22a6e6f79 100644 --- a/source/blender/blenkernel/intern/lib_remap.c +++ b/source/blender/blenkernel/intern/lib_remap.c @@ -68,7 +68,7 @@ typedef struct IDRemap { ID *old_id; ID *new_id; /** The ID in which we are replacing old_id by new_id usages. */ - ID *id; + ID *id_owner; short flag; /* 'Output' data. */ @@ -94,16 +94,21 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) { const int cb_flag = cb_data->cb_flag; - if (cb_flag & IDWALK_CB_PRIVATE) { + if (cb_flag & IDWALK_CB_EMBEDDED) { return IDWALK_RET_NOP; } + ID *id_owner = cb_data->id_owner; ID *id_self = cb_data->id_self; ID **id_p = cb_data->id_pointer; IDRemap *id_remap_data = cb_data->user_data; ID *old_id = id_remap_data->old_id; ID *new_id = id_remap_data->new_id; - ID *id = id_remap_data->id; + + /* Those asserts ensure the general sanity of ID tags regarding 'embedded' ID data (root + * nodetrees and co). */ + BLI_assert(id_owner == id_remap_data->id_owner); + BLI_assert(id_self == id_owner || (id_self->flag & LIB_EMBEDDED_DATA) != 0); if (!old_id) { /* Used to cleanup all IDs used by a specific one. */ BLI_assert(!new_id); @@ -123,9 +128,10 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) /* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct, * on the other hand since they get reset to lib data on file open/reload it is indirect too. * Edit Mode is also a 'skip direct' case. */ - const bool is_obj = (GS(id->name) == ID_OB); - const bool is_obj_proxy = (is_obj && (((Object *)id)->proxy || ((Object *)id)->proxy_group)); - const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id)); + const bool is_obj = (GS(id_owner->name) == ID_OB); + const bool is_obj_proxy = (is_obj && + (((Object *)id_owner)->proxy || ((Object *)id_owner)->proxy_group)); + const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id_owner)); const bool is_never_null = ((cb_flag & IDWALK_CB_NEVER_NULL) && (new_id == NULL) && (id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0); const bool skip_reference = (id_remap_data->flag & ID_REMAP_SKIP_OVERRIDE_LIBRARY) != 0; @@ -149,19 +155,19 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) if ((id_remap_data->flag & ID_REMAP_FLAG_NEVER_NULL_USAGE) && (cb_flag & IDWALK_CB_NEVER_NULL)) { - id->tag |= LIB_TAG_DOIT; + id_owner->tag |= LIB_TAG_DOIT; } /* Special hack in case it's Object->data and we are in edit mode, and new_id is not NULL * (otherwise, we follow common NEVER_NULL flags). * (skipped_indirect too). */ if ((is_never_null && skip_never_null) || - (is_obj_editmode && (((Object *)id)->data == *id_p) && new_id != NULL) || + (is_obj_editmode && (((Object *)id_owner)->data == *id_p) && new_id != NULL) || (skip_indirect && is_indirect) || (is_reference && skip_reference)) { if (is_indirect) { id_remap_data->skipped_indirect++; if (is_obj) { - Object *ob = (Object *)id; + Object *ob = (Object *)id_owner; if (ob->data == *id_p && ob->proxy != NULL) { /* And another 'Proudly brought to you by Proxy Hell' hack! * This will allow us to avoid clearing 'LIB_EXTERN' flag of obdata of proxies... */ @@ -189,6 +195,11 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) DEG_id_tag_update_ex(id_remap_data->bmain, id_self, ID_RECALC_COPY_ON_WRITE | ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); + if (id_self != id_owner) { + DEG_id_tag_update_ex(id_remap_data->bmain, + id_owner, + ID_RECALC_COPY_ON_WRITE | ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); + } } if (cb_flag & IDWALK_CB_USER) { /* NOTE: We don't user-count IDs which are not in the main database. @@ -215,7 +226,7 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) } /* We need to remap proxy_from pointer of remapped proxy... sigh. */ if (is_obj_proxy && new_id != NULL) { - Object *ob = (Object *)id; + Object *ob = (Object *)id_owner; if (ob->proxy == (Object *)new_id) { ob->proxy->proxy_from = ob; } @@ -228,11 +239,11 @@ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data) static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data) { - switch (GS(r_id_remap_data->id->name)) { + switch (GS(r_id_remap_data->id_owner->name)) { case ID_OB: { ID *old_id = r_id_remap_data->old_id; if (!old_id || GS(old_id->name) == ID_AR) { - Object *ob = (Object *)r_id_remap_data->id; + Object *ob = (Object *)r_id_remap_data->id_owner; /* Object's pose holds reference to armature bones... sic */ /* Note that in theory, we should have to bother about * linked/non-linked/never-null/etc. flags/states. @@ -371,7 +382,7 @@ static void libblock_remap_data( r_id_remap_data->bmain = bmain; r_id_remap_data->old_id = old_id; r_id_remap_data->new_id = new_id; - r_id_remap_data->id = NULL; + r_id_remap_data->id_owner = NULL; r_id_remap_data->flag = remap_flags; r_id_remap_data->status = 0; r_id_remap_data->skipped_direct = 0; @@ -382,7 +393,7 @@ static void libblock_remap_data( #ifdef DEBUG_PRINT printf("\tchecking id %s (%p, %p)\n", id->name, id, id->lib); #endif - r_id_remap_data->id = id; + r_id_remap_data->id_owner = id; libblock_remap_data_preprocess(r_id_remap_data); BKE_library_foreach_ID_link( NULL, id, foreach_libblock_remap_callback, (void *)r_id_remap_data, foreach_id_flags); @@ -398,7 +409,7 @@ static void libblock_remap_data( /* Note that we cannot skip indirect usages of old_id here (if requested), * we still need to check it for the user count handling... * XXX No more true (except for debug usage of those skipping counters). */ - r_id_remap_data->id = id_curr; + r_id_remap_data->id_owner = id_curr; libblock_remap_data_preprocess(r_id_remap_data); BKE_library_foreach_ID_link(NULL, id_curr, @@ -642,7 +653,7 @@ void BKE_libblock_relink_ex( static int id_relink_to_newid_looper(LibraryIDLinkCallbackData *cb_data) { const int cb_flag = cb_data->cb_flag; - if (cb_flag & IDWALK_CB_PRIVATE) { + if (cb_flag & IDWALK_CB_EMBEDDED) { return IDWALK_RET_NOP; } diff --git a/source/blender/blenkernel/intern/main_idmap.c b/source/blender/blenkernel/intern/main_idmap.c index 26eb0b681a1..8b83482d685 100644 --- a/source/blender/blenkernel/intern/main_idmap.c +++ b/source/blender/blenkernel/intern/main_idmap.c @@ -124,6 +124,8 @@ struct IDNameLib_Map *BKE_main_idmap_create(struct Main *bmain, const bool existing_key = BLI_ghash_ensure_p( id_map->uuid_map, POINTER_FROM_UINT(id->session_uuid), &id_ptr_v); BLI_assert(existing_key == false); + UNUSED_VARS_NDEBUG(existing_key); + *id_ptr_v = id; } FOREACH_MAIN_ID_END; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 1feb20ec272..8ddb78bcc17 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1654,7 +1654,7 @@ bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname) } else { ntree = MEM_callocN(sizeof(bNodeTree), "new node tree"); - ntree->id.flag |= LIB_PRIVATE_DATA; + ntree->id.flag |= LIB_EMBEDDED_DATA; *((short *)ntree->id.name) = ID_NT; BLI_strncpy(ntree->id.name + 2, name, sizeof(ntree->id.name)); } @@ -1682,21 +1682,6 @@ bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree) return ntreeCopyTree_ex(ntree, bmain, true); } -void ntreeUserIncrefID(bNodeTree *ntree) -{ - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - id_us_plus(node->id); - } -} -void ntreeUserDecrefID(bNodeTree *ntree) -{ - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - id_us_min(node->id); - } -} - /* *************** Node Preview *********** */ /* XXX this should be removed eventually ... diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index c27fb59835f..26485d10fbd 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -38,11 +38,11 @@ #include "BLI_path_util.h" #include "BLI_rand.h" #include "BLI_task.h" -#include "BLI_threads.h" #include "BLI_utildefines.h" #include "BKE_image.h" #include "BKE_ocean.h" +#include "ocean_intern.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -54,95 +54,6 @@ #ifdef WITH_OCEANSIM /* Ocean code */ -# include "fftw3.h" - -# define GRAVITY 9.81f - -typedef struct Ocean { - /* ********* input parameters to the sim ********* */ - float _V; - float _l; - float _w; - float _A; - float _damp_reflections; - float _wind_alignment; - float _depth; - - float _wx; - float _wz; - - float _L; - - /* dimensions of computational grid */ - int _M; - int _N; - - /* spatial size of computational grid */ - float _Lx; - float _Lz; - - float normalize_factor; /* init w */ - float time; - - short _do_disp_y; - short _do_normals; - short _do_chop; - short _do_jacobian; - - /* mutex for threaded texture access */ - ThreadRWMutex oceanmutex; - - /* ********* sim data arrays ********* */ - - /* two dimensional arrays of complex */ - fftw_complex *_fft_in; /* init w sim w */ - fftw_complex *_fft_in_x; /* init w sim w */ - fftw_complex *_fft_in_z; /* init w sim w */ - fftw_complex *_fft_in_jxx; /* init w sim w */ - fftw_complex *_fft_in_jzz; /* init w sim w */ - fftw_complex *_fft_in_jxz; /* init w sim w */ - fftw_complex *_fft_in_nx; /* init w sim w */ - fftw_complex *_fft_in_nz; /* init w sim w */ - fftw_complex *_htilda; /* init w sim w (only once) */ - - /* fftw "plans" */ - fftw_plan _disp_y_plan; /* init w sim r */ - fftw_plan _disp_x_plan; /* init w sim r */ - fftw_plan _disp_z_plan; /* init w sim r */ - fftw_plan _N_x_plan; /* init w sim r */ - fftw_plan _N_z_plan; /* init w sim r */ - fftw_plan _Jxx_plan; /* init w sim r */ - fftw_plan _Jxz_plan; /* init w sim r */ - fftw_plan _Jzz_plan; /* init w sim r */ - - /* two dimensional arrays of float */ - double *_disp_y; /* init w sim w via plan? */ - double *_N_x; /* init w sim w via plan? */ - /* all member of this array has same values, - * so convert this array to a float to reduce memory usage (MEM01). */ - /*float * _N_y; */ - double _N_y; /* sim w ********* can be rearranged? */ - double *_N_z; /* init w sim w via plan? */ - double *_disp_x; /* init w sim w via plan? */ - double *_disp_z; /* init w sim w via plan? */ - - /* two dimensional arrays of float */ - /* Jacobian and minimum eigenvalue */ - double *_Jxx; /* init w sim w */ - double *_Jzz; /* init w sim w */ - double *_Jxz; /* init w sim w */ - - /* one dimensional float array */ - float *_kx; /* init w sim r */ - float *_kz; /* init w sim r */ - - /* two dimensional complex array */ - fftw_complex *_h0; /* init w sim r */ - fftw_complex *_h0_minus; /* init w sim r */ - - /* two dimensional float array */ - float *_k; /* init w sim r */ -} Ocean; static float nextfr(RNG *rng, float min, float max) { @@ -285,7 +196,7 @@ float BKE_ocean_jminus_to_foam(float jminus, float coverage) { float foam = jminus * -0.005f + coverage; CLAMP(foam, 0.0f, 1.0f); - return foam * foam; + return foam; } void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v) @@ -893,6 +804,9 @@ void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData omd->wave_alignment, omd->depth, omd->time, + omd->spectrum, + omd->fetch_jonswap, + omd->sharpen_peak_jonswap, do_heightfield, do_chop, do_normals, @@ -913,6 +827,9 @@ void BKE_ocean_init(struct Ocean *o, float alignment, float depth, float time, + int spectrum, + float fetch_jonswap, + float sharpen_peak_jonswap, short do_height_field, short do_chop, short do_normals, @@ -940,6 +857,13 @@ void BKE_ocean_init(struct Ocean *o, o->_L = V * V / GRAVITY; /* largest wave for a given velocity V */ o->time = time; + /* Spectrum to use. */ + o->_spectrum = spectrum; + + /* Common JONSWAP parameters. */ + o->_fetch_jonswap = fetch_jonswap; + o->_sharpen_peak_jonswap = sharpen_peak_jonswap; + o->_do_disp_y = do_height_field; o->_do_normals = do_normals; o->_do_chop = do_chop; @@ -1001,10 +925,46 @@ void BKE_ocean_init(struct Ocean *o, fftw_complex r1r2; init_complex(r1r2, r1, r2); - mul_complex_f( - o->_h0[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); - mul_complex_f( - o->_h0_minus[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); + switch (o->_spectrum) { + case MOD_OCEAN_SPECTRUM_JONSWAP: + mul_complex_f(o->_h0[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_jonswap(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f( + o->_h0_minus[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_jonswap(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); + break; + case MOD_OCEAN_SPECTRUM_TEXEL_MARSEN_ARSLOE: + mul_complex_f( + o->_h0[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_texelmarsenarsloe(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f( + o->_h0_minus[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_texelmarsenarsloe(o, -o->_kx[i], -o->_kz[j]) / + 2.0f))); + break; + case MOD_OCEAN_SPECTRUM_PIERSON_MOSKOWITZ: + mul_complex_f( + o->_h0[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_piersonmoskowitz(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f( + o->_h0_minus[i * o->_N + j], + r1r2, + (float)(sqrt(BLI_ocean_spectrum_piersonmoskowitz(o, -o->_kx[i], -o->_kz[j]) / + 2.0f))); + break; + default: + mul_complex_f( + o->_h0[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f))); + mul_complex_f(o->_h0_minus[i * o->_N + j], + r1r2, + (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f))); + break; + } } } @@ -1517,12 +1477,6 @@ void BKE_ocean_bake(struct Ocean *o, #else /* WITH_OCEANSIM */ -/* stub */ -typedef struct Ocean { - /* need some data here, C does not allow empty struct */ - int stub; -} Ocean; - float BKE_ocean_jminus_to_foam(float UNUSED(jminus), float UNUSED(coverage)) { return 0.0f; @@ -1591,6 +1545,9 @@ void BKE_ocean_init(struct Ocean *UNUSED(o), float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), + int UNUSED(spectrum), + float UNUSED(fetch_jonswap), + float UNUSED(sharpen_peak_jonswap), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), diff --git a/source/blender/blenkernel/intern/ocean_intern.h b/source/blender/blenkernel/intern/ocean_intern.h new file mode 100644 index 00000000000..7da88419219 --- /dev/null +++ b/source/blender/blenkernel/intern/ocean_intern.h @@ -0,0 +1,137 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __BKE_OCEAN_INTERN_H__ +#define __BKE_OCEAN_INTERN_H__ + +/** \file + * \ingroup bli + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef WITH_OCEANSIM +# include "BLI_threads.h" +# include "fftw3.h" +# define GRAVITY 9.81f + +typedef struct Ocean { + /* ********* input parameters to the sim ********* */ + float _V; + float _l; + float _w; + float _A; + float _damp_reflections; + float _wind_alignment; + float _depth; + + float _wx; + float _wz; + + float _L; + + /* dimensions of computational grid */ + int _M; + int _N; + + /* spatial size of computational grid */ + float _Lx; + float _Lz; + + float normalize_factor; /* init w */ + float time; + + short _do_disp_y; + short _do_normals; + short _do_chop; + short _do_jacobian; + + /* Which spectral model we are using. */ + int _spectrum; + + /* JONSWAP common parameters. */ + float _fetch_jonswap; + float _sharpen_peak_jonswap; + + /* mutex for threaded texture access */ + ThreadRWMutex oceanmutex; + + /* ********* sim data arrays ********* */ + + /* two dimensional arrays of complex */ + fftw_complex *_fft_in; /* init w sim w */ + fftw_complex *_fft_in_x; /* init w sim w */ + fftw_complex *_fft_in_z; /* init w sim w */ + fftw_complex *_fft_in_jxx; /* init w sim w */ + fftw_complex *_fft_in_jzz; /* init w sim w */ + fftw_complex *_fft_in_jxz; /* init w sim w */ + fftw_complex *_fft_in_nx; /* init w sim w */ + fftw_complex *_fft_in_nz; /* init w sim w */ + fftw_complex *_htilda; /* init w sim w (only once) */ + + /* fftw "plans" */ + fftw_plan _disp_y_plan; /* init w sim r */ + fftw_plan _disp_x_plan; /* init w sim r */ + fftw_plan _disp_z_plan; /* init w sim r */ + fftw_plan _N_x_plan; /* init w sim r */ + fftw_plan _N_z_plan; /* init w sim r */ + fftw_plan _Jxx_plan; /* init w sim r */ + fftw_plan _Jxz_plan; /* init w sim r */ + fftw_plan _Jzz_plan; /* init w sim r */ + + /* two dimensional arrays of float */ + double *_disp_y; /* init w sim w via plan? */ + double *_N_x; /* init w sim w via plan? */ + /* all member of this array has same values, + * so convert this array to a float to reduce memory usage (MEM01). */ + /*float * _N_y; */ + double _N_y; /* sim w ********* can be rearranged? */ + double *_N_z; /* init w sim w via plan? */ + double *_disp_x; /* init w sim w via plan? */ + double *_disp_z; /* init w sim w via plan? */ + + /* two dimensional arrays of float */ + /* Jacobian and minimum eigenvalue */ + double *_Jxx; /* init w sim w */ + double *_Jzz; /* init w sim w */ + double *_Jxz; /* init w sim w */ + + /* one dimensional float array */ + float *_kx; /* init w sim r */ + float *_kz; /* init w sim r */ + + /* two dimensional complex array */ + fftw_complex *_h0; /* init w sim r */ + fftw_complex *_h0_minus; /* init w sim r */ + + /* two dimensional float array */ + float *_k; /* init w sim r */ +} Ocean; +#else +/* stub */ +typedef struct Ocean { + /* need some data here, C does not allow empty struct */ + int stub; +} Ocean; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/blender/blenkernel/intern/ocean_spectrum.c b/source/blender/blenkernel/intern/ocean_spectrum.c new file mode 100644 index 00000000000..93018f4a5b0 --- /dev/null +++ b/source/blender/blenkernel/intern/ocean_spectrum.c @@ -0,0 +1,224 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup bke + */ + +#include "BLI_math.h" +#include "BKE_ocean.h" +#include "ocean_intern.h" + +#ifdef WITH_OCEANSIM + +/* -------------------------------------------------------------------- */ +/** \name Ocean Spectrum from EncinoWaves + * \{ */ + +/* + * Original code from EncinoWaves project Copyright (c) 2015 Christopher Jon Horvath + * Modifications made to work within blender. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + +/** + * alpha_beta_spectrum is a common algorithm for the Pierson-Moskowitz, JONSWAP and TMA models. + * This is a modified implementation from the EncinoWaves project. + */ +static float alpha_beta_spectrum(const float alpha, + const float beta, + const float gamma, + const float omega, + const float peakomega) +{ + return (alpha * sqrt(gamma) / pow(omega, 5.0)) * exp(-beta * pow(peakomega / omega, 4.0)); +} + +static float peak_sharpen(const float omega, const float m_peakomega, const float m_gamma) +{ + const float peak_sharpening_sigma = (omega < m_peakomega) ? 0.07 : 0.09; + const float peak_sharpening = pow( + m_gamma, exp(-sqrt((omega - m_peakomega) / (peak_sharpening_sigma * m_peakomega)) / 2.0)); + + return peak_sharpening; +} + +/** + * Spectrum-type independent modifications. + */ +static float ocean_spectrum_wind_and_damp(const Ocean *oc, + const float kx, + const float kz, + const float val) +{ + const float k2 = kx * kx + kz * kz; + const float k_mag_inv = 1.0f / k2; + const float k_dot_w = (kx * k_mag_inv * oc->_wx) + (kz * k_mag_inv * oc->_wz); + + /* Bias towards wind dir. */ + float newval = val * pow(fabs(k_dot_w), oc->_wind_alignment); + + /* Eliminate wavelengths smaller than cutoff. */ + /* val *= exp(-k2 * m_cutoff); */ + + /* Reduce reflected waves. */ + if (k_dot_w < 0.0f) { + if (oc->_wind_alignment > 0.0) { + newval *= oc->_damp_reflections; + } + } + + return newval; +} + +static float jonswap(const Ocean *oc, const float k2) +{ + /* Get our basic JONSWAP value from #alpha_beta_spectrum. */ + const float k_mag = sqrt(k2); + + const float m_omega = GRAVITY * k_mag * tanh(k_mag * oc->_depth); + const float omega = sqrt(m_omega); + + const float m_fetch = oc->_fetch_jonswap; + + /* Strictly, this should be a random value from a Gaussian (mean 3.3, variance 0.67), + * clamped 1.0 to 6.0. */ + float m_gamma = oc->_sharpen_peak_jonswap; + if (m_gamma < 1.0) { + m_gamma = 1.00; + } + if (m_gamma > 6.0) { + m_gamma = 6.0; + } + + const float m_windspeed = oc->_V; + + const float m_dimensionlessFetch = fabs(GRAVITY * m_fetch / sqrt(m_windspeed)); + const float m_alpha = 0.076 * pow(m_dimensionlessFetch, -0.22); + + const float m_tau = M_PI * 2; + const float m_peakomega = m_tau * 3.5 * fabs(GRAVITY / oc->_V) * + pow(m_dimensionlessFetch, -0.33); + + const float beta = 1.25f; + + float val = alpha_beta_spectrum(m_alpha, beta, GRAVITY, omega, m_peakomega); + + /* Peak sharpening */ + val *= peak_sharpen(m_omega, m_peakomega, m_gamma); + + return val; +} + +/** + * Pierson-Moskowitz model, 1964, assumes waves reach equilibrium with wind. + * Model is intended for large area 'fully developed' sea, where winds have been steadily blowing + * for days over an area that includes hundreds of wavelengths on a side. + */ +float BLI_ocean_spectrum_piersonmoskowitz(const Ocean *oc, const float kx, const float kz) +{ + const float k2 = kx * kx + kz * kz; + + if (k2 == 0.0f) { + /* No DC component. */ + return 0.0f; + } + + /* Get Pierson-Moskowitz value from #alpha_beta_spectrum. */ + const float peak_omega_PM = 0.87f * GRAVITY / oc->_V; + + const float k_mag = sqrt(k2); + const float m_omega = GRAVITY * k_mag * tanh(k_mag * oc->_depth); + + const float omega = sqrt(m_omega); + const float alpha = 0.0081f; + const float beta = 1.291f; + + float val = alpha_beta_spectrum(alpha, beta, GRAVITY, omega, peak_omega_PM); + + val = ocean_spectrum_wind_and_damp(oc, kx, kz, val); + + return val; +} + +/** + * TMA extends the JONSWAP spectrum. + * This spectral model is best suited to shallow water. + */ +float BLI_ocean_spectrum_texelmarsenarsloe(const Ocean *oc, const float kx, const float kz) +{ + const float k2 = kx * kx + kz * kz; + + if (k2 == 0.0f) { + /* No DC component. */ + return 0.0f; + } + + float val = jonswap(oc, k2); + + val = ocean_spectrum_wind_and_damp(oc, kx, kz, val); + + /* TMA modifications to JONSWAP. */ + const float m_depth = oc->_depth; + const float gain = sqrt(m_depth / GRAVITY); + + const float k_mag = sqrt(k2); + + const float m_omega = GRAVITY * k_mag * tanh(k_mag * oc->_depth); + const float omega = sqrt(m_omega); + + const float kitaigorodskiiDepth_wh = omega * gain; + const float kitaigorodskiiDepth = 0.5 + (0.5 * tanh(1.8 * (kitaigorodskiiDepth_wh - 1.125))); + + val *= kitaigorodskiiDepth; + + val = ocean_spectrum_wind_and_damp(oc, kx, kz, val); + + return val; +} + +/** + * Hasselmann et al, 1973. This model extends the Pierson-Moskowitz model with a peak sharpening + * function This enhancement is an artificial construct to address the problem that the wave + * spectrum is never fully developed. + * + * The fetch parameter represents the distance from a lee shore, + * called the fetch, or the distance over which the wind blows with constant velocity. + */ +float BLI_ocean_spectrum_jonswap(const Ocean *oc, const float kx, const float kz) +{ + const float k2 = kx * kx + kz * kz; + + if (k2 == 0.0f) { + /* No DC component. */ + return 0.0f; + } + + float val = jonswap(oc, k2); + + val = ocean_spectrum_wind_and_damp(oc, kx, kz, val); + + return val; +} + +/** \} */ + +#endif /* WITH_OCEANSIM */ diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 90a4a2dee23..b0163436cc4 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1953,8 +1953,8 @@ static bool foreach_object_ptcache( if (!foreach_object_modifier_ptcache(object, callback, callback_user_data)) { return false; } - /* Consider all object in dupli groups to be part of the same object, - * for baking with linking dupligroups. Once we have better overrides + /* Consider all object in dupli-groups to be part of the same object, + * for baking with linking dupli-groups. Once we have better overrides * this can be revisited so users select the local objects directly. */ if (scene != NULL && (duplis-- > 0) && (object->instance_collection != NULL)) { FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (object->instance_collection, current_object) { diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 37049014ef7..6ca14ec9197 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -395,9 +395,9 @@ static void scene_free_data(ID *id) scene->master_collection = NULL; } - if (scene->eevee.light_cache) { - EEVEE_lightcache_free(scene->eevee.light_cache); - scene->eevee.light_cache = NULL; + if (scene->eevee.light_cache_data) { + EEVEE_lightcache_free(scene->eevee.light_cache_data); + scene->eevee.light_cache_data = NULL; } if (scene->display.shading.prop) { @@ -583,7 +583,7 @@ void BKE_scene_copy_data_eevee(Scene *sce_dst, const Scene *sce_src) { /* Copy eevee data between scenes. */ sce_dst->eevee = sce_src->eevee; - sce_dst->eevee.light_cache = NULL; + sce_dst->eevee.light_cache_data = NULL; sce_dst->eevee.light_cache_info[0] = '\0'; /* TODO Copy the cache. */ } @@ -2057,6 +2057,14 @@ void BKE_scene_free_depsgraph_hash(Scene *scene) scene->depsgraph_hash = NULL; } +void BKE_scene_free_view_layer_depsgraph(Scene *scene, ViewLayer *view_layer) +{ + if (scene->depsgraph_hash != NULL) { + DepsgraphKey key = {view_layer}; + BLI_ghash_remove(scene->depsgraph_hash, &key, depsgraph_key_free, depsgraph_key_value_free); + } +} + /* Query depsgraph for a specific contexts. */ Depsgraph *BKE_scene_get_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, bool allocate) diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index f1243330567..a9bd1d17567 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -621,7 +621,7 @@ MovieTrackingTrack *BKE_tracking_track_duplicate(MovieTrackingTrack *track) new_track->markers = MEM_dupallocN(new_track->markers); - /* Orevent duplicate from being used for 2D stabilization. + /* Prevent duplicate from being used for 2D stabilization. * If necessary, it shall be added explicitly. */ new_track->flag &= ~TRACK_USE_2D_STAB; |