2012-04-30 14:24:11 +00:00
|
|
|
/*
|
2011-05-24 07:08:58 +00:00
|
|
|
* 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.
|
|
|
|
|
*
|
2012-04-30 14:24:11 +00:00
|
|
|
* 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.
|
2011-05-24 07:08:58 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2013-09-12 03:02:50 +00:00
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
2011-06-16 10:41:00 +00:00
|
|
|
#include <stdio.h>
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_kdtree.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string_utils.h"
|
2016-05-18 22:04:58 +02:00
|
|
|
#include "BLI_task.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "BLI_threads.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-10-26 17:32:50 +00:00
|
|
|
|
2011-09-05 17:06:09 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2012-06-29 11:19:29 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2018-08-29 15:32:50 +02:00
|
|
|
#include "DNA_collection_types.h"
|
2011-12-05 13:36:41 +00:00
|
|
|
#include "DNA_constraint_types.h"
|
2011-09-05 17:06:09 +00:00
|
|
|
#include "DNA_dynamicpaint_types.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "DNA_material_types.h"
|
2011-09-05 17:06:09 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "DNA_texture_types.h"
|
2011-09-05 17:06:09 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
#include "BKE_animsys.h"
|
2012-06-29 11:19:29 +00:00
|
|
|
#include "BKE_armature.h"
|
2018-03-23 11:51:19 +01:00
|
|
|
#include "BKE_bvhutils.h" /* bvh tree */
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
#include "BKE_collection.h"
|
2018-06-25 14:21:15 +02:00
|
|
|
#include "BKE_collision.h"
|
2017-12-07 15:36:26 +11:00
|
|
|
#include "BKE_colorband.h"
|
2011-12-05 13:36:41 +00:00
|
|
|
#include "BKE_constraint.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "BKE_customdata.h"
|
2011-06-18 18:41:20 +00:00
|
|
|
#include "BKE_deform.h"
|
2011-06-16 10:41:00 +00:00
|
|
|
#include "BKE_dynamicpaint.h"
|
2011-06-27 07:30:58 +00:00
|
|
|
#include "BKE_effect.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "BKE_image.h"
|
2018-11-07 15:37:31 +01:00
|
|
|
#include "BKE_library.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_material.h"
|
2018-09-24 16:32:29 +02:00
|
|
|
#include "BKE_mesh.h"
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
#include "BKE_mesh_mapping.h"
|
2018-09-24 16:32:29 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "BKE_modifier.h"
|
2011-06-16 10:41:00 +00:00
|
|
|
#include "BKE_object.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
#include "BKE_pointcache.h"
|
2011-06-16 10:41:00 +00:00
|
|
|
#include "BKE_scene.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-04-06 12:07:27 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
/* for image output */
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* to read material/texture color */
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "RE_render_ext.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "RE_shader_ext.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
#include "atomic_ops.h"
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
2012-11-04 07:18:29 +00:00
|
|
|
/* could enable at some point but for now there are far too many conversions */
|
2012-11-23 10:03:50 +00:00
|
|
|
#ifdef __GNUC__
|
2016-05-12 12:08:03 +02:00
|
|
|
//# pragma GCC diagnostic ignored "-Wdouble-promotion"
|
2012-11-23 10:03:50 +00:00
|
|
|
#endif
|
2012-11-04 07:18:29 +00:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
static CLG_LogRef LOG = {"bke.dynamicpaint"};
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* precalculated gaussian factors for 5x super sampling */
|
2013-10-10 20:22:17 +00:00
|
|
|
static const float gaussianFactors[5] = {
|
|
|
|
|
0.996849f,
|
|
|
|
|
0.596145f,
|
|
|
|
|
0.596145f,
|
|
|
|
|
0.596145f,
|
|
|
|
|
0.524141f};
|
|
|
|
|
static const float gaussianTotal = 3.309425f;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2012-03-01 12:20:18 +00:00
|
|
|
/* UV Image neighboring pixel table x and y list */
|
2012-04-29 15:47:02 +00:00
|
|
|
static int neighX[8] = {1, 1, 0, -1, -1, -1, 0, 1};
|
|
|
|
|
static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1};
|
2011-10-13 20:00:22 +00:00
|
|
|
|
2016-09-27 11:13:04 +03:00
|
|
|
/* Neighbor x/y list that prioritizes grid directions over diagonals */
|
|
|
|
|
static int neighStraightX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
|
|
|
|
|
static int neighStraightY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
|
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
/* subframe_updateObject() flags */
|
2013-03-22 17:08:55 +00:00
|
|
|
#define SUBFRAME_RECURSION 5
|
2011-10-13 20:00:22 +00:00
|
|
|
/* surface_getBrushFlags() return vals */
|
2012-05-12 16:11:34 +00:00
|
|
|
#define BRUSH_USES_VELOCITY (1 << 0)
|
2011-10-13 20:00:22 +00:00
|
|
|
/* brush mesh raycast status */
|
|
|
|
|
#define HIT_VOLUME 1
|
|
|
|
|
#define HIT_PROXIMITY 2
|
2012-01-24 17:28:50 +00:00
|
|
|
/* dynamicPaint_findNeighbourPixel() return codes */
|
|
|
|
|
#define NOT_FOUND -1
|
|
|
|
|
#define ON_MESH_EDGE -2
|
|
|
|
|
#define OUT_OF_TEXTURE -3
|
2011-10-13 20:00:22 +00:00
|
|
|
/* paint effect default movement per frame in global units */
|
|
|
|
|
#define EFF_MOVEMENT_PER_FRAME 0.05f
|
|
|
|
|
/* initial wave time factor */
|
2012-05-12 16:11:34 +00:00
|
|
|
#define WAVE_TIME_FAC (1.0f / 24.f)
|
2012-01-16 17:18:07 +00:00
|
|
|
#define CANVAS_REL_SIZE 5.0f
|
2011-10-31 13:01:06 +00:00
|
|
|
/* drying limits */
|
|
|
|
|
#define MIN_WETNESS 0.001f
|
2012-01-16 17:18:07 +00:00
|
|
|
#define MAX_WETNESS 5.0f
|
2012-11-04 06:21:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dissolve inline function */
|
2016-05-12 12:08:03 +02:00
|
|
|
BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const bool is_log)
|
2012-11-04 06:21:09 +00:00
|
|
|
{
|
|
|
|
|
*r_value = (is_log) ?
|
|
|
|
|
(*r_value) * (powf(MIN_WETNESS, 1.0f / (1.2f * time / scale))) :
|
|
|
|
|
(*r_value) - 1.0f / time * scale;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/***************************** Internal Structs ***************************/
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
typedef struct Bounds2D {
|
2011-06-16 10:41:00 +00:00
|
|
|
float min[2], max[2];
|
2011-07-22 18:37:30 +00:00
|
|
|
} Bounds2D;
|
|
|
|
|
|
|
|
|
|
typedef struct Bounds3D {
|
|
|
|
|
float min[3], max[3];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bool valid;
|
2011-07-22 18:37:30 +00:00
|
|
|
} Bounds3D;
|
|
|
|
|
|
|
|
|
|
typedef struct VolumeGrid {
|
2011-10-13 20:00:22 +00:00
|
|
|
int dim[3];
|
2016-05-12 12:08:03 +02:00
|
|
|
Bounds3D grid_bounds; /* whole grid bounds */
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */
|
|
|
|
|
int *s_pos; /* (x*y*z) t_index begin id */
|
|
|
|
|
int *s_num; /* (x*y*z) number of t_index points */
|
|
|
|
|
int *t_index; /* actual surface point index, access: (s_pos + s_num) */
|
2011-07-22 18:37:30 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
int *temp_t_index;
|
2011-07-22 18:37:30 +00:00
|
|
|
} VolumeGrid;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
typedef struct Vec3f {
|
|
|
|
|
float v[3];
|
|
|
|
|
} Vec3f;
|
|
|
|
|
|
2012-01-24 17:28:50 +00:00
|
|
|
typedef struct BakeAdjPoint {
|
2012-05-12 16:11:34 +00:00
|
|
|
float dir[3]; /* vector pointing towards this neighbor */
|
|
|
|
|
float dist; /* distance to */
|
2012-01-24 17:28:50 +00:00
|
|
|
} BakeAdjPoint;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Surface data used while processing a frame */
|
2011-07-22 18:37:30 +00:00
|
|
|
typedef struct PaintBakeNormal {
|
|
|
|
|
float invNorm[3]; /* current pixel world-space inverted normal */
|
2016-05-12 12:08:03 +02:00
|
|
|
float normal_scale; /* normal directional scale for displace mapping */
|
2011-07-22 18:37:30 +00:00
|
|
|
} PaintBakeNormal;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
/* Temp surface data used to process a frame */
|
2011-06-17 18:04:56 +00:00
|
|
|
typedef struct PaintBakeData {
|
2011-08-03 18:31:48 +00:00
|
|
|
/* point space data */
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintBakeNormal *bNormal;
|
2016-05-12 12:08:03 +02:00
|
|
|
int *s_pos; /* index to start reading point sample realCoord */
|
|
|
|
|
int *s_num; /* num of realCoord samples */
|
|
|
|
|
Vec3f *realCoord; /* current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */
|
2011-11-16 18:32:28 +00:00
|
|
|
Bounds3D mesh_bounds;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float dim[3];
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-08-21 19:03:47 +00:00
|
|
|
/* adjacency info */
|
2016-05-12 12:08:03 +02:00
|
|
|
BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */
|
2011-08-03 18:31:48 +00:00
|
|
|
double average_dist;
|
|
|
|
|
/* space partitioning */
|
2012-05-12 16:11:34 +00:00
|
|
|
VolumeGrid *grid; /* space partitioning grid to optimize brush checks */
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* velocity and movement */
|
2012-05-12 16:11:34 +00:00
|
|
|
Vec3f *velocity; /* speed vector in global space movement per frame, if required */
|
2011-08-03 18:31:48 +00:00
|
|
|
Vec3f *prev_velocity;
|
2012-05-12 16:11:34 +00:00
|
|
|
float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge
|
2016-05-12 12:08:03 +02:00
|
|
|
* 3 float dir vec + 1 float str */
|
2012-05-12 16:11:34 +00:00
|
|
|
MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */
|
2011-07-22 18:37:30 +00:00
|
|
|
float prev_obmat[4][4]; /* previous frame object matrix */
|
2012-05-12 16:11:34 +00:00
|
|
|
int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */
|
2011-06-17 18:04:56 +00:00
|
|
|
} PaintBakeData;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* UV Image sequence format point */
|
2011-06-27 07:30:58 +00:00
|
|
|
typedef struct PaintUVPoint {
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Pixel / mesh data */
|
2015-07-27 15:52:54 +10:00
|
|
|
unsigned int tri_index, pixel_index; /* tri index on domain derived mesh */
|
2012-05-12 16:11:34 +00:00
|
|
|
unsigned int v1, v2, v3; /* vertex indexes */
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
unsigned int neighbour_pixel; /* If this pixel isn't uv mapped to any face, but it's neighboring pixel is */
|
2011-06-27 07:30:58 +00:00
|
|
|
} PaintUVPoint;
|
|
|
|
|
|
|
|
|
|
typedef struct ImgSeqFormatData {
|
|
|
|
|
PaintUVPoint *uv_p;
|
2012-05-12 16:11:34 +00:00
|
|
|
Vec3f *barycentricWeights; /* b-weights for all pixel samples */
|
2011-06-27 07:30:58 +00:00
|
|
|
} ImgSeqFormatData;
|
|
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/* adjacency data flags */
|
2012-05-12 16:11:34 +00:00
|
|
|
#define ADJ_ON_MESH_EDGE (1 << 0)
|
2017-01-03 18:50:15 +03:00
|
|
|
#define ADJ_BORDER_PIXEL (1 << 1)
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
typedef struct PaintAdjData {
|
2016-05-12 12:08:03 +02:00
|
|
|
int *n_target; /* array of neighboring point indexes, for single sample use (n_index + neigh_num) */
|
2012-05-16 23:37:23 +00:00
|
|
|
int *n_index; /* index to start reading n_target for each point */
|
2012-05-12 16:11:34 +00:00
|
|
|
int *n_num; /* num of neighs for each point */
|
|
|
|
|
int *flags; /* vertex adjacency flags */
|
2011-11-10 13:00:27 +00:00
|
|
|
int total_targets; /* size of n_target */
|
2017-01-03 18:50:15 +03:00
|
|
|
int *border; /* indices of border pixels (only for texture paint) */
|
|
|
|
|
int total_border; /* size of border */
|
2011-07-02 18:06:39 +00:00
|
|
|
} PaintAdjData;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/***************************** General Utils ******************************/
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
/* Set canvas error string to display at the bake report */
|
2011-11-10 12:28:26 +00:00
|
|
|
static int setError(DynamicPaintCanvasSettings *canvas, const char *string)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Add error to canvas ui info label */
|
2011-11-13 13:56:40 +00:00
|
|
|
BLI_strncpy(canvas->error, string, sizeof(canvas->error));
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_STR_ERROR(&LOG, string);
|
2011-06-16 10:41:00 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Get number of surface points for cached types */
|
|
|
|
|
static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_PTEX) {
|
|
|
|
|
return 0; /* not supported atm */
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2018-09-24 16:32:29 +02:00
|
|
|
return (surface->canvas->mesh) ? surface->canvas->mesh->totvert : 0;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
|
|
|
|
|
return 0;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* checks whether surface's format/type has realtime preview */
|
2014-02-01 00:51:53 +11:00
|
|
|
bool dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2016-05-12 12:08:03 +02:00
|
|
|
return !ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
|
|
|
|
|
return true;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get currently active surface (in user interface) */
|
2012-05-17 23:21:11 +00:00
|
|
|
DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas)
|
|
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
return BLI_findlink(&canvas->surfaces, canvas->active_sur);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* set preview to first previewable surface */
|
2011-09-05 16:04:15 +00:00
|
|
|
void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintSurface *surface = canvas->surfaces.first;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool done = false;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2011-07-03 14:01:57 +00:00
|
|
|
if (!done && dynamicPaint_surfaceHasColorPreview(surface)) {
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->flags |= MOD_DPAINT_PREVIEW;
|
2014-04-01 11:34:00 +11:00
|
|
|
done = true;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
else {
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->flags &= ~MOD_DPAINT_PREVIEW;
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 18:04:56 +00:00
|
|
|
/* set preview to defined surface */
|
2011-06-16 10:41:00 +00:00
|
|
|
static void dynamicPaint_setPreview(DynamicPaintSurface *t_surface)
|
|
|
|
|
{
|
|
|
|
|
DynamicPaintSurface *surface = t_surface->canvas->surfaces.first;
|
2012-05-12 16:11:34 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2011-06-16 10:41:00 +00:00
|
|
|
if (surface == t_surface)
|
|
|
|
|
surface->flags |= MOD_DPAINT_PREVIEW;
|
|
|
|
|
else
|
|
|
|
|
surface->flags &= ~MOD_DPAINT_PREVIEW;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-01 00:51:53 +11:00
|
|
|
bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object *ob, int output)
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
2014-04-27 00:20:13 +10:00
|
|
|
const char *name;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2011-11-14 06:46:07 +00:00
|
|
|
if (output == 0)
|
2011-08-03 18:31:48 +00:00
|
|
|
name = surface->output_name;
|
2011-11-14 06:46:07 +00:00
|
|
|
else if (output == 1)
|
2011-08-03 18:31:48 +00:00
|
|
|
name = surface->output_name2;
|
|
|
|
|
else
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
Mesh *me = ob->data;
|
2015-07-27 20:59:10 +10:00
|
|
|
return (CustomData_get_named_layer_index(&me->ldata, CD_MLOOPCOL, name) != -1);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
2016-05-12 13:15:55 +02:00
|
|
|
return (defgroup_name_index(ob, name) != -1);
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-04 19:27:51 +00:00
|
|
|
static bool surface_duplicateOutputExists(void *arg, const char *name)
|
2011-09-10 08:55:44 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
DynamicPaintSurface *t_surface = arg;
|
2011-09-10 08:55:44 +00:00
|
|
|
DynamicPaintSurface *surface = t_surface->canvas->surfaces.first;
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface != t_surface && surface->type == t_surface->type && surface->format == t_surface->format) {
|
|
|
|
|
if ((surface->output_name[0] != '\0' && !BLI_path_cmp(name, surface->output_name)) ||
|
|
|
|
|
(surface->output_name2[0] != '\0' && !BLI_path_cmp(name, surface->output_name2)))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-04 19:27:51 +00:00
|
|
|
return false;
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 16:05:44 +00:00
|
|
|
static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *basename, int output)
|
2011-09-10 08:55:44 +00:00
|
|
|
{
|
|
|
|
|
char name[64];
|
2011-10-28 14:46:09 +00:00
|
|
|
BLI_strncpy(name, basename, sizeof(name)); /* in case basename is surface->name use a copy */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (output == 0) {
|
|
|
|
|
BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.',
|
|
|
|
|
surface->output_name, sizeof(surface->output_name));
|
|
|
|
|
}
|
|
|
|
|
else if (output == 1) {
|
|
|
|
|
BLI_uniquename_cb(surface_duplicateOutputExists, surface, name, '.',
|
|
|
|
|
surface->output_name2, sizeof(surface->output_name2));
|
|
|
|
|
}
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-04 19:27:51 +00:00
|
|
|
static bool surface_duplicateNameExists(void *arg, const char *name)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
DynamicPaintSurface *t_surface = arg;
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintSurface *surface = t_surface->canvas->surfaces.first;
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface != t_surface && STREQ(name, surface->name))
|
|
|
|
|
return true;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2013-03-04 19:27:51 +00:00
|
|
|
return false;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
void dynamicPaintSurface_setUniqueName(DynamicPaintSurface *surface, const char *basename)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2011-06-16 10:41:00 +00:00
|
|
|
char name[64];
|
2011-10-28 14:46:09 +00:00
|
|
|
BLI_strncpy(name, basename, sizeof(name)); /* in case basename is surface->name use a copy */
|
2011-09-10 08:55:44 +00:00
|
|
|
BLI_uniquename_cb(surface_duplicateNameExists, surface, name, '.', surface->name, sizeof(surface->name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* change surface data to defaults on new type */
|
|
|
|
|
void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
2012-05-12 16:11:34 +00:00
|
|
|
surface->output_name[0] = '\0';
|
|
|
|
|
surface->output_name2[0] = '\0';
|
2011-09-10 08:55:44 +00:00
|
|
|
surface->flags |= MOD_DPAINT_ANTIALIAS;
|
2011-10-13 20:00:22 +00:00
|
|
|
surface->depth_clamp = 1.0f;
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-01-11 12:33:51 +00:00
|
|
|
strcpy(surface->output_name, "dp_");
|
2012-12-16 08:43:05 +00:00
|
|
|
BLI_strncpy(surface->output_name2, surface->output_name, sizeof(surface->output_name2));
|
2011-09-10 08:55:44 +00:00
|
|
|
surface->flags &= ~MOD_DPAINT_ANTIALIAS;
|
2011-10-13 20:00:22 +00:00
|
|
|
surface->depth_clamp = 0.0f;
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
2012-04-29 15:47:02 +00:00
|
|
|
strcat(surface->output_name, "paintmap");
|
|
|
|
|
strcat(surface->output_name2, "wetmap");
|
2011-09-10 08:55:44 +00:00
|
|
|
surface_setUniqueOutputName(surface, surface->output_name2, 1);
|
|
|
|
|
}
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
|
2012-04-29 15:47:02 +00:00
|
|
|
strcat(surface->output_name, "displace");
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
2012-04-29 15:47:02 +00:00
|
|
|
strcat(surface->output_name, "weight");
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
|
2012-04-29 15:47:02 +00:00
|
|
|
strcat(surface->output_name, "wave");
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface_setUniqueOutputName(surface, surface->output_name, 0);
|
|
|
|
|
|
|
|
|
|
/* update preview */
|
|
|
|
|
if (dynamicPaint_surfaceHasColorPreview(surface))
|
|
|
|
|
dynamicPaint_setPreview(surface);
|
|
|
|
|
else
|
|
|
|
|
dynamicPaint_resetPreview(surface->canvas);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
static int surface_totalSamples(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ && surface->flags & MOD_DPAINT_ANTIALIAS) {
|
2012-04-28 06:31:57 +00:00
|
|
|
return (surface->data->total_points * 5);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX &&
|
2012-04-28 06:31:57 +00:00
|
|
|
surface->flags & MOD_DPAINT_ANTIALIAS && surface->data->adj_data)
|
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
return (surface->data->total_points + surface->data->adj_data->total_targets);
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
return surface->data->total_points;
|
|
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
static void blendColors(
|
|
|
|
|
const float t_color[3], const float t_alpha, const float s_color[3], const float s_alpha, float result[4])
|
2011-10-31 13:01:06 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
/* Same thing as BLI's blend_color_mix_float(), but for non-premultiplied alpha. */
|
2011-10-31 13:01:06 +00:00
|
|
|
int i;
|
|
|
|
|
float i_alpha = 1.0f - s_alpha;
|
2012-05-12 16:11:34 +00:00
|
|
|
float f_alpha = t_alpha * i_alpha + s_alpha;
|
2011-10-31 13:01:06 +00:00
|
|
|
|
|
|
|
|
/* blend colors */
|
|
|
|
|
if (f_alpha) {
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha;
|
2011-10-31 13:01:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(result, t_color);
|
|
|
|
|
}
|
|
|
|
|
/* return final alpha */
|
|
|
|
|
result[3] = f_alpha;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 17:18:07 +00:00
|
|
|
/* Mix two alpha weighed colors by a defined ratio. output is saved at a_color */
|
2015-07-27 15:52:54 +10:00
|
|
|
static float mixColors(float a_color[3], float a_weight, const float b_color[3], float b_weight, float ratio)
|
2011-06-27 07:30:58 +00:00
|
|
|
{
|
2012-01-16 17:18:07 +00:00
|
|
|
float weight_ratio, factor;
|
|
|
|
|
if (b_weight) {
|
|
|
|
|
/* if first value has no weight just use b_color */
|
|
|
|
|
if (!a_weight) {
|
|
|
|
|
copy_v3_v3(a_color, b_color);
|
2012-05-12 16:11:34 +00:00
|
|
|
return b_weight * ratio;
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
weight_ratio = b_weight / (a_weight + b_weight);
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
return a_weight * (1.0f - ratio);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2012-01-16 17:18:07 +00:00
|
|
|
/* calculate final interpolation factor */
|
2012-05-12 16:11:34 +00:00
|
|
|
if (ratio <= 0.5f) {
|
|
|
|
|
factor = weight_ratio * (ratio * 2.0f);
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-12 16:11:34 +00:00
|
|
|
ratio = (ratio * 2.0f - 1.0f);
|
|
|
|
|
factor = weight_ratio * (1.0f - ratio) + ratio;
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
/* mix final color */
|
2012-01-16 17:18:07 +00:00
|
|
|
interp_v3_v3v3(a_color, a_color, b_color, factor);
|
2012-05-12 16:11:34 +00:00
|
|
|
return (1.0f - factor) * a_weight + factor * b_weight;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
static void scene_setSubframe(Scene *scene, float subframe)
|
|
|
|
|
{
|
|
|
|
|
/* dynamic paint subframes must be done on previous frame */
|
|
|
|
|
scene->r.cfra -= 1;
|
|
|
|
|
scene->r.subframe = subframe;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
static int surface_getBrushFlags(DynamicPaintSurface *surface, Depsgraph *depsgraph)
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
2018-06-25 14:21:15 +02:00
|
|
|
unsigned int numobjects;
|
|
|
|
|
Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
for (int i = 0; i < numobjects; i++) {
|
|
|
|
|
Object *brushObj = objects[i];
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
|
2011-08-03 18:31:48 +00:00
|
|
|
DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md;
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (pmd2->brush) {
|
2011-08-03 18:31:48 +00:00
|
|
|
DynamicPaintBrushSettings *brush = pmd2->brush;
|
|
|
|
|
|
|
|
|
|
if (brush->flags & MOD_DPAINT_USES_VELOCITY)
|
|
|
|
|
flags |= BRUSH_USES_VELOCITY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
BKE_collision_objects_free(objects);
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* check whether two bounds intersect */
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool boundsIntersect(Bounds3D *b1, Bounds3D *b2)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!b1->valid || !b2->valid)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 2; i--;) {
|
|
|
|
|
if (!(b1->min[i] <= b2->max[i] && b1->max[i] >= b2->min[i]))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* check whether two bounds intersect inside defined proximity */
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, const float dist)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!b1->valid || !b2->valid)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 2; i--;) {
|
|
|
|
|
if (!(b1->min[i] <= (b2->max[i] + dist) && b1->max[i] >= (b2->min[i] - dist)))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* check whether bounds intersects a point with given radius */
|
2016-12-28 17:30:58 +01:00
|
|
|
static bool boundIntersectPoint(Bounds3D *b, float point[3], const float radius)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!b->valid)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 2; i--;) {
|
|
|
|
|
if (!(b->min[i] <= (point[i] + radius) && b->max[i] >= (point[i] - radius)))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* expand bounds by a new point */
|
2011-07-22 18:37:30 +00:00
|
|
|
static void boundInsert(Bounds3D *b, float point[3])
|
|
|
|
|
{
|
2011-09-05 16:04:15 +00:00
|
|
|
if (!b->valid) {
|
2011-10-28 14:46:09 +00:00
|
|
|
copy_v3_v3(b->min, point);
|
|
|
|
|
copy_v3_v3(b->max, point);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
b->valid = true;
|
2016-05-12 12:08:03 +02:00
|
|
|
return;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
|
|
|
|
|
minmax_v3v3_v3(b->min, b->max, point);
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static float getSurfaceDimension(PaintSurfaceData *sData)
|
2012-01-16 17:18:07 +00:00
|
|
|
{
|
|
|
|
|
Bounds3D *mb = &sData->bData->mesh_bounds;
|
2012-12-21 05:07:26 +00:00
|
|
|
return max_fff((mb->max[0] - mb->min[0]), (mb->max[1] - mb->min[1]), (mb->max[2] - mb->min[2]));
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
static void freeGrid(PaintSurfaceData *data)
|
|
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = data->bData;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
|
|
|
|
|
if (grid->bounds) MEM_freeN(grid->bounds);
|
|
|
|
|
if (grid->s_pos) MEM_freeN(grid->s_pos);
|
|
|
|
|
if (grid->s_num) MEM_freeN(grid->s_num);
|
|
|
|
|
if (grid->t_index) MEM_freeN(grid->t_index);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(bData->grid);
|
|
|
|
|
bData->grid = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void grid_bound_insert_cb_ex(void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict tls)
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = userdata;
|
|
|
|
|
|
2018-01-05 16:33:13 +01:00
|
|
|
Bounds3D *grid_bound = tls->userdata_chunk;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
boundInsert(grid_bound, bData->realCoord[bData->s_pos[i]].v);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void grid_bound_insert_finalize(void *__restrict userdata,
|
|
|
|
|
void *__restrict userdata_chunk)
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = userdata;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
|
|
|
|
|
Bounds3D *grid_bound = userdata_chunk;
|
|
|
|
|
|
|
|
|
|
boundInsert(&grid->grid_bounds, grid_bound->min);
|
|
|
|
|
boundInsert(&grid->grid_bounds, grid_bound->max);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void grid_cell_points_cb_ex(void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict tls)
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = userdata;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
int *temp_t_index = grid->temp_t_index;
|
2018-01-05 16:33:13 +01:00
|
|
|
int *s_num = tls->userdata_chunk;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
int co[3];
|
|
|
|
|
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
co[j] = (int)floorf((bData->realCoord[bData->s_pos[i]].v[j] - grid->grid_bounds.min[j]) /
|
|
|
|
|
bData->dim[j] * grid->dim[j]);
|
|
|
|
|
CLAMP(co[j], 0, grid->dim[j] - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
temp_t_index[i] = co[0] + co[1] * grid->dim[0] + co[2] * grid->dim[0] * grid->dim[1];
|
|
|
|
|
s_num[temp_t_index[i]]++;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void grid_cell_points_finalize(void *__restrict userdata,
|
|
|
|
|
void *__restrict userdata_chunk)
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = userdata;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
const int grid_cells = grid->dim[0] * grid->dim[1] * grid->dim[2];
|
|
|
|
|
|
|
|
|
|
int *s_num = userdata_chunk;
|
|
|
|
|
|
|
|
|
|
/* calculate grid indexes */
|
|
|
|
|
for (int i = 0; i < grid_cells; i++) {
|
|
|
|
|
grid->s_num[i] += s_num[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void grid_cell_bounds_cb(void *__restrict userdata,
|
|
|
|
|
const int x,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = userdata;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
float *dim = bData->dim;
|
|
|
|
|
int *grid_dim = grid->dim;
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < grid_dim[1]; y++) {
|
|
|
|
|
for (int z = 0; z < grid_dim[2]; z++) {
|
|
|
|
|
const int b_index = x + y * grid_dim[0] + z * grid_dim[0] * grid_dim[1];
|
|
|
|
|
/* set bounds */
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
const int s = (j == 0) ? x : ((j == 1) ? y : z);
|
|
|
|
|
grid->bounds[b_index].min[j] = grid->grid_bounds.min[j] + dim[j] / grid_dim[j] * s;
|
|
|
|
|
grid->bounds[b_index].max[j] = grid->grid_bounds.min[j] + dim[j] / grid_dim[j] * (s + 1);
|
|
|
|
|
}
|
|
|
|
|
grid->bounds[b_index].valid = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
static void surfaceGenerateGrid(struct DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
|
|
|
|
VolumeGrid *grid;
|
|
|
|
|
int grid_cells, axis = 3;
|
|
|
|
|
int *temp_t_index = NULL;
|
|
|
|
|
int *temp_s_num = NULL;
|
|
|
|
|
|
|
|
|
|
if (bData->grid)
|
|
|
|
|
freeGrid(sData);
|
|
|
|
|
|
|
|
|
|
bData->grid = MEM_callocN(sizeof(VolumeGrid), "Surface Grid");
|
|
|
|
|
grid = bData->grid;
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
{
|
2011-10-13 20:00:22 +00:00
|
|
|
int i, error = 0;
|
2011-07-22 18:37:30 +00:00
|
|
|
float dim_factor, volume, dim[3];
|
2011-10-13 20:00:22 +00:00
|
|
|
float td[3];
|
2011-08-03 18:31:48 +00:00
|
|
|
float min_dim;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* calculate canvas dimensions */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Important to init correctly our ref grid_bound... */
|
|
|
|
|
boundInsert(&grid->grid_bounds, bData->realCoord[bData->s_pos[0]].v);
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
settings.userdata_chunk = &grid->grid_bounds;
|
|
|
|
|
settings.userdata_chunk_size = sizeof(grid->grid_bounds);
|
|
|
|
|
settings.func_finalize = grid_bound_insert_finalize;
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
bData,
|
|
|
|
|
grid_bound_insert_cb_ex,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
/* get dimensions */
|
|
|
|
|
sub_v3_v3v3(dim, grid->grid_bounds.max, grid->grid_bounds.min);
|
|
|
|
|
copy_v3_v3(td, dim);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
copy_v3_v3(bData->dim, dim);
|
2012-12-21 05:07:26 +00:00
|
|
|
min_dim = max_fff(td[0], td[1], td[2]) / 1000.f;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* deactivate zero axises */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (td[i] < min_dim) {
|
|
|
|
|
td[i] = 1.0f;
|
|
|
|
|
axis--;
|
|
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2012-12-21 05:07:26 +00:00
|
|
|
if (axis == 0 || max_fff(td[0], td[1], td[2]) < 0.0001f) {
|
2011-10-13 20:00:22 +00:00
|
|
|
MEM_freeN(bData->grid);
|
|
|
|
|
bData->grid = NULL;
|
2011-07-22 18:37:30 +00:00
|
|
|
return;
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* now calculate grid volume/area/width depending on num of active axis */
|
2012-05-12 16:11:34 +00:00
|
|
|
volume = td[0] * td[1] * td[2];
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* determine final grid size by trying to fit average 10.000 points per grid cell */
|
2012-11-04 06:21:09 +00:00
|
|
|
dim_factor = (float)pow((double)volume / ((double)sData->total_points / 10000.0), 1.0 / (double)axis);
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* define final grid size using dim_factor, use min 3 for active axises */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2011-10-13 20:00:22 +00:00
|
|
|
grid->dim[i] = (int)floor(td[i] / dim_factor);
|
2012-05-12 16:11:34 +00:00
|
|
|
CLAMP(grid->dim[i], (dim[i] >= min_dim) ? 3 : 1, 100);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
grid_cells = grid->dim[0] * grid->dim[1] * grid->dim[2];
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* allocate memory for grids */
|
|
|
|
|
grid->bounds = MEM_callocN(sizeof(Bounds3D) * grid_cells, "Surface Grid Bounds");
|
|
|
|
|
grid->s_pos = MEM_callocN(sizeof(int) * grid_cells, "Surface Grid Position");
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
grid->s_num = MEM_callocN(sizeof(int) * grid_cells, "Surface Grid Points");
|
2011-07-22 18:37:30 +00:00
|
|
|
temp_s_num = MEM_callocN(sizeof(int) * grid_cells, "Temp Surface Grid Points");
|
|
|
|
|
grid->t_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Grid Target Ids");
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
grid->temp_t_index = temp_t_index = MEM_callocN(sizeof(int) * sData->total_points, "Temp Surface Grid Target Ids");
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2012-03-04 04:35:12 +00:00
|
|
|
/* in case of an allocation failure abort here */
|
2011-07-22 18:37:30 +00:00
|
|
|
if (!grid->bounds || !grid->s_pos || !grid->s_num || !grid->t_index || !temp_s_num || !temp_t_index)
|
|
|
|
|
error = 1;
|
|
|
|
|
|
|
|
|
|
if (!error) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* calculate number of points within each cell */
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
settings.userdata_chunk = grid->s_num;
|
|
|
|
|
settings.userdata_chunk_size = sizeof(*grid->s_num) * grid_cells;
|
|
|
|
|
settings.func_finalize = grid_cell_points_finalize;
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
bData,
|
|
|
|
|
grid_cell_points_cb_ex,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* calculate grid indexes (not needed for first cell, which is zero). */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 1; i < grid_cells; i++) {
|
|
|
|
|
grid->s_pos[i] = grid->s_pos[i - 1] + grid->s_num[i - 1];
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* save point indexes to final array */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < sData->total_points; i++) {
|
2011-10-13 20:00:22 +00:00
|
|
|
int pos = grid->s_pos[temp_t_index[i]] + temp_s_num[temp_t_index[i]];
|
|
|
|
|
grid->t_index[pos] = i;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
temp_s_num[temp_t_index[i]]++;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate cell bounds */
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (grid_cells > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, grid->dim[0],
|
|
|
|
|
bData,
|
|
|
|
|
grid_cell_bounds_cb,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (temp_s_num)
|
|
|
|
|
MEM_freeN(temp_s_num);
|
|
|
|
|
if (temp_t_index)
|
|
|
|
|
MEM_freeN(temp_t_index);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
grid->temp_t_index = NULL;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
if (error || !grid->s_num) {
|
2012-10-26 17:32:50 +00:00
|
|
|
setError(surface->canvas, N_("Not enough free memory"));
|
2011-07-22 18:37:30 +00:00
|
|
|
freeGrid(sData);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/***************************** Freeing data ******************************/
|
|
|
|
|
|
|
|
|
|
/* Free brush data */
|
2011-09-05 16:04:15 +00:00
|
|
|
void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->brush) {
|
2018-09-24 16:32:29 +02:00
|
|
|
if (pmd->brush->mesh) {
|
|
|
|
|
BKE_id_free(NULL, pmd->brush->mesh);
|
|
|
|
|
}
|
|
|
|
|
pmd->brush->mesh = NULL;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->brush->paint_ramp)
|
2012-05-12 16:11:34 +00:00
|
|
|
MEM_freeN(pmd->brush->paint_ramp);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->brush->vel_ramp)
|
2012-05-12 16:11:34 +00:00
|
|
|
MEM_freeN(pmd->brush->vel_ramp);
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(pmd->brush);
|
|
|
|
|
pmd->brush = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-08 11:03:37 +00:00
|
|
|
static void dynamicPaint_freeAdjData(PaintSurfaceData *data)
|
2011-06-27 07:30:58 +00:00
|
|
|
{
|
2011-07-02 18:06:39 +00:00
|
|
|
if (data->adj_data) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (data->adj_data->n_index)
|
|
|
|
|
MEM_freeN(data->adj_data->n_index);
|
|
|
|
|
if (data->adj_data->n_num)
|
|
|
|
|
MEM_freeN(data->adj_data->n_num);
|
|
|
|
|
if (data->adj_data->n_target)
|
|
|
|
|
MEM_freeN(data->adj_data->n_target);
|
|
|
|
|
if (data->adj_data->flags)
|
|
|
|
|
MEM_freeN(data->adj_data->flags);
|
2017-01-03 18:50:15 +03:00
|
|
|
if (data->adj_data->border)
|
|
|
|
|
MEM_freeN(data->adj_data->border);
|
2011-07-02 18:06:39 +00:00
|
|
|
MEM_freeN(data->adj_data);
|
2011-07-08 11:03:37 +00:00
|
|
|
data->adj_data = NULL;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
static void free_bakeData(PaintSurfaceData *data)
|
|
|
|
|
{
|
|
|
|
|
PaintBakeData *bData = data->bData;
|
|
|
|
|
if (bData) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (bData->bNormal)
|
|
|
|
|
MEM_freeN(bData->bNormal);
|
|
|
|
|
if (bData->s_pos)
|
|
|
|
|
MEM_freeN(bData->s_pos);
|
|
|
|
|
if (bData->s_num)
|
|
|
|
|
MEM_freeN(bData->s_num);
|
|
|
|
|
if (bData->realCoord)
|
|
|
|
|
MEM_freeN(bData->realCoord);
|
|
|
|
|
if (bData->bNeighs)
|
|
|
|
|
MEM_freeN(bData->bNeighs);
|
|
|
|
|
if (bData->grid)
|
|
|
|
|
freeGrid(data);
|
|
|
|
|
if (bData->prev_verts)
|
|
|
|
|
MEM_freeN(bData->prev_verts);
|
|
|
|
|
if (bData->velocity)
|
|
|
|
|
MEM_freeN(bData->velocity);
|
|
|
|
|
if (bData->prev_velocity)
|
|
|
|
|
MEM_freeN(bData->prev_velocity);
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(data->bData);
|
|
|
|
|
data->bData = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-21 19:03:47 +00:00
|
|
|
/* free surface data if it's not used anymore */
|
2012-09-15 01:52:28 +00:00
|
|
|
static void surface_freeUnusedData(DynamicPaintSurface *surface)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!surface->data)
|
|
|
|
|
return;
|
2011-08-21 19:03:47 +00:00
|
|
|
|
|
|
|
|
/* free bakedata if not active or surface is baked */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!(surface->flags & MOD_DPAINT_ACTIVE) || (surface->pointcache && surface->pointcache->flag & PTCACHE_BAKED)) {
|
2011-08-21 19:03:47 +00:00
|
|
|
free_bakeData(surface->data);
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2011-08-21 19:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
void dynamicPaint_freeSurfaceData(DynamicPaintSurface *surface)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *data = surface->data;
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!data)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
if (data->format_data) {
|
|
|
|
|
/* format specific free */
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
2012-05-12 16:11:34 +00:00
|
|
|
ImgSeqFormatData *format_data = (ImgSeqFormatData *)data->format_data;
|
2011-06-27 07:30:58 +00:00
|
|
|
if (format_data->uv_p)
|
|
|
|
|
MEM_freeN(format_data->uv_p);
|
|
|
|
|
if (format_data->barycentricWeights)
|
|
|
|
|
MEM_freeN(format_data->barycentricWeights);
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(data->format_data);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
/* type data */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (data->type_data)
|
|
|
|
|
MEM_freeN(data->type_data);
|
2011-07-08 11:03:37 +00:00
|
|
|
dynamicPaint_freeAdjData(data);
|
2011-07-22 18:37:30 +00:00
|
|
|
/* bake data */
|
|
|
|
|
free_bakeData(data);
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
MEM_freeN(surface->data);
|
|
|
|
|
surface->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 10:22:32 +01:00
|
|
|
void dynamicPaint_freeSurface(const DynamicPaintModifierData *pmd,
|
|
|
|
|
DynamicPaintSurface *surface)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
/* point cache */
|
2018-11-20 10:22:32 +01:00
|
|
|
if ((pmd->modifier.flag & eModifierFlag_SharedCaches) == 0) {
|
|
|
|
|
BKE_ptcache_free_list(&(surface->ptcaches));
|
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
surface->pointcache = NULL;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (surface->effector_weights)
|
2011-06-27 07:30:58 +00:00
|
|
|
MEM_freeN(surface->effector_weights);
|
|
|
|
|
surface->effector_weights = NULL;
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
BLI_remlink(&(surface->canvas->surfaces), surface);
|
|
|
|
|
dynamicPaint_freeSurfaceData(surface);
|
|
|
|
|
MEM_freeN(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free canvas data */
|
2011-09-05 16:04:15 +00:00
|
|
|
void dynamicPaint_freeCanvas(DynamicPaintModifierData *pmd)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->canvas) {
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Free surface data */
|
|
|
|
|
DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
|
|
|
|
|
DynamicPaintSurface *next_surface = NULL;
|
|
|
|
|
|
|
|
|
|
while (surface) {
|
|
|
|
|
next_surface = surface->next;
|
2018-11-20 10:22:32 +01:00
|
|
|
dynamicPaint_freeSurface(pmd, surface);
|
2011-06-16 10:41:00 +00:00
|
|
|
surface = next_surface;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* free mesh copy */
|
|
|
|
|
if (pmd->canvas->mesh) {
|
|
|
|
|
BKE_id_free(NULL, pmd->canvas->mesh);
|
|
|
|
|
}
|
|
|
|
|
pmd->canvas->mesh = NULL;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(pmd->canvas);
|
|
|
|
|
pmd->canvas = NULL;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Free whole dp modifier */
|
|
|
|
|
void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd) {
|
2011-06-16 10:41:00 +00:00
|
|
|
dynamicPaint_freeCanvas(pmd);
|
|
|
|
|
dynamicPaint_freeBrush(pmd);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/***************************** Initialize and reset ******************************/
|
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
/*
|
2012-05-12 16:11:34 +00:00
|
|
|
* Creates a new surface and adds it to the list
|
|
|
|
|
* If scene is null, frame range of 1-250 is used
|
|
|
|
|
* A pointer to this surface is returned
|
|
|
|
|
*/
|
2012-05-17 23:21:11 +00:00
|
|
|
DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas, Scene *scene)
|
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
DynamicPaintSurface *surface = MEM_callocN(sizeof(DynamicPaintSurface), "DynamicPaintSurface");
|
2013-03-25 08:29:06 +00:00
|
|
|
if (!surface)
|
|
|
|
|
return NULL;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
surface->canvas = canvas;
|
|
|
|
|
surface->format = MOD_DPAINT_SURFACE_F_VERTEX;
|
|
|
|
|
surface->type = MOD_DPAINT_SURFACE_T_PAINT;
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* cache */
|
|
|
|
|
surface->pointcache = BKE_ptcache_add(&(surface->ptcaches));
|
|
|
|
|
surface->pointcache->flag |= PTCACHE_DISK_CACHE;
|
|
|
|
|
surface->pointcache->step = 1;
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Set initial values */
|
2011-06-27 07:30:58 +00:00
|
|
|
surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | MOD_DPAINT_DISSOLVE_LOG |
|
2012-05-12 16:11:34 +00:00
|
|
|
MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING;
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->effect = 0;
|
|
|
|
|
surface->effect_ui = 1;
|
|
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
surface->diss_speed = 250;
|
|
|
|
|
surface->dry_speed = 500;
|
2012-01-16 17:18:07 +00:00
|
|
|
surface->color_dry_threshold = 1.0f;
|
2011-10-13 20:00:22 +00:00
|
|
|
surface->depth_clamp = 0.0f;
|
|
|
|
|
surface->disp_factor = 1.0f;
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->disp_type = MOD_DPAINT_DISP_DISPLACE;
|
|
|
|
|
surface->image_fileformat = MOD_DPAINT_IMGFORMAT_PNG;
|
|
|
|
|
|
2012-01-16 17:18:07 +00:00
|
|
|
surface->influence_scale = 1.0f;
|
|
|
|
|
surface->radius_scale = 1.0f;
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
surface->init_color[0] = 1.0f;
|
|
|
|
|
surface->init_color[1] = 1.0f;
|
|
|
|
|
surface->init_color[2] = 1.0f;
|
|
|
|
|
surface->init_color[3] = 1.0f;
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->image_resolution = 256;
|
2011-08-28 16:36:47 +00:00
|
|
|
surface->substeps = 0;
|
2011-07-08 11:03:37 +00:00
|
|
|
|
|
|
|
|
if (scene) {
|
|
|
|
|
surface->start_frame = scene->r.sfra;
|
|
|
|
|
surface->end_frame = scene->r.efra;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
surface->start_frame = 1;
|
|
|
|
|
surface->end_frame = 250;
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
surface->spread_speed = 1.0f;
|
2011-08-05 09:31:35 +00:00
|
|
|
surface->color_spread_speed = 1.0f;
|
2011-06-16 10:41:00 +00:00
|
|
|
surface->shrink_speed = 1.0f;
|
|
|
|
|
|
2011-11-16 18:32:28 +00:00
|
|
|
surface->wave_damping = 0.04f;
|
2011-10-31 13:01:06 +00:00
|
|
|
surface->wave_speed = 1.0f;
|
2011-07-02 18:06:39 +00:00
|
|
|
surface->wave_timescale = 1.0f;
|
2011-11-10 13:00:27 +00:00
|
|
|
surface->wave_spring = 0.20f;
|
2013-08-03 09:46:38 +00:00
|
|
|
surface->wave_smoothness = 1.0f;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2011-11-22 10:04:28 +00:00
|
|
|
modifier_path_init(surface->image_output_path, sizeof(surface->image_output_path), "cache_dynamicpaint");
|
2011-11-20 14:38:11 +00:00
|
|
|
|
2013-03-25 08:29:06 +00:00
|
|
|
/* Using ID_BRUSH i18n context, as we have no physics/dpaint one for now... */
|
2015-08-16 17:32:01 +10:00
|
|
|
dynamicPaintSurface_setUniqueName(surface, CTX_DATA_(BLT_I18NCONTEXT_ID_BRUSH, "Surface"));
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2018-12-02 14:14:51 +11:00
|
|
|
surface->effector_weights = BKE_effector_add_weights(NULL);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
dynamicPaintSurface_updateType(surface);
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&canvas->surfaces, surface);
|
|
|
|
|
|
|
|
|
|
return surface;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2012-05-12 16:11:34 +00:00
|
|
|
* Initialize modifier data
|
|
|
|
|
*/
|
2014-02-05 22:36:15 +11:00
|
|
|
bool dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, struct Scene *scene)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd) {
|
|
|
|
|
if (type == MOD_DYNAMICPAINT_TYPE_CANVAS) {
|
2011-10-31 13:01:06 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->canvas)
|
2011-06-16 10:41:00 +00:00
|
|
|
dynamicPaint_freeCanvas(pmd);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
canvas = pmd->canvas = MEM_callocN(sizeof(DynamicPaintCanvasSettings), "DynamicPaint Canvas");
|
|
|
|
|
if (!canvas)
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-10-31 13:01:06 +00:00
|
|
|
canvas->pmd = pmd;
|
2018-09-24 16:32:29 +02:00
|
|
|
canvas->mesh = NULL;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Create one surface */
|
2011-10-31 13:01:06 +00:00
|
|
|
if (!dynamicPaint_createNewSurface(canvas, scene))
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (type == MOD_DYNAMICPAINT_TYPE_BRUSH) {
|
2011-10-31 13:01:06 +00:00
|
|
|
DynamicPaintBrushSettings *brush;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->brush)
|
2011-06-16 10:41:00 +00:00
|
|
|
dynamicPaint_freeBrush(pmd);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
brush = pmd->brush = MEM_callocN(sizeof(DynamicPaintBrushSettings), "DynamicPaint Paint");
|
|
|
|
|
if (!brush)
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->pmd = pmd;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
brush->psys = NULL;
|
|
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->flags = MOD_DPAINT_ABS_ALPHA | MOD_DPAINT_RAMP_ALPHA;
|
|
|
|
|
brush->collision = MOD_DPAINT_COL_VOLUME;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->r = 0.15f;
|
|
|
|
|
brush->g = 0.4f;
|
|
|
|
|
brush->b = 0.8f;
|
|
|
|
|
brush->alpha = 1.0f;
|
|
|
|
|
brush->wetness = 1.0f;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->paint_distance = 1.0f;
|
|
|
|
|
brush->proximity_falloff = MOD_DPAINT_PRFALL_SMOOTH;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->particle_radius = 0.2f;
|
|
|
|
|
brush->particle_smooth = 0.05f;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2011-11-16 18:32:28 +00:00
|
|
|
brush->wave_type = MOD_DPAINT_WAVEB_CHANGE;
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->wave_factor = 1.0f;
|
|
|
|
|
brush->wave_clamp = 0.0f;
|
|
|
|
|
brush->smudge_strength = 0.3f;
|
|
|
|
|
brush->max_velocity = 1.0f;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
brush->mesh = NULL;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* Paint proximity falloff colorramp. */
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
|
|
|
|
CBData *ramp;
|
|
|
|
|
|
2017-12-07 15:52:59 +11:00
|
|
|
brush->paint_ramp = BKE_colorband_add(false);
|
2011-10-31 13:01:06 +00:00
|
|
|
if (!brush->paint_ramp)
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-10-31 13:01:06 +00:00
|
|
|
ramp = brush->paint_ramp->data;
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Add default smooth-falloff ramp. */
|
2011-05-24 07:08:58 +00:00
|
|
|
ramp[0].r = ramp[0].g = ramp[0].b = ramp[0].a = 1.0f;
|
|
|
|
|
ramp[0].pos = 0.0f;
|
|
|
|
|
ramp[1].r = ramp[1].g = ramp[1].b = ramp[1].pos = 1.0f;
|
|
|
|
|
ramp[1].a = 0.0f;
|
2011-06-16 10:41:00 +00:00
|
|
|
pmd->brush->paint_ramp->tot = 2;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* Brush velocity ramp. */
|
|
|
|
|
{
|
|
|
|
|
CBData *ramp;
|
|
|
|
|
|
2017-12-07 15:52:59 +11:00
|
|
|
brush->vel_ramp = BKE_colorband_add(false);
|
2011-10-31 13:01:06 +00:00
|
|
|
if (!brush->vel_ramp)
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2011-10-31 13:01:06 +00:00
|
|
|
ramp = brush->vel_ramp->data;
|
2011-08-03 18:31:48 +00:00
|
|
|
ramp[0].r = ramp[0].g = ramp[0].b = ramp[0].a = ramp[0].pos = 0.0f;
|
|
|
|
|
ramp[1].r = ramp[1].g = ramp[1].b = ramp[1].a = ramp[1].pos = 1.0f;
|
2011-10-31 13:01:06 +00:00
|
|
|
brush->paint_ramp->tot = 2;
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-12-01 17:11:18 +01:00
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-07-08 11:03:37 +00:00
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-20 10:22:32 +01:00
|
|
|
void dynamicPaint_Modifier_copy(const struct DynamicPaintModifierData *pmd,
|
|
|
|
|
struct DynamicPaintModifierData *tpmd,
|
|
|
|
|
int flag)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Init modifier */
|
2011-05-24 07:08:58 +00:00
|
|
|
tpmd->type = pmd->type;
|
2011-07-08 11:03:37 +00:00
|
|
|
if (pmd->canvas)
|
|
|
|
|
dynamicPaint_createType(tpmd, MOD_DYNAMICPAINT_TYPE_CANVAS, NULL);
|
|
|
|
|
if (pmd->brush)
|
|
|
|
|
dynamicPaint_createType(tpmd, MOD_DYNAMICPAINT_TYPE_BRUSH, NULL);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Copy data */
|
2011-05-24 07:08:58 +00:00
|
|
|
if (tpmd->canvas) {
|
2012-12-16 19:19:45 +00:00
|
|
|
DynamicPaintSurface *surface;
|
2011-09-05 16:04:15 +00:00
|
|
|
tpmd->canvas->pmd = tpmd;
|
2012-12-16 19:19:45 +00:00
|
|
|
/* free default surface */
|
|
|
|
|
if (tpmd->canvas->surfaces.first)
|
2018-11-20 10:22:32 +01:00
|
|
|
dynamicPaint_freeSurface(tpmd, tpmd->canvas->surfaces.first);
|
2012-12-16 19:19:45 +00:00
|
|
|
|
|
|
|
|
/* copy existing surfaces */
|
|
|
|
|
for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
|
|
|
|
|
DynamicPaintSurface *t_surface = dynamicPaint_createNewSurface(tpmd->canvas, NULL);
|
2018-11-20 10:22:32 +01:00
|
|
|
if (flag & LIB_ID_CREATE_NO_MAIN) {
|
|
|
|
|
/* TODO(sergey): Consider passing some tips to the surface
|
|
|
|
|
* creation to avoid this allocate-and-free cache behavior. */
|
|
|
|
|
BKE_ptcache_free_list(&t_surface->ptcaches);
|
|
|
|
|
tpmd->modifier.flag |= eModifierFlag_SharedCaches;
|
|
|
|
|
t_surface->ptcaches = surface->ptcaches;
|
|
|
|
|
t_surface->pointcache = surface->pointcache;
|
|
|
|
|
}
|
2012-12-16 19:19:45 +00:00
|
|
|
|
|
|
|
|
/* surface settings */
|
|
|
|
|
t_surface->brush_group = surface->brush_group;
|
|
|
|
|
MEM_freeN(t_surface->effector_weights);
|
|
|
|
|
t_surface->effector_weights = MEM_dupallocN(surface->effector_weights);
|
|
|
|
|
|
|
|
|
|
BLI_strncpy(t_surface->name, surface->name, sizeof(t_surface->name));
|
|
|
|
|
t_surface->format = surface->format;
|
|
|
|
|
t_surface->type = surface->type;
|
|
|
|
|
t_surface->disp_type = surface->disp_type;
|
|
|
|
|
t_surface->image_fileformat = surface->image_fileformat;
|
|
|
|
|
t_surface->effect_ui = surface->effect_ui;
|
|
|
|
|
t_surface->preview_id = surface->preview_id;
|
|
|
|
|
t_surface->init_color_type = surface->init_color_type;
|
|
|
|
|
t_surface->flags = surface->flags;
|
|
|
|
|
t_surface->effect = surface->effect;
|
|
|
|
|
|
|
|
|
|
t_surface->image_resolution = surface->image_resolution;
|
|
|
|
|
t_surface->substeps = surface->substeps;
|
|
|
|
|
t_surface->start_frame = surface->start_frame;
|
|
|
|
|
t_surface->end_frame = surface->end_frame;
|
|
|
|
|
|
|
|
|
|
copy_v4_v4(t_surface->init_color, surface->init_color);
|
|
|
|
|
t_surface->init_texture = surface->init_texture;
|
|
|
|
|
BLI_strncpy(t_surface->init_layername, surface->init_layername, sizeof(t_surface->init_layername));
|
|
|
|
|
|
|
|
|
|
t_surface->dry_speed = surface->dry_speed;
|
|
|
|
|
t_surface->diss_speed = surface->diss_speed;
|
|
|
|
|
t_surface->color_dry_threshold = surface->color_dry_threshold;
|
|
|
|
|
t_surface->depth_clamp = surface->depth_clamp;
|
|
|
|
|
t_surface->disp_factor = surface->disp_factor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t_surface->spread_speed = surface->spread_speed;
|
|
|
|
|
t_surface->color_spread_speed = surface->color_spread_speed;
|
|
|
|
|
t_surface->shrink_speed = surface->shrink_speed;
|
|
|
|
|
t_surface->drip_vel = surface->drip_vel;
|
|
|
|
|
t_surface->drip_acc = surface->drip_acc;
|
|
|
|
|
|
|
|
|
|
t_surface->influence_scale = surface->influence_scale;
|
|
|
|
|
t_surface->radius_scale = surface->radius_scale;
|
|
|
|
|
|
|
|
|
|
t_surface->wave_damping = surface->wave_damping;
|
|
|
|
|
t_surface->wave_speed = surface->wave_speed;
|
|
|
|
|
t_surface->wave_timescale = surface->wave_timescale;
|
|
|
|
|
t_surface->wave_spring = surface->wave_spring;
|
2013-08-03 09:46:38 +00:00
|
|
|
t_surface->wave_smoothness = surface->wave_smoothness;
|
2012-12-16 19:19:45 +00:00
|
|
|
|
|
|
|
|
BLI_strncpy(t_surface->uvlayer_name, surface->uvlayer_name, sizeof(t_surface->uvlayer_name));
|
|
|
|
|
BLI_strncpy(t_surface->image_output_path, surface->image_output_path, sizeof(t_surface->image_output_path));
|
|
|
|
|
BLI_strncpy(t_surface->output_name, surface->output_name, sizeof(t_surface->output_name));
|
|
|
|
|
BLI_strncpy(t_surface->output_name2, surface->output_name2, sizeof(t_surface->output_name2));
|
|
|
|
|
}
|
|
|
|
|
dynamicPaint_resetPreview(tpmd->canvas);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else if (tpmd->brush) {
|
2011-10-31 13:01:06 +00:00
|
|
|
DynamicPaintBrushSettings *brush = pmd->brush, *t_brush = tpmd->brush;
|
|
|
|
|
t_brush->pmd = tpmd;
|
|
|
|
|
|
|
|
|
|
t_brush->flags = brush->flags;
|
|
|
|
|
t_brush->collision = brush->collision;
|
|
|
|
|
|
|
|
|
|
t_brush->r = brush->r;
|
|
|
|
|
t_brush->g = brush->g;
|
|
|
|
|
t_brush->b = brush->b;
|
|
|
|
|
t_brush->alpha = brush->alpha;
|
|
|
|
|
t_brush->wetness = brush->wetness;
|
|
|
|
|
|
|
|
|
|
t_brush->particle_radius = brush->particle_radius;
|
|
|
|
|
t_brush->particle_smooth = brush->particle_smooth;
|
|
|
|
|
t_brush->paint_distance = brush->paint_distance;
|
2016-12-28 17:30:58 +01:00
|
|
|
t_brush->psys = brush->psys;
|
2011-10-31 13:01:06 +00:00
|
|
|
|
|
|
|
|
if (brush->paint_ramp)
|
|
|
|
|
memcpy(t_brush->paint_ramp, brush->paint_ramp, sizeof(ColorBand));
|
|
|
|
|
if (brush->vel_ramp)
|
|
|
|
|
memcpy(t_brush->vel_ramp, brush->vel_ramp, sizeof(ColorBand));
|
|
|
|
|
|
|
|
|
|
t_brush->proximity_falloff = brush->proximity_falloff;
|
|
|
|
|
t_brush->wave_type = brush->wave_type;
|
|
|
|
|
t_brush->ray_dir = brush->ray_dir;
|
|
|
|
|
|
|
|
|
|
t_brush->wave_factor = brush->wave_factor;
|
|
|
|
|
t_brush->wave_clamp = brush->wave_clamp;
|
|
|
|
|
t_brush->max_velocity = brush->max_velocity;
|
|
|
|
|
t_brush->smudge_strength = brush->smudge_strength;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* allocates surface data depending on surface type */
|
|
|
|
|
static void dynamicPaint_allocateSurfaceType(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
switch (surface->type) {
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_PAINT:
|
2012-05-12 16:11:34 +00:00
|
|
|
sData->type_data = MEM_callocN(sizeof(PaintPoint) * sData->total_points, "DynamicPaintSurface Data");
|
2011-10-13 20:00:22 +00:00
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_DISPLACE:
|
2012-05-12 16:11:34 +00:00
|
|
|
sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface DepthData");
|
2011-10-13 20:00:22 +00:00
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_WEIGHT:
|
2012-05-12 16:11:34 +00:00
|
|
|
sData->type_data = MEM_callocN(sizeof(float) * sData->total_points, "DynamicPaintSurface WeightData");
|
2011-10-13 20:00:22 +00:00
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_WAVE:
|
2012-05-12 16:11:34 +00:00
|
|
|
sData->type_data = MEM_callocN(sizeof(PaintWavePoint) * sData->total_points, "DynamicPaintSurface WaveData");
|
2011-10-13 20:00:22 +00:00
|
|
|
break;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (sData->type_data == NULL)
|
|
|
|
|
setError(surface->canvas, N_("Not enough free memory"));
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool surface_usesAdjDistance(DynamicPaintSurface *surface)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
return ((surface->type == MOD_DPAINT_SURFACE_T_PAINT && surface->effect) ||
|
|
|
|
|
(surface->type == MOD_DPAINT_SURFACE_T_WAVE));
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool surface_usesAdjData(DynamicPaintSurface *surface)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2016-05-12 12:08:03 +02:00
|
|
|
return (surface_usesAdjDistance(surface) ||
|
|
|
|
|
(surface->format == MOD_DPAINT_SURFACE_F_VERTEX && surface->flags & MOD_DPAINT_ANTIALIAS));
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/* initialize surface adjacency data */
|
2016-05-12 12:08:03 +02:00
|
|
|
static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const bool force_init)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2011-06-27 07:30:58 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = surface->canvas->mesh;
|
2012-01-24 17:28:50 +00:00
|
|
|
PaintAdjData *ad;
|
2011-07-02 18:06:39 +00:00
|
|
|
int *temp_data;
|
2011-06-27 07:30:58 +00:00
|
|
|
int neigh_points = 0;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (!force_init && !surface_usesAdjData(surface))
|
2016-05-12 12:08:03 +02:00
|
|
|
return;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2012-03-09 00:41:09 +00:00
|
|
|
/* For vertex format, neighbors are connected by edges */
|
2018-09-24 16:32:29 +02:00
|
|
|
neigh_points = 2 * mesh->totedge;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2016-05-12 12:08:03 +02:00
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
2012-05-12 16:11:34 +00:00
|
|
|
neigh_points = sData->total_points * 8;
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!neigh_points)
|
|
|
|
|
return;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
/* allocate memory */
|
2012-01-24 17:28:50 +00:00
|
|
|
ad = sData->adj_data = MEM_callocN(sizeof(PaintAdjData), "Surface Adj Data");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!ad)
|
|
|
|
|
return;
|
2012-05-12 16:11:34 +00:00
|
|
|
ad->n_index = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Index");
|
|
|
|
|
ad->n_num = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Counts");
|
|
|
|
|
temp_data = MEM_callocN(sizeof(int) * sData->total_points, "Temp Adj Data");
|
|
|
|
|
ad->n_target = MEM_callocN(sizeof(int) * neigh_points, "Surface Adj Targets");
|
|
|
|
|
ad->flags = MEM_callocN(sizeof(int) * sData->total_points, "Surface Adj Flags");
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->total_targets = neigh_points;
|
2017-01-03 18:50:15 +03:00
|
|
|
ad->border = NULL;
|
|
|
|
|
ad->total_border = 0;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
/* in case of allocation error, free memory */
|
2012-01-24 17:28:50 +00:00
|
|
|
if (!ad->n_index || !ad->n_num || !ad->n_target || !temp_data) {
|
2011-07-08 11:03:37 +00:00
|
|
|
dynamicPaint_freeAdjData(sData);
|
2016-05-12 12:08:03 +02:00
|
|
|
if (temp_data)
|
|
|
|
|
MEM_freeN(temp_data);
|
2012-10-26 17:32:50 +00:00
|
|
|
setError(surface->canvas, N_("Not enough free memory"));
|
2011-06-27 07:30:58 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2011-07-02 18:06:39 +00:00
|
|
|
int i;
|
2011-06-27 07:30:58 +00:00
|
|
|
int n_pos;
|
|
|
|
|
|
|
|
|
|
/* For vertex format, count every vertex that is connected by an edge */
|
2018-09-24 16:32:29 +02:00
|
|
|
int numOfEdges = mesh->totedge;
|
|
|
|
|
int numOfPolys = mesh->totpoly;
|
|
|
|
|
struct MEdge *edge = mesh->medge;
|
|
|
|
|
struct MPoly *mpoly = mesh->mpoly;
|
|
|
|
|
struct MLoop *mloop = mesh->mloop;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/* count number of edges per vertex */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfEdges; i++) {
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->n_num[edge[i].v1]++;
|
|
|
|
|
ad->n_num[edge[i].v2]++;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
temp_data[edge[i].v1]++;
|
|
|
|
|
temp_data[edge[i].v2]++;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-24 17:28:50 +00:00
|
|
|
/* also add number of vertices to temp_data
|
2018-09-02 18:28:27 +10:00
|
|
|
* to locate points on "mesh edge" */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfPolys; i++) {
|
2016-05-12 12:08:03 +02:00
|
|
|
for (int j = 0; j < mpoly[i].totloop; j++) {
|
2012-01-24 18:29:01 +00:00
|
|
|
temp_data[mloop[mpoly[i].loopstart + j].v]++;
|
|
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* now check if total number of edges+faces for
|
2018-09-02 18:28:27 +10:00
|
|
|
* each vertex is even, if not -> vertex is on mesh edge */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < sData->total_points; i++) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if ((temp_data[i] % 2) || (temp_data[i] < 4)) {
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->flags[i] |= ADJ_ON_MESH_EDGE;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* reset temp data */
|
2011-07-02 18:06:39 +00:00
|
|
|
temp_data[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* order n_index array */
|
2011-06-27 07:30:58 +00:00
|
|
|
n_pos = 0;
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < sData->total_points; i++) {
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->n_index[i] = n_pos;
|
|
|
|
|
n_pos += ad->n_num[i];
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2012-03-01 12:20:18 +00:00
|
|
|
/* and now add neighbor data using that info */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfEdges; i++) {
|
2011-07-02 18:06:39 +00:00
|
|
|
/* first vertex */
|
|
|
|
|
int index = edge[i].v1;
|
2012-05-12 16:11:34 +00:00
|
|
|
n_pos = ad->n_index[index] + temp_data[index];
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->n_target[n_pos] = edge[i].v2;
|
2011-07-02 18:06:39 +00:00
|
|
|
temp_data[index]++;
|
|
|
|
|
|
|
|
|
|
/* second vertex */
|
|
|
|
|
index = edge[i].v2;
|
2012-05-12 16:11:34 +00:00
|
|
|
n_pos = ad->n_index[index] + temp_data[index];
|
2012-01-24 17:28:50 +00:00
|
|
|
ad->n_target[n_pos] = edge[i].v1;
|
2011-07-02 18:06:39 +00:00
|
|
|
temp_data[index]++;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
|
|
|
|
/* for image sequences, only allocate memory.
|
2018-09-02 18:28:27 +10:00
|
|
|
* bake initialization takes care of rest */
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(temp_data);
|
|
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintSetInitColorData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const MLoopUV *mloopuv;
|
|
|
|
|
const MLoopTri *mlooptri;
|
|
|
|
|
const MLoopCol *mloopcol;
|
|
|
|
|
struct ImagePool *pool;
|
|
|
|
|
|
|
|
|
|
const bool scene_color_manage;
|
|
|
|
|
} DynamicPaintSetInitColorData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_set_init_color_tex_to_vcol_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintSetInitColorData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const PaintSurfaceData *sData = data->surface->data;
|
|
|
|
|
PaintPoint *pPoint = (PaintPoint *)sData->type_data;
|
|
|
|
|
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv = data->mloopuv;
|
|
|
|
|
struct ImagePool *pool = data->pool;
|
|
|
|
|
Tex *tex = data->surface->init_texture;
|
|
|
|
|
|
|
|
|
|
const bool scene_color_manage = data->scene_color_manage;
|
|
|
|
|
|
|
|
|
|
float uv[3] = {0.0f};
|
|
|
|
|
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
TexResult texres = {0};
|
|
|
|
|
const unsigned int vert = mloop[mlooptri[i].tri[j]].v;
|
|
|
|
|
|
|
|
|
|
/* remap to [-1.0, 1.0] */
|
|
|
|
|
uv[0] = mloopuv[mlooptri[i].tri[j]].uv[0] * 2.0f - 1.0f;
|
|
|
|
|
uv[1] = mloopuv[mlooptri[i].tri[j]].uv[1] * 2.0f - 1.0f;
|
|
|
|
|
|
|
|
|
|
multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage, false);
|
|
|
|
|
|
|
|
|
|
if (texres.tin > pPoint[vert].color[3]) {
|
|
|
|
|
copy_v3_v3(pPoint[vert].color, &texres.tr);
|
|
|
|
|
pPoint[vert].color[3] = texres.tin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_set_init_color_tex_to_imseq_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintSetInitColorData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const PaintSurfaceData *sData = data->surface->data;
|
|
|
|
|
PaintPoint *pPoint = (PaintPoint *)sData->type_data;
|
|
|
|
|
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv = data->mloopuv;
|
|
|
|
|
Tex *tex = data->surface->init_texture;
|
|
|
|
|
ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data;
|
|
|
|
|
const int samples = (data->surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
|
|
|
|
|
|
|
|
|
const bool scene_color_manage = data->scene_color_manage;
|
|
|
|
|
|
|
|
|
|
float uv[9] = {0.0f};
|
|
|
|
|
float uv_final[3] = {0.0f};
|
|
|
|
|
|
|
|
|
|
TexResult texres = {0};
|
|
|
|
|
|
|
|
|
|
/* collect all uvs */
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
copy_v2_v2(&uv[j * 3], mloopuv[mlooptri[f_data->uv_p[i].tri_index].tri[j]].uv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interpolate final uv pos */
|
|
|
|
|
interp_v3_v3v3v3(uv_final, &uv[0], &uv[3], &uv[6], f_data->barycentricWeights[i * samples].v);
|
|
|
|
|
/* remap to [-1.0, 1.0] */
|
|
|
|
|
uv_final[0] = uv_final[0] * 2.0f - 1.0f;
|
|
|
|
|
uv_final[1] = uv_final[1] * 2.0f - 1.0f;
|
|
|
|
|
|
|
|
|
|
multitex_ext_safe(tex, uv_final, &texres, NULL, scene_color_manage, false);
|
|
|
|
|
|
|
|
|
|
/* apply color */
|
|
|
|
|
copy_v3_v3(pPoint[i].color, &texres.tr);
|
|
|
|
|
pPoint[i].color[3] = texres.tin;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_set_init_color_vcol_to_imseq_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintSetInitColorData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const PaintSurfaceData *sData = data->surface->data;
|
|
|
|
|
PaintPoint *pPoint = (PaintPoint *)sData->type_data;
|
|
|
|
|
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopCol *mloopcol = data->mloopcol;
|
|
|
|
|
ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data;
|
|
|
|
|
const int samples = (data->surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
|
|
|
|
|
|
|
|
|
const int tri_idx = f_data->uv_p[i].tri_index;
|
|
|
|
|
float colors[3][4];
|
|
|
|
|
float final_color[4];
|
|
|
|
|
|
|
|
|
|
/* collect color values */
|
|
|
|
|
for (int j = 3; j--;) {
|
|
|
|
|
rgba_uchar_to_float(colors[j], (const unsigned char *)&mloopcol[mlooptri[tri_idx].tri[j]].r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interpolate final color */
|
|
|
|
|
interp_v4_v4v4v4(final_color, UNPACK3(colors), f_data->barycentricWeights[i * samples].v);
|
|
|
|
|
|
|
|
|
|
copy_v4_v4(pPoint[i].color, final_color);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-21 22:10:43 +11:00
|
|
|
static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface *surface)
|
2011-09-05 16:04:15 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
2012-05-12 16:11:34 +00:00
|
|
|
PaintPoint *pPoint = (PaintPoint *)sData->type_data;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = surface->canvas->mesh;
|
2011-09-05 16:04:15 +00:00
|
|
|
int i;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool scene_color_manage = BKE_scene_check_color_management_enabled(scene);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
|
if (surface->type != MOD_DPAINT_SURFACE_T_PAINT)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (surface->init_color_type == MOD_DPAINT_INITIAL_NONE)
|
|
|
|
|
return;
|
2016-05-12 12:08:03 +02:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* Single color */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) {
|
2011-09-05 16:04:15 +00:00
|
|
|
/* apply color to every surface point */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < sData->total_points; i++) {
|
2015-07-27 15:52:54 +10:00
|
|
|
copy_v4_v4(pPoint[i].color, surface->init_color);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* UV mapped texture */
|
|
|
|
|
else if (surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) {
|
|
|
|
|
Tex *tex = surface->init_texture;
|
2015-07-27 15:52:54 +10:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
const MLoop *mloop = mesh->mloop;
|
|
|
|
|
const MLoopTri *mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
|
|
|
|
const int tottri = BKE_mesh_runtime_looptri_len(mesh);
|
2015-07-27 15:52:54 +10:00
|
|
|
const MLoopUV *mloopuv = NULL;
|
|
|
|
|
|
2012-01-11 08:51:06 +00:00
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!tex)
|
|
|
|
|
return;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2011-11-23 17:25:25 +00:00
|
|
|
/* get uv map */
|
2018-09-24 16:32:29 +02:00
|
|
|
CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, surface->init_layername, uvname);
|
|
|
|
|
mloopuv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname);
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!mloopuv)
|
|
|
|
|
return;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
|
/* for vertex surface loop through tfaces and find uv color
|
2018-09-02 18:28:27 +10:00
|
|
|
* that provides highest alpha */
|
2011-09-05 16:04:15 +00:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2013-01-21 08:49:42 +00:00
|
|
|
struct ImagePool *pool = BKE_image_pool_new();
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintSetInitColorData data = {
|
|
|
|
|
.surface = surface,
|
|
|
|
|
.mloop = mloop, .mlooptri = mlooptri, .mloopuv = mloopuv, .pool = pool,
|
2019-01-07 00:06:58 +11:00
|
|
|
.scene_color_manage = scene_color_manage,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (tottri > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, tottri,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_set_init_color_tex_to_vcol_cb,
|
|
|
|
|
&settings);
|
2013-01-21 08:49:42 +00:00
|
|
|
BKE_image_pool_free(pool);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintSetInitColorData data = {
|
|
|
|
|
.surface = surface,
|
|
|
|
|
.mlooptri = mlooptri, .mloopuv = mloopuv,
|
2019-01-07 00:06:58 +11:00
|
|
|
.scene_color_manage = scene_color_manage,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_set_init_color_tex_to_imseq_cb,
|
|
|
|
|
&settings);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* vertex color layer */
|
|
|
|
|
else if (surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR) {
|
|
|
|
|
|
|
|
|
|
/* for vertex surface, just copy colors from mcol */
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2018-09-24 16:32:29 +02:00
|
|
|
const MLoop *mloop = mesh->mloop;
|
|
|
|
|
const int totloop = mesh->totloop;
|
|
|
|
|
const MLoopCol *col = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPCOL, surface->init_layername);
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!col)
|
|
|
|
|
return;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2015-07-27 15:52:54 +10:00
|
|
|
for (i = 0; i < totloop; i++) {
|
|
|
|
|
rgba_uchar_to_float(pPoint[mloop[i].v].color, (const unsigned char *)&col[mloop[i].v].r);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
2018-09-24 16:32:29 +02:00
|
|
|
const MLoopTri *mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
|
|
|
|
MLoopCol *col = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPCOL, surface->init_layername);
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!col)
|
|
|
|
|
return;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintSetInitColorData data = {
|
|
|
|
|
.surface = surface,
|
|
|
|
|
.mlooptri = mlooptri, .mloopcol = col,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_set_init_color_vcol_to_imseq_cb,
|
|
|
|
|
&settings);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/* clears surface data back to zero */
|
2015-03-21 22:10:43 +11:00
|
|
|
void dynamicPaint_clearSurface(const Scene *scene, DynamicPaintSurface *surface)
|
2011-08-21 19:03:47 +00:00
|
|
|
{
|
2011-07-02 18:06:39 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
if (sData && sData->type_data) {
|
|
|
|
|
unsigned int data_size;
|
|
|
|
|
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT)
|
|
|
|
|
data_size = sizeof(PaintPoint);
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE)
|
|
|
|
|
data_size = sizeof(PaintWavePoint);
|
|
|
|
|
else
|
|
|
|
|
data_size = sizeof(float);
|
|
|
|
|
|
|
|
|
|
memset(sData->type_data, 0, data_size * sData->total_points);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* set initial color */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT)
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
dynamicPaint_setInitialColor(scene, surface);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
if (sData->bData)
|
|
|
|
|
sData->bData->clear = 1;
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/* completely (re)initializes surface (only for point cache types)*/
|
2015-03-21 22:10:43 +11:00
|
|
|
bool dynamicPaint_resetSurface(const Scene *scene, DynamicPaintSurface *surface)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
|
|
|
|
int numOfPoints = dynamicPaint_surfaceNumOfPoints(surface);
|
2012-01-24 17:28:50 +00:00
|
|
|
/* free existing data */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface->data)
|
|
|
|
|
dynamicPaint_freeSurfaceData(surface);
|
2012-01-24 17:28:50 +00:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* don't reallocate for image sequence types. they get handled only on bake */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
|
|
|
|
|
return true;
|
|
|
|
|
if (numOfPoints < 1)
|
|
|
|
|
return false;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* allocate memory */
|
|
|
|
|
surface->data = MEM_callocN(sizeof(PaintSurfaceData), "PaintSurfaceData");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!surface->data)
|
|
|
|
|
return false;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* allocate data depending on surface type and format */
|
|
|
|
|
surface->data->total_points = numOfPoints;
|
|
|
|
|
dynamicPaint_allocateSurfaceType(surface);
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_initAdjacencyData(surface, false);
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* set initial color */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT)
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
dynamicPaint_setInitialColor(scene, surface);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make sure allocated surface size matches current requirements */
|
2015-03-21 22:10:43 +11:00
|
|
|
static bool dynamicPaint_checkSurfaceData(const Scene *scene, DynamicPaintSurface *surface)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
|
|
|
|
if (!surface->data || ((dynamicPaint_surfaceNumOfPoints(surface) != surface->data->total_points))) {
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
return dynamicPaint_resetSurface(scene, surface);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************** Modifier processing ******************************/
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintModifierApplyData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
Object *ob;
|
|
|
|
|
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const MPoly *mpoly;
|
|
|
|
|
|
|
|
|
|
float (*fcolor)[4];
|
|
|
|
|
MLoopCol *mloopcol;
|
|
|
|
|
MLoopCol *mloopcol_wet;
|
|
|
|
|
MLoopCol *mloopcol_preview;
|
|
|
|
|
} DynamicPaintModifierApplyData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_apply_surface_displace_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintModifierApplyData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
MVert *mvert = data->mvert;
|
|
|
|
|
|
|
|
|
|
float normal[3];
|
|
|
|
|
const float *value = (float *)surface->data->type_data;
|
|
|
|
|
const float val = value[i] * surface->disp_factor;
|
|
|
|
|
|
|
|
|
|
normal_short_to_float_v3(normal, mvert[i].no);
|
|
|
|
|
|
|
|
|
|
/* same as 'mvert[i].co[0] -= normal[0] * val' etc. */
|
|
|
|
|
madd_v3_v3fl(mvert[i].co, normal, -val);
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-08-05 09:31:35 +00:00
|
|
|
/* apply displacing vertex surface to the derived mesh */
|
2018-09-24 16:32:29 +02:00
|
|
|
static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Mesh *result)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2011-08-05 09:31:35 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!sData || surface->format != MOD_DPAINT_SURFACE_F_VERTEX)
|
|
|
|
|
return;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-08-05 09:31:35 +00:00
|
|
|
/* displace paint */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
|
2018-09-24 16:32:29 +02:00
|
|
|
MVert *mvert = result->mvert;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2019-01-07 00:06:58 +11:00
|
|
|
DynamicPaintModifierApplyData data = { .surface = surface, .mvert = mvert, };
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 10000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_apply_surface_displace_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_apply_surface_vpaint_blend_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintModifierApplyData *data = userdata;
|
|
|
|
|
|
|
|
|
|
PaintPoint *pPoint = (PaintPoint *)data->surface->data->type_data;
|
|
|
|
|
float (*fcolor)[4] = data->fcolor;
|
|
|
|
|
|
|
|
|
|
/* blend dry and wet layer */
|
|
|
|
|
blendColors(pPoint[i].color, pPoint[i].color[3], pPoint[i].e_color, pPoint[i].e_color[3], fcolor[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_apply_surface_vpaint_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int p_index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintModifierApplyData *data = userdata;
|
|
|
|
|
Object *ob = data->ob;
|
|
|
|
|
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
const MPoly *mpoly = data->mpoly;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
PaintPoint *pPoint = (PaintPoint *)surface->data->type_data;
|
|
|
|
|
float (*fcolor)[4] = data->fcolor;
|
|
|
|
|
|
|
|
|
|
MLoopCol *mloopcol = data->mloopcol;
|
|
|
|
|
MLoopCol *mloopcol_wet = data->mloopcol_wet;
|
|
|
|
|
MLoopCol *mloopcol_preview = data->mloopcol_preview;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const Material *material = mloopcol_preview ?
|
|
|
|
|
give_current_material(ob, mpoly[p_index].mat_nr + 1) : NULL;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < mpoly[p_index].totloop; j++) {
|
|
|
|
|
const int l_index = mpoly[p_index].loopstart + j;
|
|
|
|
|
const int v_index = mloop[l_index].v;
|
|
|
|
|
|
|
|
|
|
/* save layer data to output layer */
|
|
|
|
|
/* apply color */
|
|
|
|
|
if (mloopcol) {
|
|
|
|
|
rgba_float_to_uchar((unsigned char *)&mloopcol[l_index].r, fcolor[v_index]);
|
|
|
|
|
}
|
|
|
|
|
/* apply wetness */
|
|
|
|
|
if (mloopcol_wet) {
|
2018-05-07 17:31:28 +02:00
|
|
|
const char c = unit_float_to_uchar_clamp(pPoint[v_index].wetness);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
mloopcol_wet[l_index].r = c;
|
|
|
|
|
mloopcol_wet[l_index].g = c;
|
|
|
|
|
mloopcol_wet[l_index].b = c;
|
|
|
|
|
mloopcol_wet[l_index].a = 255;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* viewport preview */
|
|
|
|
|
if (mloopcol_preview) {
|
|
|
|
|
if (surface->preview_id == MOD_DPAINT_SURFACE_PREV_PAINT) {
|
|
|
|
|
float c[3];
|
|
|
|
|
|
|
|
|
|
/* Apply material color as base vertex color for preview */
|
|
|
|
|
mloopcol_preview[l_index].a = 255;
|
|
|
|
|
if (material) {
|
|
|
|
|
c[0] = material->r;
|
|
|
|
|
c[1] = material->g;
|
|
|
|
|
c[2] = material->b;
|
|
|
|
|
}
|
|
|
|
|
else { /* default gray */
|
|
|
|
|
c[0] = 0.65f;
|
|
|
|
|
c[1] = 0.65f;
|
|
|
|
|
c[2] = 0.65f;
|
|
|
|
|
}
|
|
|
|
|
/* mix surface color */
|
|
|
|
|
interp_v3_v3v3(c, c, fcolor[v_index], fcolor[v_index][3]);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
rgb_float_to_uchar((unsigned char *)&mloopcol_preview[l_index].r, c);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2018-05-07 17:31:28 +02:00
|
|
|
const char c = unit_float_to_uchar_clamp(pPoint[v_index].wetness);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
mloopcol_preview[l_index].r = c;
|
|
|
|
|
mloopcol_preview[l_index].g = c;
|
|
|
|
|
mloopcol_preview[l_index].b = c;
|
|
|
|
|
mloopcol_preview[l_index].a = 255;
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_apply_surface_wave_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintModifierApplyData *data = userdata;
|
|
|
|
|
|
|
|
|
|
PaintWavePoint *wPoint = (PaintWavePoint *)data->surface->data->type_data;
|
|
|
|
|
MVert *mvert = data->mvert;
|
|
|
|
|
float normal[3];
|
|
|
|
|
|
|
|
|
|
normal_short_to_float_v3(normal, mvert[i].no);
|
|
|
|
|
madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Apply canvas data to the object derived mesh
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2018-09-24 16:32:29 +02:00
|
|
|
static Mesh *dynamicPaint_Modifier_apply(
|
|
|
|
|
DynamicPaintModifierData *pmd, Object *ob, Mesh *mesh)
|
2012-05-17 23:21:11 +00:00
|
|
|
{
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *result = BKE_mesh_copy_for_eval(mesh, false);
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-04-23 16:29:13 +00:00
|
|
|
DynamicPaintSurface *surface;
|
2013-07-06 01:42:45 +00:00
|
|
|
bool update_normals = false;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* loop through surfaces */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
|
2011-08-03 18:31:48 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-04-23 16:29:13 +00:00
|
|
|
if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && sData) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!(surface->flags & MOD_DPAINT_ACTIVE))
|
|
|
|
|
continue;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* process vertex surface previews */
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
|
|
|
|
|
|
|
|
|
/* vertex color paint */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
2018-09-24 16:32:29 +02:00
|
|
|
MLoop *mloop = result->mloop;
|
|
|
|
|
const int totloop = result->totloop;
|
|
|
|
|
MPoly *mpoly = result->mpoly;
|
|
|
|
|
const int totpoly = result->totpoly;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* paint is stored on dry and wet layers, so mix final color first */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float (*fcolor)[4] = MEM_callocN(sizeof(*fcolor) * sData->total_points, "Temp paint color");
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2019-01-07 00:06:58 +11:00
|
|
|
DynamicPaintModifierApplyData data = { .surface = surface, .fcolor = fcolor, };
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_apply_surface_vpaint_blend_cb,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
|
/* paint layer */
|
2018-09-24 16:32:29 +02:00
|
|
|
MLoopCol *mloopcol = CustomData_get_layer_named(&result->ldata, CD_MLOOPCOL, surface->output_name);
|
2011-11-20 10:52:25 +00:00
|
|
|
/* if output layer is lost from a constructive modifier, re-add it */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (!mloopcol && dynamicPaint_outputLayerExists(surface, ob, 0)) {
|
|
|
|
|
mloopcol = CustomData_add_layer_named(
|
2018-09-24 16:32:29 +02:00
|
|
|
&result->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wet layer */
|
2018-09-24 16:32:29 +02:00
|
|
|
MLoopCol *mloopcol_wet = CustomData_get_layer_named(&result->ldata, CD_MLOOPCOL, surface->output_name2);
|
2011-11-20 10:52:25 +00:00
|
|
|
/* if output layer is lost from a constructive modifier, re-add it */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (!mloopcol_wet && dynamicPaint_outputLayerExists(surface, ob, 1)) {
|
|
|
|
|
mloopcol_wet = CustomData_add_layer_named(
|
2018-09-24 16:32:29 +02:00
|
|
|
&result->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name2);
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* Save preview results to weight layer to be able to share same drawing methods */
|
|
|
|
|
MLoopCol *mloopcol_preview = NULL;
|
|
|
|
|
if (surface->flags & MOD_DPAINT_PREVIEW) {
|
2018-09-24 16:32:29 +02:00
|
|
|
mloopcol_preview = CustomData_get_layer(&result->ldata, CD_PREVIEW_MLOOPCOL);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (!mloopcol_preview) {
|
|
|
|
|
mloopcol_preview = CustomData_add_layer(
|
2018-09-24 16:32:29 +02:00
|
|
|
&result->ldata, CD_PREVIEW_MLOOPCOL, CD_CALLOC, NULL, totloop);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 22:06:57 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
data.ob = ob;
|
|
|
|
|
data.mloop = mloop;
|
|
|
|
|
data.mpoly = mpoly;
|
|
|
|
|
data.mloopcol = mloopcol;
|
|
|
|
|
data.mloopcol_wet = mloopcol_wet;
|
|
|
|
|
data.mloopcol_preview = mloopcol_preview;
|
|
|
|
|
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (totpoly > 1000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, totpoly,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_apply_surface_vpaint_cb,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
MEM_freeN(fcolor);
|
|
|
|
|
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 22:06:57 +00:00
|
|
|
/* Mark tessellated CD layers as dirty. */
|
2018-09-24 16:32:29 +02:00
|
|
|
//result->dirty |= DM_DIRTY_TESS_CDLAYERS;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
/* vertex group paint */
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
2011-06-18 18:41:20 +00:00
|
|
|
int defgrp_index = defgroup_name_index(ob, surface->output_name);
|
2018-09-24 16:32:29 +02:00
|
|
|
MDeformVert *dvert = CustomData_get_layer(&result->vdata, CD_MDEFORMVERT);
|
2012-05-12 16:11:34 +00:00
|
|
|
float *weight = (float *)sData->type_data;
|
2011-11-30 20:41:13 +00:00
|
|
|
|
2011-06-18 18:41:20 +00:00
|
|
|
/* viewport preview */
|
2012-01-23 16:32:11 +00:00
|
|
|
if (surface->flags & MOD_DPAINT_PREVIEW) {
|
2011-11-30 20:41:13 +00:00
|
|
|
/* Save preview results to weight layer to be
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 22:06:57 +00:00
|
|
|
* able to share same drawing methods.
|
|
|
|
|
* Note this func also sets DM_DIRTY_TESS_CDLAYERS flag! */
|
2018-09-24 16:32:29 +02:00
|
|
|
//TODO port this function
|
|
|
|
|
//DM_update_weight_mcol(ob, result, 0, weight, 0, NULL);
|
2011-06-18 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* apply weights into a vertex group, if doesn't exists add a new layer */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (defgrp_index != -1 && !dvert && (surface->output_name[0] != '\0')) {
|
2018-09-24 16:32:29 +02:00
|
|
|
dvert = CustomData_add_layer(&result->vdata, CD_MDEFORMVERT, CD_CALLOC,
|
2017-05-29 12:06:40 +02:00
|
|
|
NULL, sData->total_points);
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2012-10-22 17:19:05 +00:00
|
|
|
if (defgrp_index != -1 && dvert) {
|
2011-06-18 18:41:20 +00:00
|
|
|
int i;
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < sData->total_points; i++) {
|
|
|
|
|
MDeformVert *dv = &dvert[i];
|
2011-10-28 14:46:09 +00:00
|
|
|
MDeformWeight *def_weight = defvert_find_index(dv, defgrp_index);
|
2011-06-18 18:41:20 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* skip if weight value is 0 and no existing weight is found */
|
2011-11-30 10:04:14 +00:00
|
|
|
if ((def_weight != NULL) || (weight[i] != 0.0f)) {
|
|
|
|
|
/* if not found, add a weight for it */
|
|
|
|
|
if (def_weight == NULL) {
|
2012-05-12 16:11:34 +00:00
|
|
|
def_weight = defvert_verify_index(dv, defgrp_index);
|
2011-06-18 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-30 10:04:14 +00:00
|
|
|
/* set weight value */
|
|
|
|
|
def_weight->weight = weight[i];
|
|
|
|
|
}
|
2011-06-18 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
/* wave simulation */
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
|
2018-09-24 16:32:29 +02:00
|
|
|
MVert *mvert = result->mvert;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2019-01-07 00:06:58 +11:00
|
|
|
DynamicPaintModifierApplyData data = { .surface = surface, .mvert = mvert, };
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_apply_surface_wave_cb,
|
|
|
|
|
&settings);
|
2013-07-06 01:42:45 +00:00
|
|
|
update_normals = true;
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
2011-08-05 09:31:35 +00:00
|
|
|
|
|
|
|
|
/* displace */
|
2012-01-16 17:18:07 +00:00
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
|
|
|
|
|
dynamicPaint_applySurfaceDisplace(surface, result);
|
2013-07-06 01:42:45 +00:00
|
|
|
update_normals = true;
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-16 17:18:07 +00:00
|
|
|
|
2013-07-06 01:42:45 +00:00
|
|
|
if (update_normals) {
|
2018-09-24 16:32:29 +02:00
|
|
|
//result->dirty |= DM_DIRTY_NORMALS;
|
2013-07-06 01:42:45 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2018-09-24 16:32:29 +02:00
|
|
|
/* make a copy of mesh to use as brush data */
|
2011-07-08 11:03:37 +00:00
|
|
|
if (pmd->brush) {
|
2018-09-24 16:32:29 +02:00
|
|
|
if (pmd->brush->mesh) {
|
|
|
|
|
BKE_id_free(NULL, pmd->brush->mesh);
|
|
|
|
|
}
|
|
|
|
|
pmd->brush->mesh = BKE_mesh_copy_for_eval(result, false);
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* update cache frame range */
|
|
|
|
|
void dynamicPaint_cacheUpdateFrames(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
if (surface->pointcache) {
|
|
|
|
|
surface->pointcache->startframe = surface->start_frame;
|
|
|
|
|
surface->pointcache->endframe = surface->end_frame;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
static void canvas_copyMesh(DynamicPaintCanvasSettings *canvas, Mesh *mesh)
|
2011-08-05 09:31:35 +00:00
|
|
|
{
|
2018-09-24 16:32:29 +02:00
|
|
|
if (canvas->mesh) {
|
|
|
|
|
BKE_id_free(NULL, canvas->mesh);
|
2012-09-15 01:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
canvas->mesh = BKE_mesh_copy_for_eval(mesh, false);
|
2011-08-05 09:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Updates derived mesh copy and processes dynamic paint step / caches.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2017-08-16 12:45:11 +10:00
|
|
|
static void dynamicPaint_frameUpdate(
|
2018-04-06 12:07:27 +02:00
|
|
|
DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene,
|
2018-09-24 16:32:29 +02:00
|
|
|
Object *ob, Mesh *mesh)
|
2011-08-05 09:31:35 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pmd->canvas) {
|
2011-08-05 09:31:35 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas = pmd->canvas;
|
|
|
|
|
DynamicPaintSurface *surface = canvas->surfaces.first;
|
|
|
|
|
|
|
|
|
|
/* update derived mesh copy */
|
2018-09-24 16:32:29 +02:00
|
|
|
canvas_copyMesh(canvas, mesh);
|
2011-08-05 09:31:35 +00:00
|
|
|
|
|
|
|
|
/* in case image sequence baking, stop here */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (canvas->flags & MOD_DPAINT_BAKING)
|
|
|
|
|
return;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
|
|
|
|
/* loop through surfaces */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2011-08-05 09:31:35 +00:00
|
|
|
int current_frame = (int)scene->r.cfra;
|
2013-07-12 16:33:37 +00:00
|
|
|
bool no_surface_data;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
2011-08-21 19:03:47 +00:00
|
|
|
/* free bake data if not required anymore */
|
|
|
|
|
surface_freeUnusedData(surface);
|
|
|
|
|
|
2011-08-05 09:31:35 +00:00
|
|
|
/* image sequences are handled by bake operator */
|
2016-05-12 12:08:03 +02:00
|
|
|
if ((surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) || !(surface->flags & MOD_DPAINT_ACTIVE))
|
|
|
|
|
continue;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
|
|
|
|
/* make sure surface is valid */
|
2013-07-12 16:33:37 +00:00
|
|
|
no_surface_data = surface->data == NULL;
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!dynamicPaint_checkSurfaceData(scene, surface))
|
|
|
|
|
continue;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
|
|
|
|
/* limit frame range */
|
|
|
|
|
CLAMP(current_frame, surface->start_frame, surface->end_frame);
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (no_surface_data || current_frame != surface->current_frame ||
|
|
|
|
|
(int)scene->r.cfra == surface->start_frame)
|
|
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache = surface->pointcache;
|
|
|
|
|
PTCacheID pid;
|
2011-08-05 09:31:35 +00:00
|
|
|
surface->current_frame = current_frame;
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* read point cache */
|
|
|
|
|
BKE_ptcache_id_from_dynamicpaint(&pid, ob, surface);
|
|
|
|
|
pid.cache->startframe = surface->start_frame;
|
|
|
|
|
pid.cache->endframe = surface->end_frame;
|
|
|
|
|
BKE_ptcache_id_time(&pid, scene, (float)scene->r.cfra, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* reset non-baked cache at first frame */
|
|
|
|
|
if ((int)scene->r.cfra == surface->start_frame && !(cache->flag & PTCACHE_BAKED)) {
|
|
|
|
|
cache->flag |= PTCACHE_REDO_NEEDED;
|
|
|
|
|
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
|
|
|
|
|
cache->flag &= ~PTCACHE_REDO_NEEDED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* try to read from cache */
|
|
|
|
|
bool can_simulate = ((int)scene->r.cfra == current_frame) && !(cache->flag & PTCACHE_BAKED);
|
|
|
|
|
|
|
|
|
|
if (BKE_ptcache_read(&pid, (float)scene->r.cfra, can_simulate)) {
|
|
|
|
|
BKE_ptcache_validate(cache, (int)scene->r.cfra);
|
|
|
|
|
}
|
|
|
|
|
/* if read failed and we're on surface range do recalculate */
|
|
|
|
|
else if (can_simulate) {
|
2011-08-05 09:31:35 +00:00
|
|
|
/* calculate surface frame */
|
|
|
|
|
canvas->flags |= MOD_DPAINT_BAKING;
|
2018-04-06 12:07:27 +02:00
|
|
|
dynamicPaint_calculateFrame(surface, depsgraph, scene, ob, current_frame);
|
2011-08-05 09:31:35 +00:00
|
|
|
canvas->flags &= ~MOD_DPAINT_BAKING;
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* restore canvas mesh if required */
|
2011-08-05 09:31:35 +00:00
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE &&
|
2012-04-28 06:31:57 +00:00
|
|
|
surface->flags & MOD_DPAINT_DISP_INCREMENTAL && surface->next)
|
|
|
|
|
{
|
2018-09-24 16:32:29 +02:00
|
|
|
canvas_copyMesh(canvas, mesh);
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
BKE_ptcache_validate(cache, surface->current_frame);
|
|
|
|
|
BKE_ptcache_write(&pid, surface->current_frame);
|
2011-08-05 09:31:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Modifier call. Processes dynamic paint modifier step. */
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *dynamicPaint_Modifier_do(
|
2018-04-06 12:07:27 +02:00
|
|
|
DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene,
|
2018-09-24 16:32:29 +02:00
|
|
|
Object *ob, Mesh *mesh)
|
2012-05-17 23:21:11 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (pmd->canvas) {
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *ret;
|
2012-01-24 18:29:01 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Update canvas data for a new frame */
|
2018-09-24 16:32:29 +02:00
|
|
|
dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, mesh);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* Return output mesh */
|
2018-09-24 16:32:29 +02:00
|
|
|
ret = dynamicPaint_Modifier_apply(pmd, ob, mesh);
|
2012-01-24 18:29:01 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Update canvas data for a new frame */
|
2018-09-24 16:32:29 +02:00
|
|
|
dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, mesh);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* Return output mesh */
|
2018-09-24 16:32:29 +02:00
|
|
|
return dynamicPaint_Modifier_apply(pmd, ob, mesh);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/***************************** Image Sequence / UV Image Surface Calls ******************************/
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Create a surface for uv image sequence format
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
#define JITTER_SAMPLES { \
|
|
|
|
|
0.0f, 0.0f, \
|
|
|
|
|
-0.2f, -0.4f, \
|
|
|
|
|
0.2f, 0.4f, \
|
|
|
|
|
0.4f, -0.2f, \
|
|
|
|
|
-0.4f, 0.3f, \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct DynamicPaintCreateUVSurfaceData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
|
|
|
|
|
PaintUVPoint *tempPoints;
|
|
|
|
|
Vec3f *tempWeights;
|
|
|
|
|
|
|
|
|
|
const MLoopTri *mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv;
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const int tottri;
|
|
|
|
|
|
|
|
|
|
const Bounds2D *faceBB;
|
|
|
|
|
uint32_t *active_points;
|
|
|
|
|
} DynamicPaintCreateUVSurfaceData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_create_uv_surface_direct_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int ty,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintCreateUVSurfaceData *data = userdata;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
PaintUVPoint *tempPoints = data->tempPoints;
|
|
|
|
|
Vec3f *tempWeights = data->tempWeights;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv = data->mloopuv;
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
const int tottri = data->tottri;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const Bounds2D *faceBB = data->faceBB;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float jitter5sample[10] = JITTER_SAMPLES;
|
|
|
|
|
const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
|
|
|
|
const int w = surface->image_resolution;
|
|
|
|
|
const int h = w;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int tx = 0; tx < w; tx++) {
|
|
|
|
|
const int index = tx + w * ty;
|
|
|
|
|
PaintUVPoint *tPoint = &tempPoints[index];
|
|
|
|
|
float point[5][2];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Init per pixel settings */
|
|
|
|
|
tPoint->tri_index = -1;
|
|
|
|
|
tPoint->neighbour_pixel = -1;
|
|
|
|
|
tPoint->pixel_index = index;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Actual pixel center, used when collision is found */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
point[0][0] = ((float)tx + 0.5f) / w;
|
|
|
|
|
point[0][1] = ((float)ty + 0.5f) / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/*
|
|
|
|
|
* A pixel middle sample isn't enough to find very narrow polygons
|
|
|
|
|
* So using 4 samples of each corner too
|
|
|
|
|
*/
|
|
|
|
|
point[1][0] = ((float)tx) / w;
|
|
|
|
|
point[1][1] = ((float)ty) / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
point[2][0] = ((float)tx + 1) / w;
|
|
|
|
|
point[2][1] = ((float)ty) / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
point[3][0] = ((float)tx) / w;
|
|
|
|
|
point[3][1] = ((float)ty + 1) / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
point[4][0] = ((float)tx + 1) / w;
|
|
|
|
|
point[4][1] = ((float)ty + 1) / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Loop through samples, starting from middle point */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int sample = 0; sample < 5; sample++) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Loop through every face in the mesh */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* XXX TODO This is *horrible* with big meshes, should use a 2D BVHTree over UV tris here! */
|
|
|
|
|
for (int i = 0; i < tottri; i++) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Check uv bb */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if ((faceBB[i].min[0] > point[sample][0]) ||
|
|
|
|
|
(faceBB[i].min[1] > point[sample][1]) ||
|
|
|
|
|
(faceBB[i].max[0] < point[sample][0]) ||
|
|
|
|
|
(faceBB[i].max[1] < point[sample][1]))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv;
|
|
|
|
|
const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv;
|
|
|
|
|
const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* If point is inside the face */
|
|
|
|
|
if (isect_point_tri_v2(point[sample], uv1, uv2, uv3) != 0) {
|
|
|
|
|
float uv[2];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Add b-weights per anti-aliasing sample */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int j = 0; j < aa_samples; j++) {
|
|
|
|
|
uv[0] = point[0][0] + jitter5sample[j * 2] / w;
|
|
|
|
|
uv[1] = point[0][1] + jitter5sample[j * 2 + 1] / h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
barycentric_weights_v2(uv1, uv2, uv3, uv, tempWeights[index * aa_samples + j].v);
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Set surface point face values */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
tPoint->tri_index = i;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* save vertex indexes */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
tPoint->v1 = mloop[mlooptri[i].tri[0]].v;
|
|
|
|
|
tPoint->v2 = mloop[mlooptri[i].tri[1]].v;
|
|
|
|
|
tPoint->v3 = mloop[mlooptri[i].tri[2]].v;
|
|
|
|
|
|
|
|
|
|
sample = 5; /* make sure we exit sample loop as well */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_create_uv_surface_neighbor_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int ty,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintCreateUVSurfaceData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
PaintUVPoint *tempPoints = data->tempPoints;
|
|
|
|
|
Vec3f *tempWeights = data->tempWeights;
|
|
|
|
|
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv = data->mloopuv;
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
|
|
|
|
|
uint32_t *active_points = data->active_points;
|
|
|
|
|
|
|
|
|
|
const float jitter5sample[10] = JITTER_SAMPLES;
|
|
|
|
|
const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
|
|
|
|
const int w = surface->image_resolution;
|
|
|
|
|
const int h = w;
|
|
|
|
|
|
|
|
|
|
for (int tx = 0; tx < w; tx++) {
|
|
|
|
|
const int index = tx + w * ty;
|
|
|
|
|
PaintUVPoint *tPoint = &tempPoints[index];
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If point isn't on canvas mesh */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (tPoint->tri_index == -1) {
|
|
|
|
|
float point[2];
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* get loop area */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int u_min = (tx > 0) ? -1 : 0;
|
|
|
|
|
const int u_max = (tx < (w - 1)) ? 1 : 0;
|
|
|
|
|
const int v_min = (ty > 0) ? -1 : 0;
|
|
|
|
|
const int v_max = (ty < (h - 1)) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
point[0] = ((float)tx + 0.5f) / w;
|
|
|
|
|
point[1] = ((float)ty + 0.5f) / h;
|
|
|
|
|
|
2016-09-27 11:13:04 +03:00
|
|
|
/* search through defined area for neighbor, checking grid directions first */
|
|
|
|
|
for (int ni = 0; ni < 8; ni++) {
|
|
|
|
|
int u = neighStraightX[ni];
|
|
|
|
|
int v = neighStraightY[ni];
|
|
|
|
|
|
|
|
|
|
if (u >= u_min && u <= u_max && v >= v_min && v <= v_max) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* if not this pixel itself */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (u != 0 || v != 0) {
|
|
|
|
|
const int ind = (tx + u) + w * (ty + v);
|
|
|
|
|
|
|
|
|
|
/* if neighbor has index */
|
|
|
|
|
if (tempPoints[ind].neighbour_pixel == -1 && tempPoints[ind].tri_index != -1) {
|
|
|
|
|
float uv[2];
|
|
|
|
|
const int i = tempPoints[ind].tri_index;
|
|
|
|
|
const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv;
|
|
|
|
|
const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv;
|
|
|
|
|
const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv;
|
|
|
|
|
|
|
|
|
|
/* tri index */
|
|
|
|
|
/* There is a low possibility of actually having a neighbor point which tri is
|
|
|
|
|
* already set from another neighbor in a separate thread here.
|
2016-07-08 00:48:03 +10:00
|
|
|
* Checking for both tri_index and neighbour_pixel above reduces that probability
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* but it remains possible.
|
|
|
|
|
* That atomic op (and its memory fence) ensures tPoint->neighbour_pixel is set
|
|
|
|
|
* to non--1 *before* its tri_index is set (i.e. that it cannot be used a neighbour).
|
|
|
|
|
*/
|
|
|
|
|
tPoint->neighbour_pixel = ind - 1;
|
2016-11-15 12:16:26 +01:00
|
|
|
atomic_add_and_fetch_uint32(&tPoint->neighbour_pixel, 1);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
tPoint->tri_index = i;
|
|
|
|
|
|
|
|
|
|
/* Now calculate pixel data for this pixel as it was on polygon surface */
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Add b-weights per anti-aliasing sample */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int j = 0; j < aa_samples; j++) {
|
|
|
|
|
uv[0] = point[0] + jitter5sample[j * 2] / w;
|
|
|
|
|
uv[1] = point[1] + jitter5sample[j * 2 + 1] / h;
|
|
|
|
|
barycentric_weights_v2(uv1, uv2, uv3, uv, tempWeights[index * aa_samples + j].v);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* save vertex indexes */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
tPoint->v1 = mloop[mlooptri[i].tri[0]].v;
|
|
|
|
|
tPoint->v2 = mloop[mlooptri[i].tri[1]].v;
|
|
|
|
|
tPoint->v3 = mloop[mlooptri[i].tri[2]].v;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Increase the final number of active surface points if relevant. */
|
|
|
|
|
if (tPoint->tri_index != -1)
|
2016-11-15 12:16:26 +01:00
|
|
|
atomic_add_and_fetch_uint32(active_points, 1);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef JITTER_SAMPLES
|
|
|
|
|
|
2017-01-03 19:13:02 +03:00
|
|
|
static float dist_squared_to_looptri_uv_edges(const MLoopTri *mlooptri, const MLoopUV *mloopuv, int tri_index, const float point[2])
|
|
|
|
|
{
|
|
|
|
|
float min_distance = FLT_MAX;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
const float dist_squared = dist_squared_to_line_segment_v2(
|
|
|
|
|
point,
|
|
|
|
|
mloopuv[mlooptri[tri_index].tri[(i + 0)]].uv,
|
|
|
|
|
mloopuv[mlooptri[tri_index].tri[(i + 1) % 3]].uv
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (dist_squared < min_distance)
|
|
|
|
|
min_distance = dist_squared;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return min_distance;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
typedef struct DynamicPaintFindIslandBorderData {
|
|
|
|
|
const MeshElemMap *vert_to_looptri_map;
|
|
|
|
|
int w, h, px, py;
|
|
|
|
|
|
|
|
|
|
int best_index;
|
|
|
|
|
float best_weight;
|
|
|
|
|
} DynamicPaintFindIslandBorderData;
|
|
|
|
|
|
|
|
|
|
static void dynamic_paint_find_island_border(
|
|
|
|
|
const DynamicPaintCreateUVSurfaceData *data, DynamicPaintFindIslandBorderData *bdata,
|
|
|
|
|
int tri_index, const float pixel[2], int in_edge, int depth);
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Tries to find the neighboring pixel in given (uv space) direction.
|
|
|
|
|
* Result is used by effect system to move paint on the surface.
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* px, py : origin pixel x and y
|
|
|
|
|
* n_index : lookup direction index (use neighX, neighY to get final index)
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
static int dynamic_paint_find_neighbour_pixel(
|
|
|
|
|
const DynamicPaintCreateUVSurfaceData *data, const MeshElemMap *vert_to_looptri_map,
|
|
|
|
|
const int w, const int h, const int px, const int py, const int n_index)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-03-01 12:20:18 +00:00
|
|
|
/* Note: Current method only uses polygon edges to detect neighboring pixels.
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* -> It doesn't always lead to the optimum pixel but is accurate enough
|
|
|
|
|
* and faster/simpler than including possible face tip point links)
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/* shift position by given n_index */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int x = px + neighX[n_index];
|
|
|
|
|
const int y = py + neighY[n_index];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (x < 0 || x >= w || y < 0 || y >= h)
|
|
|
|
|
return OUT_OF_TEXTURE;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const PaintUVPoint *tempPoints = data->tempPoints;
|
|
|
|
|
const PaintUVPoint *tPoint = &tempPoints[x + w * y]; /* UV neighbor */
|
|
|
|
|
const PaintUVPoint *cPoint = &tempPoints[px + w * py]; /* Origin point */
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Check if shifted point is on same face -> it's a correct neighbor (and if it isn't marked as an "edge pixel") */
|
2015-07-27 15:52:54 +10:00
|
|
|
if ((tPoint->tri_index == cPoint->tri_index) && (tPoint->neighbour_pixel == -1))
|
2012-05-12 16:11:34 +00:00
|
|
|
return (x + w * y);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Even if shifted point is on another face
|
|
|
|
|
* -> use this point.
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* !! Replace with "is uv faces linked" check !!
|
|
|
|
|
* This should work fine as long as uv island margin is > 1 pixel.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2015-07-27 15:52:54 +10:00
|
|
|
if ((tPoint->tri_index != -1) && (tPoint->neighbour_pixel == -1)) {
|
2012-05-12 16:11:34 +00:00
|
|
|
return (x + w * y);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* If we get here, the actual neighboring pixel is located on a non-linked uv face,
|
|
|
|
|
* and we have to find its "real" position.
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* Simple neighboring face finding algorithm:
|
|
|
|
|
* - find closest uv edge to shifted pixel and get the another face that shares that edge
|
|
|
|
|
* - find corresponding position of that new face edge in uv space
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
* TODO: Implement something more accurate / optimized?
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2017-01-03 19:11:59 +03:00
|
|
|
DynamicPaintFindIslandBorderData bdata = {
|
|
|
|
|
.vert_to_looptri_map = vert_to_looptri_map,
|
|
|
|
|
.w = w, .h = h, .px = px, .py = py,
|
2019-01-07 00:06:58 +11:00
|
|
|
.best_index = NOT_FOUND, .best_weight = 1.0f,
|
2017-01-03 19:11:59 +03:00
|
|
|
};
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float pixel[2];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
pixel[0] = ((float)(px + neighX[n_index]) + 0.5f) / (float)w;
|
|
|
|
|
pixel[1] = ((float)(py + neighY[n_index]) + 0.5f) / (float)h;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Do a small recursive search for the best island edge. */
|
|
|
|
|
dynamic_paint_find_island_border(data, &bdata, cPoint->tri_index, pixel, -1, 5);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
return bdata.best_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
static void dynamic_paint_find_island_border(
|
|
|
|
|
const DynamicPaintCreateUVSurfaceData *data, DynamicPaintFindIslandBorderData *bdata,
|
|
|
|
|
int tri_index, const float pixel[2], int in_edge, int depth)
|
|
|
|
|
{
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const MLoopUV *mloopuv = data->mloopuv;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
const unsigned int *loop_idx = mlooptri[tri_index].tri;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Enumerate all edges of the triangle, rotating the vertex list accordingly. */
|
|
|
|
|
for (int edge_idx = 0; edge_idx < 3; edge_idx++) {
|
|
|
|
|
/* but not the edge we have just recursed through */
|
|
|
|
|
if (edge_idx == in_edge)
|
|
|
|
|
continue;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
float uv0[2], uv1[2], uv2[2];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
copy_v2_v2(uv0, mloopuv[loop_idx[(edge_idx + 0)]].uv);
|
|
|
|
|
copy_v2_v2(uv1, mloopuv[loop_idx[(edge_idx + 1) % 3]].uv);
|
|
|
|
|
copy_v2_v2(uv2, mloopuv[loop_idx[(edge_idx + 2) % 3]].uv);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Verify the target point is on the opposite side of the edge from the third triangle
|
|
|
|
|
* vertex, to ensure that we always move closer to the goal point. */
|
|
|
|
|
const float sidep = line_point_side_v2(uv0, uv1, pixel);
|
|
|
|
|
const float side2 = line_point_side_v2(uv0, uv1, uv2);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
if (side2 == 0.0f)
|
|
|
|
|
continue;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Hack: allow all edges of the original triangle */
|
|
|
|
|
const bool correct_side = (in_edge == -1) || (sidep < 0 && side2 > 0) || (sidep > 0 && side2 < 0);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Allow exactly on edge for the non-recursive case */
|
|
|
|
|
if (!correct_side && sidep != 0.0f)
|
|
|
|
|
continue;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Now find another face that is linked to that edge. */
|
|
|
|
|
const int vert0 = mloop[loop_idx[(edge_idx + 0)]].v;
|
|
|
|
|
const int vert1 = mloop[loop_idx[(edge_idx + 1) % 3]].v;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Use a pre-computed vert-to-looptri mapping, speeds up things a lot compared to looping over all loopti. */
|
|
|
|
|
const MeshElemMap *map = &bdata->vert_to_looptri_map[vert0];
|
|
|
|
|
|
|
|
|
|
bool found_other = false;
|
|
|
|
|
int target_tri = -1;
|
|
|
|
|
int target_edge = -1;
|
|
|
|
|
|
|
|
|
|
float ouv0[2], ouv1[2];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < map->count && !found_other; i++) {
|
|
|
|
|
const int lt_index = map->indices[i];
|
|
|
|
|
|
|
|
|
|
if (lt_index == tri_index)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const unsigned int *other_loop_idx = mlooptri[lt_index].tri;
|
|
|
|
|
|
|
|
|
|
/* Check edges for match, looping in the same order as the outer loop. */
|
2017-03-12 02:40:04 +11:00
|
|
|
for (int j = 0; j < 3; j++) {
|
2017-01-03 19:11:59 +03:00
|
|
|
const int overt0 = mloop[other_loop_idx[(j + 0)]].v;
|
|
|
|
|
const int overt1 = mloop[other_loop_idx[(j + 1) % 3]].v;
|
|
|
|
|
|
|
|
|
|
/* Allow for swapped vertex order */
|
|
|
|
|
if (overt0 == vert0 && overt1 == vert1) {
|
|
|
|
|
found_other = true;
|
|
|
|
|
copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 0)]].uv);
|
|
|
|
|
copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 1) % 3]].uv);
|
|
|
|
|
}
|
|
|
|
|
else if (overt0 == vert1 && overt1 == vert0) {
|
|
|
|
|
found_other = true;
|
|
|
|
|
copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 0)]].uv);
|
|
|
|
|
copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 1) % 3]].uv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found_other) {
|
|
|
|
|
target_tri = lt_index;
|
|
|
|
|
target_edge = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-27 11:13:04 +03:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
if (!found_other) {
|
|
|
|
|
if (bdata->best_index < 0)
|
|
|
|
|
bdata->best_index = ON_MESH_EDGE;
|
2016-09-27 11:13:04 +03:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
continue;
|
|
|
|
|
}
|
2016-09-27 11:13:04 +03:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* If this edge is connected in UV space too, recurse */
|
|
|
|
|
if (equals_v2v2(uv0, ouv0) && equals_v2v2(uv1, ouv1)) {
|
|
|
|
|
if (depth > 0 && correct_side) {
|
|
|
|
|
dynamic_paint_find_island_border(data, bdata, target_tri, pixel, target_edge, depth - 1);
|
2016-09-27 11:13:04 +03:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
continue;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
/* Otherwise try to map to the other side of the edge.
|
|
|
|
|
* First check if there already is a better solution. */
|
|
|
|
|
const float dist_squared = dist_squared_to_line_segment_v2(pixel, uv0, uv1);
|
|
|
|
|
|
|
|
|
|
if (bdata->best_index >= 0 && dist_squared >= bdata->best_weight)
|
|
|
|
|
continue;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Find a point that is relatively at same edge position
|
|
|
|
|
* on this other face UV
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
*/
|
2017-01-03 19:11:59 +03:00
|
|
|
float closest_point[2], dir_vec[2], tgt_pixel[2];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
float lambda = closest_to_line_v2(closest_point, pixel, uv0, uv1);
|
|
|
|
|
CLAMP(lambda, 0.0f, 1.0f);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
sub_v2_v2v2(dir_vec, ouv1, ouv0);
|
|
|
|
|
madd_v2_v2v2fl(tgt_pixel, ouv0, dir_vec, lambda);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
int w = bdata->w, h = bdata->h, px = bdata->px, py = bdata->py;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
int final_pixel[2] = { (int)floorf(tgt_pixel[0] * w), (int)floorf(tgt_pixel[1] * h) };
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If current pixel uv is outside of texture */
|
2017-03-12 02:40:04 +11:00
|
|
|
if (final_pixel[0] < 0 || final_pixel[0] >= w || final_pixel[1] < 0 || final_pixel[1] >= h) {
|
2017-01-03 19:11:59 +03:00
|
|
|
if (bdata->best_index == NOT_FOUND)
|
|
|
|
|
bdata->best_index = OUT_OF_TEXTURE;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
const PaintUVPoint *tempPoints = data->tempPoints;
|
|
|
|
|
int final_index = final_pixel[0] + w * final_pixel[1];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If we ended up to our origin point ( mesh has smaller than pixel sized faces) */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (final_index == (px + w * py))
|
2017-01-03 19:11:59 +03:00
|
|
|
continue;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* If final point is an "edge pixel", use it's "real" neighbor instead */
|
2016-09-27 11:13:04 +03:00
|
|
|
if (tempPoints[final_index].neighbour_pixel != -1) {
|
|
|
|
|
final_index = tempPoints[final_index].neighbour_pixel;
|
|
|
|
|
|
|
|
|
|
/* If we ended up to our origin point */
|
|
|
|
|
if (final_index == (px + w * py))
|
2017-01-03 19:11:59 +03:00
|
|
|
continue;
|
2016-09-27 11:13:04 +03:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If found pixel still lies on wrong face ( mesh has smaller than pixel sized faces) */
|
2017-01-03 19:13:02 +03:00
|
|
|
if (tempPoints[final_index].tri_index != target_tri) {
|
|
|
|
|
/* Check if it's close enough to likely touch the intended triangle. Any triangle
|
|
|
|
|
* becomes thinner than a pixel at its vertices, so robustness requires some margin. */
|
|
|
|
|
const float final_pt[2] = { ((final_index % w) + 0.5f) / w, ((final_index / w) + 0.5f) / h };
|
|
|
|
|
const float threshold = SQUARE(0.7f) / (w * h);
|
|
|
|
|
|
|
|
|
|
if (dist_squared_to_looptri_uv_edges(mlooptri, mloopuv, tempPoints[final_index].tri_index, final_pt) > threshold)
|
2017-01-03 19:11:59 +03:00
|
|
|
continue;
|
2017-01-03 19:13:02 +03:00
|
|
|
}
|
|
|
|
|
|
2017-01-03 19:11:59 +03:00
|
|
|
bdata->best_index = final_index;
|
|
|
|
|
bdata->best_weight = dist_squared;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
static bool dynamicPaint_pointHasNeighbor(PaintAdjData *ed, int index, int neighbor)
|
|
|
|
|
{
|
|
|
|
|
const int idx = ed->n_index[index];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ed->n_num[index]; i++) {
|
|
|
|
|
if (ed->n_target[idx + i] == neighbor) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Makes the adjacency data symmetric, except for border pixels. I.e. if A is neighbor of B, B is neighbor of A. */
|
|
|
|
|
static bool dynamicPaint_symmetrizeAdjData(PaintAdjData *ed, int active_points)
|
|
|
|
|
{
|
|
|
|
|
int *new_n_index = MEM_callocN(sizeof(int) * active_points, "Surface Adj Index");
|
|
|
|
|
int *new_n_num = MEM_callocN(sizeof(int) * active_points, "Surface Adj Counts");
|
|
|
|
|
|
|
|
|
|
if (new_n_num && new_n_index) {
|
|
|
|
|
/* Count symmetrized neigbors */
|
|
|
|
|
int total_targets = 0;
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < active_points; index++) {
|
|
|
|
|
total_targets += ed->n_num[index];
|
|
|
|
|
new_n_num[index] = ed->n_num[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < active_points; index++) {
|
|
|
|
|
if (ed->flags[index] & ADJ_BORDER_PIXEL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0, idx = ed->n_index[index]; i < ed->n_num[index]; i++) {
|
|
|
|
|
const int target = ed->n_target[idx + i];
|
|
|
|
|
|
|
|
|
|
assert(!(ed->flags[target] & ADJ_BORDER_PIXEL));
|
|
|
|
|
|
|
|
|
|
if (!dynamicPaint_pointHasNeighbor(ed, target, index)) {
|
|
|
|
|
new_n_num[target]++;
|
|
|
|
|
total_targets++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-27 11:13:04 +03:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
/* Allocate a new target map */
|
|
|
|
|
int *new_n_target = MEM_callocN(sizeof(int) * total_targets, "Surface Adj Targets");
|
|
|
|
|
|
|
|
|
|
if (new_n_target) {
|
|
|
|
|
/* Copy existing neighbors to the new map */
|
|
|
|
|
int n_pos = 0;
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < active_points; index++) {
|
|
|
|
|
new_n_index[index] = n_pos;
|
|
|
|
|
memcpy(&new_n_target[n_pos], &ed->n_target[ed->n_index[index]], sizeof(int) * ed->n_num[index]);
|
|
|
|
|
|
|
|
|
|
/* Reset count to old, but advance position by new, leaving a gap to fill below. */
|
|
|
|
|
n_pos += new_n_num[index];
|
|
|
|
|
new_n_num[index] = ed->n_num[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(n_pos == total_targets);
|
|
|
|
|
|
|
|
|
|
/* Add symmetrized - this loop behavior must exactly match the count pass above */
|
|
|
|
|
for (int index = 0; index < active_points; index++) {
|
|
|
|
|
if (ed->flags[index] & ADJ_BORDER_PIXEL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0, idx = ed->n_index[index]; i < ed->n_num[index]; i++) {
|
|
|
|
|
const int target = ed->n_target[idx + i];
|
|
|
|
|
|
|
|
|
|
if (!dynamicPaint_pointHasNeighbor(ed, target, index)) {
|
|
|
|
|
const int num = new_n_num[target]++;
|
|
|
|
|
new_n_target[new_n_index[target] + num] = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Swap maps */
|
|
|
|
|
MEM_freeN(ed->n_target);
|
|
|
|
|
ed->n_target = new_n_target;
|
|
|
|
|
|
|
|
|
|
MEM_freeN(ed->n_index);
|
|
|
|
|
ed->n_index = new_n_index;
|
|
|
|
|
|
|
|
|
|
MEM_freeN(ed->n_num);
|
|
|
|
|
ed->n_num = new_n_num;
|
|
|
|
|
|
|
|
|
|
ed->total_targets = total_targets;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2017-01-03 18:50:15 +03:00
|
|
|
|
|
|
|
|
if (new_n_index)
|
|
|
|
|
MEM_freeN(new_n_index);
|
|
|
|
|
if (new_n_num)
|
|
|
|
|
MEM_freeN(new_n_num);
|
|
|
|
|
|
|
|
|
|
return false;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface, float *progress, short *do_update)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Antialias jitter point relative coords */
|
2016-05-20 23:16:52 +02:00
|
|
|
const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
2012-01-11 08:51:06 +00:00
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
2016-05-20 23:16:52 +02:00
|
|
|
uint32_t active_points = 0;
|
2016-05-12 12:08:03 +02:00
|
|
|
bool error = false;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
PaintSurfaceData *sData;
|
|
|
|
|
DynamicPaintCanvasSettings *canvas = surface->canvas;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = canvas->mesh;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
PaintUVPoint *tempPoints = NULL;
|
|
|
|
|
Vec3f *tempWeights = NULL;
|
2015-07-27 15:52:54 +10:00
|
|
|
const MLoopTri *mlooptri = NULL;
|
|
|
|
|
const MLoopUV *mloopuv = NULL;
|
|
|
|
|
const MLoop *mloop = NULL;
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
Bounds2D *faceBB = NULL;
|
2011-06-27 07:30:58 +00:00
|
|
|
int *final_index;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.0f;
|
|
|
|
|
*do_update = true;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
if (!mesh)
|
2012-10-26 17:32:50 +00:00
|
|
|
return setError(canvas, N_("Canvas mesh not updated"));
|
|
|
|
|
if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ)
|
|
|
|
|
return setError(canvas, N_("Cannot bake non-'image sequence' formats"));
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
mloop = mesh->mloop;
|
2018-11-15 16:33:00 +01:00
|
|
|
mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
2018-09-24 16:32:29 +02:00
|
|
|
const int tottri = BKE_mesh_runtime_looptri_len(mesh);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-11-23 17:25:25 +00:00
|
|
|
/* get uv map */
|
2018-09-24 16:32:29 +02:00
|
|
|
if (CustomData_has_layer(&mesh->ldata, CD_MLOOPUV)) {
|
|
|
|
|
CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, surface->uvlayer_name, uvname);
|
|
|
|
|
mloopuv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname);
|
2016-02-04 14:17:52 +11:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Check for validity */
|
2015-07-27 15:52:54 +10:00
|
|
|
if (!mloopuv)
|
2012-10-26 17:32:50 +00:00
|
|
|
return setError(canvas, N_("No UV data on canvas"));
|
|
|
|
|
if (surface->image_resolution < 16 || surface->image_resolution > 8192)
|
|
|
|
|
return setError(canvas, N_("Invalid resolution"));
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
const int w = surface->image_resolution;
|
|
|
|
|
const int h = w;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Start generating the surface
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_INFO(&LOG, 1, "Preparing UV surface of %ix%i pixels and %i tris.", w, h, tottri);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Init data struct */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (surface->data)
|
|
|
|
|
dynamicPaint_freeSurfaceData(surface);
|
2011-06-16 10:41:00 +00:00
|
|
|
sData = surface->data = MEM_callocN(sizeof(PaintSurfaceData), "PaintSurfaceData");
|
2012-10-26 17:32:50 +00:00
|
|
|
if (!surface->data)
|
|
|
|
|
return setError(canvas, N_("Not enough free memory"));
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
tempPoints = MEM_callocN(w * h * sizeof(*tempPoints), "Temp PaintUVPoint");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!tempPoints)
|
|
|
|
|
error = true;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
final_index = MEM_callocN(w * h * sizeof(*final_index), "Temp UV Final Indexes");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!final_index)
|
|
|
|
|
error = true;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
tempWeights = MEM_mallocN(w * h * aa_samples * sizeof(*tempWeights), "Temp bWeights");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!tempWeights)
|
|
|
|
|
error = true;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Generate a temporary bounding box array for UV faces to optimize
|
|
|
|
|
* the pixel-inside-a-face search.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2011-06-27 07:30:58 +00:00
|
|
|
if (!error) {
|
2016-05-20 23:16:52 +02:00
|
|
|
faceBB = MEM_mallocN(tottri * sizeof(*faceBB), "MPCanvasFaceBB");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!faceBB)
|
|
|
|
|
error = true;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.01f;
|
|
|
|
|
*do_update = true;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!error) {
|
2016-05-20 23:16:52 +02:00
|
|
|
for (int i = 0; i < tottri; i++) {
|
|
|
|
|
copy_v2_v2(faceBB[i].min, mloopuv[mlooptri[i].tri[0]].uv);
|
|
|
|
|
copy_v2_v2(faceBB[i].max, mloopuv[mlooptri[i].tri[0]].uv);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
for (int j = 1; j < 3; j++) {
|
|
|
|
|
minmax_v2v2_v2(faceBB[i].min, faceBB[i].max, mloopuv[mlooptri[i].tri[j]].uv);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.02f;
|
|
|
|
|
*do_update = true;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
/* Loop through every pixel and check if pixel is uv-mapped on a canvas face. */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintCreateUVSurfaceData data = {
|
|
|
|
|
.surface = surface, .tempPoints = tempPoints, .tempWeights = tempWeights,
|
|
|
|
|
.mlooptri = mlooptri, .mloopuv = mloopuv, .mloop = mloop, .tottri = tottri,
|
|
|
|
|
.faceBB = faceBB,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (h > 64 || tottri > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, h,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_create_uv_surface_direct_cb,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.04f;
|
|
|
|
|
*do_update = true;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Now loop through every pixel that was left without index
|
|
|
|
|
* and find if they have neighboring pixels that have an index.
|
|
|
|
|
* If so use that polygon as pixel surface.
|
|
|
|
|
* (To avoid seams on uv island edges)
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
data.active_points = &active_points;
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (h > 64);
|
|
|
|
|
BLI_task_parallel_range(0, h,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_create_uv_surface_neighbor_cb,
|
|
|
|
|
&settings);
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.06f;
|
|
|
|
|
*do_update = true;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Generate surface adjacency data. */
|
2011-12-31 10:28:36 +00:00
|
|
|
{
|
2015-11-23 11:27:02 +11:00
|
|
|
int cursor = 0;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/* Create a temporary array of final indexes (before unassigned
|
2018-09-02 18:28:27 +10:00
|
|
|
* pixels have been dropped) */
|
2015-11-23 11:27:02 +11:00
|
|
|
for (int i = 0; i < w * h; i++) {
|
2015-07-27 15:52:54 +10:00
|
|
|
if (tempPoints[i].tri_index != -1) {
|
2011-06-27 07:30:58 +00:00
|
|
|
final_index[i] = cursor;
|
|
|
|
|
cursor++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* allocate memory */
|
2012-05-12 16:11:34 +00:00
|
|
|
sData->total_points = w * h;
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_initAdjacencyData(surface, true);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
if (sData->adj_data) {
|
|
|
|
|
PaintAdjData *ed = sData->adj_data;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
int n_pos = 0;
|
|
|
|
|
|
|
|
|
|
MeshElemMap *vert_to_looptri_map;
|
|
|
|
|
int *vert_to_looptri_map_mem;
|
|
|
|
|
|
|
|
|
|
BKE_mesh_vert_looptri_map_create(
|
|
|
|
|
&vert_to_looptri_map, &vert_to_looptri_map_mem,
|
2018-09-24 16:32:29 +02:00
|
|
|
mesh->mvert, mesh->totvert, mlooptri, tottri, mloop, mesh->totloop);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
int total_border = 0;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int ty = 0; ty < h; ty++) {
|
2016-05-20 23:16:52 +02:00
|
|
|
for (int tx = 0; tx < w; tx++) {
|
|
|
|
|
const int index = tx + w * ty;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2015-07-27 15:52:54 +10:00
|
|
|
if (tempPoints[index].tri_index != -1) {
|
2011-06-27 07:30:58 +00:00
|
|
|
ed->n_index[final_index[index]] = n_pos;
|
2011-07-08 11:03:37 +00:00
|
|
|
ed->n_num[final_index[index]] = 0;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
if (tempPoints[index].neighbour_pixel != -1) {
|
|
|
|
|
ed->flags[final_index[index]] |= ADJ_BORDER_PIXEL;
|
|
|
|
|
total_border++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-23 11:27:02 +11:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2016-05-20 23:16:52 +02:00
|
|
|
/* Try to find a neighboring pixel in defined direction. If not found, -1 is returned */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int n_target = dynamic_paint_find_neighbour_pixel(
|
|
|
|
|
&data, vert_to_looptri_map, w, h, tx, ty, i);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-09-27 12:21:44 +03:00
|
|
|
if (n_target >= 0 && n_target != index) {
|
2017-01-03 18:50:15 +03:00
|
|
|
if (!dynamicPaint_pointHasNeighbor(ed, final_index[index], final_index[n_target])) {
|
2016-09-27 12:21:44 +03:00
|
|
|
ed->n_target[n_pos] = final_index[n_target];
|
|
|
|
|
ed->n_num[final_index[index]]++;
|
|
|
|
|
n_pos++;
|
|
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2012-01-24 17:28:50 +00:00
|
|
|
else if (n_target == ON_MESH_EDGE || n_target == OUT_OF_TEXTURE) {
|
|
|
|
|
ed->flags[final_index[index]] |= ADJ_ON_MESH_EDGE;
|
|
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
MEM_freeN(vert_to_looptri_map);
|
|
|
|
|
MEM_freeN(vert_to_looptri_map_mem);
|
2017-01-03 18:50:15 +03:00
|
|
|
|
|
|
|
|
/* Make neighbors symmetric */
|
|
|
|
|
if (!dynamicPaint_symmetrizeAdjData(ed, active_points)) {
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a list of border pixels */
|
|
|
|
|
ed->border = MEM_callocN(sizeof(int) * total_border, "Border Pixel Index");
|
|
|
|
|
|
|
|
|
|
if (ed->border) {
|
|
|
|
|
ed->total_border = total_border;
|
|
|
|
|
|
|
|
|
|
for (int i = 0, next = 0; i < active_points; i++) {
|
|
|
|
|
if (ed->flags[i] & ADJ_BORDER_PIXEL) {
|
|
|
|
|
ed->border[next++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-03 19:11:59 +03:00
|
|
|
|
|
|
|
|
#if 0
|
2018-11-14 12:53:15 +11:00
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
|
* For debug, write a dump of adjacency data to a file.
|
|
|
|
|
* -----------------------------------------------------------------*/
|
2017-01-03 19:11:59 +03:00
|
|
|
FILE *dump_file = fopen("dynpaint-adj-data.txt", "w");
|
|
|
|
|
int *tmp = MEM_callocN(sizeof(int) * active_points, "tmp");
|
|
|
|
|
for (int ty = 0; ty < h; ty++) {
|
|
|
|
|
for (int tx = 0; tx < w; tx++) {
|
|
|
|
|
const int index = tx + w * ty;
|
|
|
|
|
if (tempPoints[index].tri_index != -1)
|
|
|
|
|
tmp[final_index[index]] = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int ty = 0; ty < h; ty++) {
|
|
|
|
|
for (int tx = 0; tx < w; tx++) {
|
|
|
|
|
const int index = tx + w * ty;
|
|
|
|
|
const int fidx = final_index[index];
|
|
|
|
|
|
|
|
|
|
if (tempPoints[index].tri_index != -1) {
|
|
|
|
|
int nidx = tempPoints[index].neighbour_pixel;
|
|
|
|
|
fprintf(dump_file, "%d\t%d,%d\t%u\t%d,%d\t%d\t", fidx, tx, h-1-ty, tempPoints[index].tri_index, nidx<0?-1:(nidx%w), nidx<0?-1:h-1-(nidx/w), ed->flags[fidx]);
|
|
|
|
|
for (int i = 0; i < ed->n_num[fidx]; i++) {
|
|
|
|
|
int tgt = tmp[ed->n_target[ed->n_index[fidx]+i]];
|
|
|
|
|
fprintf(dump_file, "%s%d,%d", i?" ":"", tgt%w, h-1-tgt/w);
|
|
|
|
|
}
|
|
|
|
|
fprintf(dump_file, "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(tmp);
|
|
|
|
|
fclose(dump_file);
|
|
|
|
|
#endif
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.08f;
|
|
|
|
|
*do_update = true;
|
|
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/* Create final surface data without inactive points */
|
2016-05-20 23:16:52 +02:00
|
|
|
ImgSeqFormatData *f_data = MEM_callocN(sizeof(*f_data), "ImgSeqFormatData");
|
|
|
|
|
if (f_data) {
|
|
|
|
|
f_data->uv_p = MEM_callocN(active_points * sizeof(*f_data->uv_p), "PaintUVPoint");
|
2016-06-19 06:25:54 +10:00
|
|
|
f_data->barycentricWeights =
|
|
|
|
|
MEM_callocN(active_points * aa_samples * sizeof(*f_data->barycentricWeights), "PaintUVPoint");
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
if (!f_data->uv_p || !f_data->barycentricWeights)
|
2013-03-09 03:46:30 +00:00
|
|
|
error = 1;
|
2016-05-20 23:16:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
error = 1;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
/* in case of allocation error, free everything */
|
|
|
|
|
if (error) {
|
|
|
|
|
if (f_data) {
|
|
|
|
|
if (f_data->uv_p)
|
|
|
|
|
MEM_freeN(f_data->uv_p);
|
|
|
|
|
if (f_data->barycentricWeights)
|
|
|
|
|
MEM_freeN(f_data->barycentricWeights);
|
|
|
|
|
MEM_freeN(f_data);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2016-05-20 23:16:52 +02:00
|
|
|
sData->total_points = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sData->total_points = (int)active_points;
|
|
|
|
|
sData->format_data = f_data;
|
|
|
|
|
|
|
|
|
|
for (int index = 0, cursor = 0; index < (w * h); index++) {
|
|
|
|
|
if (tempPoints[index].tri_index != -1) {
|
|
|
|
|
memcpy(&f_data->uv_p[cursor], &tempPoints[index], sizeof(PaintUVPoint));
|
|
|
|
|
memcpy(&f_data->barycentricWeights[cursor * aa_samples], &tempWeights[index * aa_samples],
|
2018-01-16 11:40:43 +11:00
|
|
|
sizeof(*tempWeights) * aa_samples);
|
2016-05-20 23:16:52 +02:00
|
|
|
cursor++;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-26 17:32:50 +00:00
|
|
|
if (error == 1)
|
|
|
|
|
setError(canvas, N_("Not enough free memory"));
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (faceBB)
|
|
|
|
|
MEM_freeN(faceBB);
|
|
|
|
|
if (tempPoints)
|
|
|
|
|
MEM_freeN(tempPoints);
|
|
|
|
|
if (tempWeights)
|
|
|
|
|
MEM_freeN(tempWeights);
|
|
|
|
|
if (final_index)
|
|
|
|
|
MEM_freeN(final_index);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* Init surface type data */
|
2011-06-27 07:30:58 +00:00
|
|
|
if (!error) {
|
|
|
|
|
dynamicPaint_allocateSurfaceType(surface);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
#if 0
|
2018-11-14 12:53:15 +11:00
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
|
* For debug, output pixel statuses to the color map
|
|
|
|
|
* -----------------------------------------------------------------*/
|
2016-05-12 12:08:03 +02:00
|
|
|
for (index = 0; index < sData->total_points; index++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data;
|
|
|
|
|
PaintUVPoint *uvPoint = &((PaintUVPoint *)f_data->uv_p)[index];
|
|
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
pPoint->alpha = 1.0f;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Every pixel that is assigned as "edge pixel" gets blue color */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (uvPoint->neighbour_pixel != -1)
|
|
|
|
|
pPoint->color[2] = 1.0f;
|
2018-11-14 12:53:15 +11:00
|
|
|
/* and every pixel that finally got an polygon gets red color */
|
|
|
|
|
/* green color shows pixel face index hash */
|
2016-05-20 23:16:52 +02:00
|
|
|
if (uvPoint->tri_index != -1) {
|
|
|
|
|
pPoint->color[0] = 1.0f;
|
2016-05-12 12:08:03 +02:00
|
|
|
pPoint->color[1] = (float)(uvPoint->tri_index % 255) / 256.0f;
|
2016-05-20 23:16:52 +02:00
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
2016-05-20 23:16:52 +02:00
|
|
|
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
dynamicPaint_setInitialColor(scene, surface);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-21 16:09:35 +02:00
|
|
|
*progress = 0.09f;
|
|
|
|
|
*do_update = true;
|
|
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
return (error == 0);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Outputs an image file from uv surface data.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintOutputSurfaceImageData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
} DynamicPaintOutputSurfaceImageData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_output_surface_image_paint_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintOutputSurfaceImageData *data = userdata;
|
2011-10-28 14:46:09 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintPoint *point = &((PaintPoint *)surface->data->type_data)[index];
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf = data->ibuf;
|
|
|
|
|
/* image buffer position */
|
|
|
|
|
const int pos = ((ImgSeqFormatData *)(surface->data->format_data))->uv_p[index].pixel_index * 4;
|
|
|
|
|
|
|
|
|
|
/* blend wet and dry layers */
|
|
|
|
|
blendColors(point->color, point->color[3], point->e_color, point->e_color[3], &ibuf->rect_float[pos]);
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Multiply color by alpha if enabled */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (surface->flags & MOD_DPAINT_MULALPHA) {
|
|
|
|
|
mul_v3_fl(&ibuf->rect_float[pos], ibuf->rect_float[pos + 3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_output_surface_image_displace_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintOutputSurfaceImageData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
float depth = ((float *)surface->data->type_data)[index];
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf = data->ibuf;
|
|
|
|
|
/* image buffer position */
|
|
|
|
|
const int pos = ((ImgSeqFormatData *)(surface->data->format_data))->uv_p[index].pixel_index * 4;
|
|
|
|
|
|
|
|
|
|
if (surface->depth_clamp)
|
|
|
|
|
depth /= surface->depth_clamp;
|
|
|
|
|
|
|
|
|
|
if (surface->disp_type == MOD_DPAINT_DISP_DISPLACE) {
|
|
|
|
|
depth = (0.5f - depth / 2.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLAMP(depth, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
copy_v3_fl(&ibuf->rect_float[pos], depth);
|
|
|
|
|
ibuf->rect_float[pos + 3] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_output_surface_image_wave_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintOutputSurfaceImageData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintWavePoint *wPoint = &((PaintWavePoint *)surface->data->type_data)[index];
|
|
|
|
|
float depth = wPoint->height;
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf = data->ibuf;
|
|
|
|
|
/* image buffer position */
|
|
|
|
|
const int pos = ((ImgSeqFormatData *)(surface->data->format_data))->uv_p[index].pixel_index * 4;
|
|
|
|
|
|
|
|
|
|
if (surface->depth_clamp)
|
|
|
|
|
depth /= surface->depth_clamp;
|
|
|
|
|
|
|
|
|
|
depth = (0.5f + depth / 2.0f);
|
|
|
|
|
CLAMP(depth, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
copy_v3_fl(&ibuf->rect_float[pos], depth);
|
|
|
|
|
ibuf->rect_float[pos + 3] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_output_surface_image_wetmap_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintOutputSurfaceImageData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintPoint *point = &((PaintPoint *)surface->data->type_data)[index];
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf = data->ibuf;
|
|
|
|
|
/* image buffer position */
|
|
|
|
|
const int pos = ((ImgSeqFormatData *)(surface->data->format_data))->uv_p[index].pixel_index * 4;
|
|
|
|
|
|
|
|
|
|
copy_v3_fl(&ibuf->rect_float[pos], (point->wetness > 1.0f) ? 1.0f : point->wetness);
|
|
|
|
|
ibuf->rect_float[pos + 3] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filename, short output_layer)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
ImBuf *ibuf = NULL;
|
2011-06-16 10:41:00 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
2018-11-14 12:53:15 +11:00
|
|
|
/* OpenEXR or PNG */
|
2011-11-22 00:35:26 +00:00
|
|
|
int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG;
|
2011-10-28 14:46:09 +00:00
|
|
|
char output_file[FILE_MAX];
|
|
|
|
|
|
2012-10-26 17:32:50 +00:00
|
|
|
if (!sData->type_data) {
|
|
|
|
|
setError(surface->canvas, N_("Image save failed: invalid surface"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-24 17:27:41 +02:00
|
|
|
/* if selected format is openexr, but current build doesn't support one */
|
2013-12-22 14:11:10 +11:00
|
|
|
#ifndef WITH_OPENEXR
|
2016-05-12 12:08:03 +02:00
|
|
|
if (format == R_IMF_IMTYPE_OPENEXR)
|
|
|
|
|
format = R_IMF_IMTYPE_PNG;
|
2013-12-22 14:11:10 +11:00
|
|
|
#endif
|
2011-10-28 14:46:09 +00:00
|
|
|
BLI_strncpy(output_file, filename, sizeof(output_file));
|
2015-01-24 16:48:23 +11:00
|
|
|
BKE_image_path_ensure_ext_from_imtype(output_file, format);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Validate output file path */
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(output_file, BKE_main_blendfile_path_from_global());
|
2011-06-16 10:41:00 +00:00
|
|
|
BLI_make_existing_file(output_file);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Init image buffer */
|
2011-10-13 20:00:22 +00:00
|
|
|
ibuf = IMB_allocImBuf(surface->image_resolution, surface->image_resolution, 32, IB_rectfloat);
|
2012-10-26 17:32:50 +00:00
|
|
|
if (ibuf == NULL) {
|
|
|
|
|
setError(surface->canvas, N_("Image save failed: not enough free memory"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2019-01-07 00:06:58 +11:00
|
|
|
DynamicPaintOutputSurfaceImageData data = { .surface = surface, .ibuf = ibuf, };
|
2016-06-19 06:25:54 +10:00
|
|
|
switch (surface->type) {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
case MOD_DPAINT_SURFACE_T_PAINT:
|
|
|
|
|
switch (output_layer) {
|
|
|
|
|
case 0:
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 10000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_output_surface_image_paint_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
2018-01-08 11:35:48 +01:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
case 1:
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 10000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_output_surface_image_wetmap_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
2018-01-08 11:35:48 +01:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_DISPLACE:
|
|
|
|
|
switch (output_layer) {
|
|
|
|
|
case 0:
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 10000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_output_surface_image_displace_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
2018-01-08 11:35:48 +01:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
case 1:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
2011-10-28 14:46:09 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_SURFACE_T_WAVE:
|
|
|
|
|
switch (output_layer) {
|
|
|
|
|
case 0:
|
2018-01-08 11:35:48 +01:00
|
|
|
{
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 10000);
|
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
|
0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_output_surface_image_wave_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
2018-01-08 11:35:48 +01:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
case 1:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
2011-10-28 14:46:09 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* Set output format, png in case exr isn't supported */
|
2011-06-16 10:41:00 +00:00
|
|
|
#ifdef WITH_OPENEXR
|
2012-05-12 16:11:34 +00:00
|
|
|
if (format == R_IMF_IMTYPE_OPENEXR) { /* OpenEXR 32-bit float */
|
2015-07-13 13:58:17 +02:00
|
|
|
ibuf->ftype = IMB_FTYPE_OPENEXR;
|
|
|
|
|
ibuf->foptions.flag |= OPENEXR_COMPRESS;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
else
|
2011-06-16 10:41:00 +00:00
|
|
|
#endif
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
ibuf->ftype = IMB_FTYPE_PNG;
|
|
|
|
|
ibuf->foptions.quality = 15;
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
/* Save image */
|
|
|
|
|
IMB_saveiff(ibuf, output_file, IB_rectfloat);
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/***************************** Ray / Nearest Point Utils ******************************/
|
|
|
|
|
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
/* A modified callback to bvh tree raycast. The tree must have been built using bvhtree_from_mesh_looptri.
|
2012-05-12 16:11:34 +00:00
|
|
|
* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
|
|
|
|
|
*
|
2018-11-14 12:53:15 +11:00
|
|
|
* To optimize brush detection speed this doesn't calculate hit coordinates or normal.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2015-07-27 15:52:54 +10:00
|
|
|
static void mesh_tris_spherecast_dp(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
|
2015-07-22 17:39:33 +10:00
|
|
|
const MVert *vert = data->vert;
|
2015-07-27 15:52:54 +10:00
|
|
|
const MLoopTri *mlooptri = data->looptri;
|
|
|
|
|
const MLoop *mloop = data->loop;
|
|
|
|
|
|
|
|
|
|
const float *t0, *t1, *t2;
|
|
|
|
|
float dist;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2015-07-27 15:52:54 +10:00
|
|
|
t0 = vert[mloop[mlooptri[index].tri[0]].v].co;
|
|
|
|
|
t1 = vert[mloop[mlooptri[index].tri[1]].v].co;
|
|
|
|
|
t2 = vert[mloop[mlooptri[index].tri[2]].v].co;
|
|
|
|
|
|
|
|
|
|
dist = bvhtree_ray_tri_intersection(ray, hit->dist, t0, t1, t2);
|
|
|
|
|
|
|
|
|
|
if (dist >= 0 && dist < hit->dist) {
|
|
|
|
|
hit->index = index;
|
|
|
|
|
hit->dist = dist;
|
|
|
|
|
hit->no[0] = 0.0f;
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
/* A modified callback to bvh tree nearest point. The tree must have been built using bvhtree_from_mesh_looptri.
|
2018-09-02 18:28:27 +10:00
|
|
|
* userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree.
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
2018-09-02 18:28:27 +10:00
|
|
|
* To optimize brush detection speed this doesn't calculate hit normal.
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2015-07-27 15:52:54 +10:00
|
|
|
static void mesh_tris_nearest_point_dp(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata;
|
2015-07-22 17:39:33 +10:00
|
|
|
const MVert *vert = data->vert;
|
2015-07-27 15:52:54 +10:00
|
|
|
const MLoopTri *mlooptri = data->looptri;
|
|
|
|
|
const MLoop *mloop = data->loop;
|
|
|
|
|
float nearest_tmp[3], dist_sq;
|
|
|
|
|
|
|
|
|
|
const float *t0, *t1, *t2;
|
|
|
|
|
t0 = vert[mloop[mlooptri[index].tri[0]].v].co;
|
|
|
|
|
t1 = vert[mloop[mlooptri[index].tri[1]].v].co;
|
|
|
|
|
t2 = vert[mloop[mlooptri[index].tri[2]].v].co;
|
|
|
|
|
|
|
|
|
|
closest_on_tri_to_point_v3(nearest_tmp, co, t0, t1, t2);
|
|
|
|
|
dist_sq = len_squared_v3v3(co, nearest_tmp);
|
|
|
|
|
|
|
|
|
|
if (dist_sq < nearest->dist_sq) {
|
|
|
|
|
nearest->index = index;
|
|
|
|
|
nearest->dist_sq = dist_sq;
|
|
|
|
|
copy_v3_v3(nearest->co, nearest_tmp);
|
|
|
|
|
nearest->no[0] = 0.0f;
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/***************************** Brush Painting Calls ******************************/
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-09-26 20:05:38 +00:00
|
|
|
/**
|
|
|
|
|
* Mix color values to canvas point.
|
2012-05-12 16:11:34 +00:00
|
|
|
*
|
2015-05-20 12:54:45 +10:00
|
|
|
* \param surface: Canvas surface
|
|
|
|
|
* \param index: Surface point index
|
|
|
|
|
* \param paintFlags: paint object flags
|
|
|
|
|
* \param paintColor,paintAlpha,paintWetness: To be mixed paint values
|
|
|
|
|
* \param timescale: Value used to adjust time dependent
|
2012-09-26 20:05:38 +00:00
|
|
|
* operations when using substeps
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2015-05-20 12:54:45 +10:00
|
|
|
static void dynamicPaint_mixPaintColors(
|
2016-05-20 23:16:52 +02:00
|
|
|
const DynamicPaintSurface *surface, const int index, const int paintFlags,
|
|
|
|
|
const float paintColor[3], const float paintAlpha, const float paintWetness, const float timescale)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
PaintPoint *pPoint = &((PaintPoint *)surface->data->type_data)[index];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Add paint */
|
2011-05-24 07:08:58 +00:00
|
|
|
if (!(paintFlags & MOD_DPAINT_ERASE)) {
|
2011-11-02 11:32:22 +00:00
|
|
|
float mix[4];
|
2016-05-20 23:16:52 +02:00
|
|
|
float temp_alpha = paintAlpha * ((paintFlags & MOD_DPAINT_ABS_ALPHA) ? 1.0f : timescale);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/* mix brush color with wet layer color */
|
2015-07-27 15:52:54 +10:00
|
|
|
blendColors(pPoint->e_color, pPoint->e_color[3], paintColor, temp_alpha, mix);
|
2011-10-31 13:01:06 +00:00
|
|
|
copy_v3_v3(pPoint->e_color, mix);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-11-02 11:32:22 +00:00
|
|
|
/* mix wetness and alpha depending on selected alpha mode */
|
2011-05-24 07:08:58 +00:00
|
|
|
if (paintFlags & MOD_DPAINT_ABS_ALPHA) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* update values to the brush level unless they're higher already */
|
2016-05-20 23:16:52 +02:00
|
|
|
CLAMP_MIN(pPoint->e_color[3], paintAlpha);
|
|
|
|
|
CLAMP_MIN(pPoint->wetness, paintWetness);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2016-05-20 23:16:52 +02:00
|
|
|
float wetness = paintWetness;
|
2011-11-02 11:32:22 +00:00
|
|
|
CLAMP(wetness, 0.0f, 1.0f);
|
2015-07-27 15:52:54 +10:00
|
|
|
pPoint->e_color[3] = mix[3];
|
2012-05-12 16:11:34 +00:00
|
|
|
pPoint->wetness = pPoint->wetness * (1.0f - wetness) + wetness;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-27 15:52:54 +10:00
|
|
|
CLAMP_MIN(pPoint->wetness, MIN_WETNESS);
|
2011-11-02 11:32:22 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
pPoint->state = DPAINT_PAINT_NEW;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Erase paint */
|
2011-05-24 07:08:58 +00:00
|
|
|
else {
|
|
|
|
|
float a_ratio, a_highest;
|
|
|
|
|
float wetness;
|
2016-05-20 23:16:52 +02:00
|
|
|
float invFact = 1.0f - paintAlpha;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Make highest alpha to match erased value
|
|
|
|
|
* but maintain alpha ratio
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
if (paintFlags & MOD_DPAINT_ABS_ALPHA) {
|
2015-07-27 15:52:54 +10:00
|
|
|
a_highest = max_ff(pPoint->color[3], pPoint->e_color[3]);
|
2011-05-24 07:08:58 +00:00
|
|
|
if (a_highest > invFact) {
|
|
|
|
|
a_ratio = invFact / a_highest;
|
|
|
|
|
|
2015-07-27 15:52:54 +10:00
|
|
|
pPoint->e_color[3] *= a_ratio;
|
|
|
|
|
pPoint->color[3] *= a_ratio;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2016-05-20 23:16:52 +02:00
|
|
|
pPoint->e_color[3] -= paintAlpha * timescale;
|
2015-07-27 15:52:54 +10:00
|
|
|
CLAMP_MIN(pPoint->e_color[3], 0.0f);
|
2016-05-20 23:16:52 +02:00
|
|
|
pPoint->color[3] -= paintAlpha * timescale;
|
2015-07-27 15:52:54 +10:00
|
|
|
CLAMP_MIN(pPoint->color[3], 0.0f);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
wetness = (1.0f - paintWetness) * pPoint->e_color[3];
|
2015-07-27 15:52:54 +10:00
|
|
|
CLAMP_MAX(pPoint->wetness, wetness);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* applies given brush intersection value for wave surface */
|
2016-05-20 23:16:52 +02:00
|
|
|
static void dynamicPaint_mixWaveHeight(
|
|
|
|
|
PaintWavePoint *wPoint, const DynamicPaintBrushSettings *brush, float isect_height)
|
2011-07-02 18:06:39 +00:00
|
|
|
{
|
2016-05-20 23:16:52 +02:00
|
|
|
const float isect_change = isect_height - wPoint->brush_isect;
|
|
|
|
|
const float wave_factor = brush->wave_factor;
|
2016-05-12 12:08:03 +02:00
|
|
|
bool hit = false;
|
|
|
|
|
|
2011-11-16 18:32:28 +00:00
|
|
|
/* intersection marked regardless of brush type or hit */
|
|
|
|
|
wPoint->brush_isect = isect_height;
|
|
|
|
|
wPoint->state = DPAINT_WAVE_ISECT_CHANGED;
|
|
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
isect_height *= wave_factor;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
/* determine hit depending on wave_factor */
|
2016-05-20 23:16:52 +02:00
|
|
|
if (wave_factor > 0.0f && wPoint->height > isect_height)
|
2016-05-12 12:08:03 +02:00
|
|
|
hit = true;
|
2016-05-20 23:16:52 +02:00
|
|
|
else if (wave_factor < 0.0f && wPoint->height < isect_height)
|
2016-05-12 12:08:03 +02:00
|
|
|
hit = true;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
if (hit) {
|
2016-05-20 23:16:52 +02:00
|
|
|
switch (brush->wave_type) {
|
|
|
|
|
case MOD_DPAINT_WAVEB_DEPTH:
|
|
|
|
|
wPoint->height = isect_height;
|
|
|
|
|
wPoint->state = DPAINT_WAVE_OBSTACLE;
|
|
|
|
|
wPoint->velocity = 0.0f;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_WAVEB_FORCE:
|
|
|
|
|
wPoint->velocity = isect_height;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_WAVEB_REFLECT:
|
|
|
|
|
wPoint->state = DPAINT_WAVE_REFLECT_ONLY;
|
|
|
|
|
break;
|
|
|
|
|
case MOD_DPAINT_WAVEB_CHANGE:
|
|
|
|
|
if (isect_change < 0.0f)
|
|
|
|
|
wPoint->height += isect_change * wave_factor;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
2011-11-16 18:32:28 +00:00
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-08 11:03:37 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* add brush results to the surface data depending on surface type
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2016-05-12 12:08:03 +02:00
|
|
|
static void dynamicPaint_updatePointData(
|
2016-05-20 23:16:52 +02:00
|
|
|
const DynamicPaintSurface *surface, const int index, const DynamicPaintBrushSettings *brush,
|
|
|
|
|
float paint[3], float influence, float depth, float vel_factor, const float timescale)
|
2011-07-08 11:03:37 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
float strength;
|
|
|
|
|
|
|
|
|
|
/* apply influence scale */
|
|
|
|
|
influence *= surface->influence_scale;
|
|
|
|
|
depth *= surface->influence_scale;
|
|
|
|
|
|
|
|
|
|
strength = influence * brush->alpha;
|
|
|
|
|
CLAMP(strength, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
/* Sample velocity colorband if required */
|
|
|
|
|
if (brush->flags & (MOD_DPAINT_VELOCITY_ALPHA | MOD_DPAINT_VELOCITY_COLOR | MOD_DPAINT_VELOCITY_DEPTH)) {
|
|
|
|
|
float coba_res[4];
|
|
|
|
|
vel_factor /= brush->max_velocity;
|
|
|
|
|
CLAMP(vel_factor, 0.0f, 1.0f);
|
|
|
|
|
|
2017-12-07 15:52:59 +11:00
|
|
|
if (BKE_colorband_evaluate(brush->vel_ramp, vel_factor, coba_res)) {
|
2012-05-12 16:11:34 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_VELOCITY_COLOR) {
|
2016-05-12 12:08:03 +02:00
|
|
|
copy_v3_v3(paint, coba_res);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_VELOCITY_ALPHA)
|
|
|
|
|
strength *= coba_res[3];
|
|
|
|
|
if (brush->flags & MOD_DPAINT_VELOCITY_DEPTH)
|
|
|
|
|
depth *= coba_res[3];
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
2011-07-08 11:03:37 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
/* mix paint surface */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
float paintWetness = brush->wetness * strength;
|
|
|
|
|
float paintAlpha = strength;
|
2011-07-08 11:03:37 +00:00
|
|
|
|
2016-05-20 23:16:52 +02:00
|
|
|
dynamicPaint_mixPaintColors(surface, index, brush->flags, paint, paintAlpha, paintWetness, timescale);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
/* displace surface */
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_DISPLACE) {
|
|
|
|
|
float *value = (float *)sData->type_data;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL)
|
|
|
|
|
depth = value[index] + depth;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
if (surface->depth_clamp) {
|
|
|
|
|
CLAMP(depth, 0.0f - surface->depth_clamp, surface->depth_clamp);
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_ERASE) {
|
|
|
|
|
value[index] *= (1.0f - strength);
|
2016-05-12 12:08:03 +02:00
|
|
|
CLAMP_MIN(value[index], 0.0f);
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
else {
|
2016-05-12 12:08:03 +02:00
|
|
|
CLAMP_MIN(value[index], depth);
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
/* vertex weight group surface */
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
|
|
|
|
float *value = (float *)sData->type_data;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_ERASE) {
|
|
|
|
|
value[index] *= (1.0f - strength);
|
2016-05-12 12:08:03 +02:00
|
|
|
CLAMP_MIN(value[index], 0.0f);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2016-05-12 12:08:03 +02:00
|
|
|
CLAMP_MIN(value[index], strength);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* wave surface */
|
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
|
|
|
|
|
if (brush->wave_clamp) {
|
|
|
|
|
CLAMP(depth, 0.0f - brush->wave_clamp, brush->wave_clamp);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_mixWaveHeight(&((PaintWavePoint *)sData->type_data)[index], brush, 0.0f - depth);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* doing velocity based painting */
|
|
|
|
|
if (sData->bData->brush_velocity) {
|
|
|
|
|
sData->bData->brush_velocity[index * 4 + 3] *= influence;
|
|
|
|
|
}
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* checks whether surface and brush bounds intersect depending on brush type */
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
|
|
|
|
if (brush->collision == MOD_DPAINT_COL_VOLUME)
|
|
|
|
|
return boundsIntersect(b1, b2);
|
|
|
|
|
else if (brush->collision == MOD_DPAINT_COL_DIST || brush->collision == MOD_DPAINT_COL_VOLDIST)
|
2012-01-16 17:18:07 +00:00
|
|
|
return boundsIntersectDist(b1, b2, brush_radius);
|
2016-05-12 12:08:03 +02:00
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* calculate velocity for mesh vertices */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintBrushVelocityData {
|
|
|
|
|
Vec3f *brush_vel;
|
|
|
|
|
|
|
|
|
|
const MVert *mvert_p;
|
|
|
|
|
const MVert *mvert_c;
|
|
|
|
|
|
|
|
|
|
float (*obmat)[4];
|
|
|
|
|
float (*prev_obmat)[4];
|
|
|
|
|
|
|
|
|
|
const float timescale;
|
|
|
|
|
} DynamicPaintBrushVelocityData;
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_brush_velocity_compute_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int i,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintBrushVelocityData *data = userdata;
|
|
|
|
|
|
|
|
|
|
Vec3f *brush_vel = data->brush_vel;
|
|
|
|
|
|
|
|
|
|
const MVert *mvert_p = data->mvert_p;
|
|
|
|
|
const MVert *mvert_c = data->mvert_c;
|
|
|
|
|
|
|
|
|
|
float (*obmat)[4] = data->obmat;
|
|
|
|
|
float (*prev_obmat)[4] = data->prev_obmat;
|
|
|
|
|
|
|
|
|
|
const float timescale = data->timescale;
|
|
|
|
|
|
|
|
|
|
float p1[3], p2[3];
|
|
|
|
|
|
|
|
|
|
copy_v3_v3(p1, mvert_p[i].co);
|
|
|
|
|
mul_m4_v3(prev_obmat, p1);
|
|
|
|
|
|
|
|
|
|
copy_v3_v3(p2, mvert_c[i].co);
|
|
|
|
|
mul_m4_v3(obmat, p2);
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(brush_vel[i].v, p2, p1);
|
|
|
|
|
mul_v3_fl(brush_vel[i].v, 1.0f / timescale);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static void dynamicPaint_brushMeshCalculateVelocity(
|
2018-06-11 14:39:38 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene,
|
2017-08-16 12:45:11 +10:00
|
|
|
Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale)
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
|
|
|
|
float prev_obmat[4][4];
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh_p, *mesh_c;
|
2011-08-03 18:31:48 +00:00
|
|
|
MVert *mvert_p, *mvert_c;
|
|
|
|
|
int numOfVerts_p, numOfVerts_c;
|
|
|
|
|
|
|
|
|
|
float cur_sfra = scene->r.subframe;
|
|
|
|
|
int cur_fra = scene->r.cfra;
|
|
|
|
|
float prev_sfra = cur_sfra - timescale;
|
|
|
|
|
int prev_fra = cur_fra;
|
|
|
|
|
|
|
|
|
|
if (prev_sfra < 0.0f) {
|
|
|
|
|
prev_sfra += 1.0f;
|
|
|
|
|
prev_fra = cur_fra - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* previous frame mesh */
|
2011-08-03 18:31:48 +00:00
|
|
|
scene->r.cfra = prev_fra;
|
|
|
|
|
scene->r.subframe = prev_sfra;
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_object_modifier_update_subframe(
|
2018-04-06 12:07:27 +02:00
|
|
|
depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2018-09-24 16:32:29 +02:00
|
|
|
mesh_p = BKE_mesh_copy_for_eval(brush->mesh, false);
|
|
|
|
|
numOfVerts_p = mesh_p->totvert;
|
|
|
|
|
mvert_p = mesh_p->mvert;
|
2011-08-03 18:31:48 +00:00
|
|
|
copy_m4_m4(prev_obmat, ob->obmat);
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* current frame mesh */
|
2011-08-03 18:31:48 +00:00
|
|
|
scene->r.cfra = cur_fra;
|
|
|
|
|
scene->r.subframe = cur_sfra;
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_object_modifier_update_subframe(
|
2018-04-06 12:07:27 +02:00
|
|
|
depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2018-09-24 16:32:29 +02:00
|
|
|
mesh_c = brush->mesh;
|
|
|
|
|
numOfVerts_c = mesh_c->totvert;
|
|
|
|
|
mvert_c = mesh_c->mvert;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
(*brushVel) = (struct Vec3f *) MEM_mallocN(numOfVerts_c * sizeof(Vec3f), "Dynamic Paint brush velocity");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!(*brushVel))
|
|
|
|
|
return;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* if mesh is constructive -> num of verts has changed, only use current frame derived mesh */
|
2011-08-03 18:31:48 +00:00
|
|
|
if (numOfVerts_p != numOfVerts_c)
|
|
|
|
|
mvert_p = mvert_c;
|
|
|
|
|
|
|
|
|
|
/* calculate speed */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintBrushVelocityData data = {
|
|
|
|
|
.brush_vel = *brushVel,
|
|
|
|
|
.mvert_p = mvert_p, .mvert_c = mvert_c, .obmat = ob->obmat, .prev_obmat = prev_obmat,
|
|
|
|
|
.timescale = timescale,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (numOfVerts_c > 10000);
|
|
|
|
|
BLI_task_parallel_range(0, numOfVerts_c,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_brush_velocity_compute_cb,
|
|
|
|
|
&settings);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
BKE_id_free(NULL, mesh_p);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate velocity for object center point */
|
2018-05-31 12:27:47 +02:00
|
|
|
static void dynamicPaint_brushObjectCalculateVelocity(
|
2018-06-11 14:39:38 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
|
|
|
|
float prev_obmat[4][4];
|
|
|
|
|
float cur_loc[3] = {0.0f}, prev_loc[3] = {0.0f};
|
|
|
|
|
|
|
|
|
|
float cur_sfra = scene->r.subframe;
|
|
|
|
|
int cur_fra = scene->r.cfra;
|
|
|
|
|
float prev_sfra = cur_sfra - timescale;
|
|
|
|
|
int prev_fra = cur_fra;
|
|
|
|
|
|
|
|
|
|
if (prev_sfra < 0.0f) {
|
|
|
|
|
prev_sfra += 1.0f;
|
|
|
|
|
prev_fra = cur_fra - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* previous frame mesh */
|
2011-08-03 18:31:48 +00:00
|
|
|
scene->r.cfra = prev_fra;
|
|
|
|
|
scene->r.subframe = prev_sfra;
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_object_modifier_update_subframe(
|
2018-04-06 12:07:27 +02:00
|
|
|
depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2011-08-03 18:31:48 +00:00
|
|
|
copy_m4_m4(prev_obmat, ob->obmat);
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
/* current frame mesh */
|
2011-08-03 18:31:48 +00:00
|
|
|
scene->r.cfra = cur_fra;
|
|
|
|
|
scene->r.subframe = cur_sfra;
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_object_modifier_update_subframe(
|
2018-04-06 12:07:27 +02:00
|
|
|
depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* calculate speed */
|
|
|
|
|
mul_m4_v3(prev_obmat, prev_loc);
|
|
|
|
|
mul_m4_v3(ob->obmat, cur_loc);
|
|
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
sub_v3_v3v3(brushVel->v, cur_loc, prev_loc);
|
2012-05-12 16:11:34 +00:00
|
|
|
mul_v3_fl(brushVel->v, 1.0f / timescale);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintPaintData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
const DynamicPaintBrushSettings *brush;
|
|
|
|
|
Object *brushOb;
|
|
|
|
|
const Scene *scene;
|
|
|
|
|
const float timescale;
|
|
|
|
|
const int c_index;
|
|
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const MVert *mvert;
|
|
|
|
|
const MLoop *mloop;
|
|
|
|
|
const MLoopTri *mlooptri;
|
|
|
|
|
const float brush_radius;
|
|
|
|
|
const float *avg_brushNor;
|
|
|
|
|
const Vec3f *brushVelocity;
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
const ParticleSystem *psys;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float solidradius;
|
|
|
|
|
|
|
|
|
|
void *treeData;
|
|
|
|
|
|
|
|
|
|
float *pointCoord;
|
|
|
|
|
} DynamicPaintPaintData;
|
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Paint a brush object mesh to the surface
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
static void dynamic_paint_paint_mesh_cell_point_cb_ex(
|
2018-01-10 12:49:51 +01:00
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int id,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintPaintData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const PaintBakeData *bData = sData->bData;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintBrushSettings *brush = data->brush;
|
|
|
|
|
|
|
|
|
|
const float timescale = data->timescale;
|
|
|
|
|
const int c_index = data->c_index;
|
|
|
|
|
|
|
|
|
|
const MVert *mvert = data->mvert;
|
|
|
|
|
const MLoop *mloop = data->mloop;
|
|
|
|
|
const MLoopTri *mlooptri = data->mlooptri;
|
|
|
|
|
const float brush_radius = data->brush_radius;
|
|
|
|
|
const float *avg_brushNor = data->avg_brushNor;
|
|
|
|
|
const Vec3f *brushVelocity = data->brushVelocity;
|
|
|
|
|
|
|
|
|
|
BVHTreeFromMesh *treeData = data->treeData;
|
|
|
|
|
|
|
|
|
|
const int index = grid->t_index[grid->s_pos[c_index] + id];
|
|
|
|
|
const int samples = bData->s_num[index];
|
|
|
|
|
int ss;
|
|
|
|
|
float total_sample = (float)samples;
|
|
|
|
|
float brushStrength = 0.0f; /* brush influence factor */
|
|
|
|
|
float depth = 0.0f; /* brush intersection depth */
|
|
|
|
|
float velocity_val = 0.0f;
|
|
|
|
|
|
|
|
|
|
float paintColor[3] = {0.0f};
|
|
|
|
|
int numOfHits = 0;
|
|
|
|
|
|
|
|
|
|
/* for image sequence anti-aliasing, use gaussian factors */
|
|
|
|
|
if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
|
|
|
|
|
total_sample = gaussianTotal;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Supersampling */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (ss = 0; ss < samples; ss++) {
|
|
|
|
|
float ray_start[3], ray_dir[3];
|
|
|
|
|
float sample_factor = 0.0f;
|
|
|
|
|
float sampleStrength = 0.0f;
|
|
|
|
|
BVHTreeRayHit hit;
|
|
|
|
|
BVHTreeNearest nearest;
|
|
|
|
|
short hit_found = 0;
|
|
|
|
|
|
|
|
|
|
/* volume sample */
|
|
|
|
|
float volume_factor = 0.0f;
|
|
|
|
|
/* proximity sample */
|
|
|
|
|
float proximity_factor = 0.0f;
|
|
|
|
|
float prox_colorband[4] = {0.0f};
|
|
|
|
|
const bool inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX &&
|
|
|
|
|
brush->collision == MOD_DPAINT_COL_VOLDIST);
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* hit data */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float hitCoord[3];
|
|
|
|
|
int hitTri = -1;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Supersampling factor */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (samples > 1 && surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
|
|
|
|
|
sample_factor = gaussianFactors[ss];
|
|
|
|
|
else
|
|
|
|
|
sample_factor = 1.0f;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Get current sample position in world coordinates */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
copy_v3_v3(ray_start, bData->realCoord[bData->s_pos[index] + ss].v);
|
|
|
|
|
copy_v3_v3(ray_dir, bData->bNormal[index].invNorm);
|
|
|
|
|
|
|
|
|
|
/* a simple hack to minimize chance of ray leaks at identical ray <-> edge locations */
|
|
|
|
|
add_v3_fl(ray_start, 0.001f);
|
|
|
|
|
|
|
|
|
|
hit.index = -1;
|
|
|
|
|
hit.dist = BVH_RAYCAST_DIST_MAX;
|
|
|
|
|
nearest.index = -1;
|
|
|
|
|
nearest.dist_sq = brush_radius * brush_radius; /* find_nearest uses squared distance */
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Check volume collision */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (ELEM(brush->collision, MOD_DPAINT_COL_VOLUME, MOD_DPAINT_COL_VOLDIST)) {
|
|
|
|
|
BLI_bvhtree_ray_cast(treeData->tree, ray_start, ray_dir, 0.0f, &hit, mesh_tris_spherecast_dp, treeData);
|
|
|
|
|
if (hit.index != -1) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* We hit a triangle, now check if collision point normal is facing the point */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* For optimization sake, hit point normal isn't calculated in ray cast loop */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int vtri[3] = {
|
|
|
|
|
mloop[mlooptri[hit.index].tri[0]].v,
|
|
|
|
|
mloop[mlooptri[hit.index].tri[1]].v,
|
|
|
|
|
mloop[mlooptri[hit.index].tri[2]].v,
|
|
|
|
|
};
|
|
|
|
|
float dot;
|
|
|
|
|
|
|
|
|
|
normal_tri_v3(hit.no, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co);
|
|
|
|
|
dot = dot_v3v3(ray_dir, hit.no);
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If ray and hit face normal are facing same direction
|
|
|
|
|
* hit point is inside a closed mesh. */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (dot >= 0.0f) {
|
|
|
|
|
const float dist = hit.dist;
|
|
|
|
|
const int f_index = hit.index;
|
|
|
|
|
|
|
|
|
|
/* Also cast a ray in opposite direction to make sure
|
|
|
|
|
* point is at least surrounded by two brush faces */
|
|
|
|
|
negate_v3(ray_dir);
|
|
|
|
|
hit.index = -1;
|
|
|
|
|
hit.dist = BVH_RAYCAST_DIST_MAX;
|
|
|
|
|
|
|
|
|
|
BLI_bvhtree_ray_cast(
|
|
|
|
|
treeData->tree, ray_start, ray_dir, 0.0f, &hit, mesh_tris_spherecast_dp, treeData);
|
|
|
|
|
|
|
|
|
|
if (hit.index != -1) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Add factor on supersample filter */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
volume_factor = 1.0f;
|
|
|
|
|
hit_found = HIT_VOLUME;
|
|
|
|
|
|
|
|
|
|
/* Mark hit info */
|
|
|
|
|
madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit.dist); /* Calculate final hit coordinates */
|
|
|
|
|
depth += dist * sample_factor;
|
|
|
|
|
hitTri = f_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Check proximity collision */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (ELEM(brush->collision, MOD_DPAINT_COL_DIST, MOD_DPAINT_COL_VOLDIST) &&
|
|
|
|
|
(!hit_found || (brush->flags & MOD_DPAINT_INVERSE_PROX)))
|
|
|
|
|
{
|
|
|
|
|
float proxDist = -1.0f;
|
|
|
|
|
float hitCo[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
int tri = 0;
|
|
|
|
|
|
|
|
|
|
/* if inverse prox and no hit found, skip this sample */
|
|
|
|
|
if (inner_proximity && !hit_found)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If pure distance proximity, find the nearest point on the mesh */
|
|
|
|
|
if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) {
|
|
|
|
|
BLI_bvhtree_find_nearest(treeData->tree, ray_start, &nearest, mesh_tris_nearest_point_dp, treeData);
|
|
|
|
|
if (nearest.index != -1) {
|
|
|
|
|
proxDist = sqrtf(nearest.dist_sq);
|
|
|
|
|
copy_v3_v3(hitCo, nearest.co);
|
|
|
|
|
tri = nearest.index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { /* else cast a ray in defined projection direction */
|
|
|
|
|
float proj_ray[3] = {0.0f};
|
|
|
|
|
|
|
|
|
|
if (brush->ray_dir == MOD_DPAINT_RAY_CANVAS) {
|
|
|
|
|
copy_v3_v3(proj_ray, bData->bNormal[index].invNorm);
|
|
|
|
|
negate_v3(proj_ray);
|
|
|
|
|
}
|
|
|
|
|
else if (brush->ray_dir == MOD_DPAINT_RAY_BRUSH_AVG) {
|
|
|
|
|
copy_v3_v3(proj_ray, avg_brushNor);
|
|
|
|
|
}
|
|
|
|
|
else { /* MOD_DPAINT_RAY_ZPLUS */
|
|
|
|
|
proj_ray[2] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
hit.index = -1;
|
|
|
|
|
hit.dist = brush_radius;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Do a face normal directional raycast, and use that distance */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
BLI_bvhtree_ray_cast(
|
|
|
|
|
treeData->tree, ray_start, proj_ray, 0.0f, &hit, mesh_tris_spherecast_dp, treeData);
|
|
|
|
|
if (hit.index != -1) {
|
|
|
|
|
proxDist = hit.dist;
|
|
|
|
|
madd_v3_v3v3fl(hitCo, ray_start, proj_ray, hit.dist); /* Calculate final hit coordinates */
|
|
|
|
|
tri = hit.index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If a hit was found, calculate required values */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (proxDist >= 0.0f && proxDist <= brush_radius) {
|
|
|
|
|
proximity_factor = proxDist / brush_radius;
|
|
|
|
|
CLAMP(proximity_factor, 0.0f, 1.0f);
|
|
|
|
|
if (!inner_proximity)
|
|
|
|
|
proximity_factor = 1.0f - proximity_factor;
|
|
|
|
|
|
|
|
|
|
hit_found = HIT_PROXIMITY;
|
|
|
|
|
|
|
|
|
|
/* if no volume hit, use prox point face info */
|
|
|
|
|
if (hitTri == -1) {
|
|
|
|
|
copy_v3_v3(hitCoord, hitCo);
|
|
|
|
|
hitTri = tri;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* mix final sample strength depending on brush settings */
|
|
|
|
|
if (hit_found) {
|
|
|
|
|
/* if "negate volume" enabled, negate all factors within volume*/
|
|
|
|
|
if (brush->collision == MOD_DPAINT_COL_VOLDIST &&
|
|
|
|
|
brush->flags & MOD_DPAINT_NEGATE_VOLUME)
|
|
|
|
|
{
|
|
|
|
|
volume_factor = 1.0f - volume_factor;
|
|
|
|
|
if (inner_proximity)
|
|
|
|
|
proximity_factor = 1.0f - proximity_factor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* apply final sample depending on final hit type */
|
|
|
|
|
if (hit_found == HIT_VOLUME) {
|
|
|
|
|
sampleStrength = volume_factor;
|
|
|
|
|
}
|
|
|
|
|
else if (hit_found == HIT_PROXIMITY) {
|
|
|
|
|
/* apply falloff curve to the proximity_factor */
|
|
|
|
|
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP &&
|
2017-12-07 15:52:59 +11:00
|
|
|
BKE_colorband_evaluate(brush->paint_ramp, (1.0f - proximity_factor), prox_colorband))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
proximity_factor = prox_colorband[3];
|
|
|
|
|
}
|
|
|
|
|
else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) {
|
|
|
|
|
proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f;
|
|
|
|
|
}
|
|
|
|
|
/* apply sample */
|
|
|
|
|
sampleStrength = proximity_factor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sampleStrength *= sample_factor;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* velocity brush, only do on main sample */
|
|
|
|
|
if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss == 0 && brushVelocity) {
|
2017-01-11 15:15:54 -02:00
|
|
|
float weights[3];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float brushPointVelocity[3];
|
|
|
|
|
float velocity[3];
|
|
|
|
|
|
|
|
|
|
const int v1 = mloop[mlooptri[hitTri].tri[0]].v;
|
|
|
|
|
const int v2 = mloop[mlooptri[hitTri].tri[1]].v;
|
|
|
|
|
const int v3 = mloop[mlooptri[hitTri].tri[2]].v;
|
|
|
|
|
|
|
|
|
|
/* calculate barycentric weights for hit point */
|
2017-01-11 15:15:54 -02:00
|
|
|
interp_weights_tri_v3(weights, mvert[v1].co, mvert[v2].co, mvert[v3].co, hitCoord);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* simple check based on brush surface velocity,
|
2018-09-02 18:28:27 +10:00
|
|
|
* todo: perhaps implement something that handles volume movement as well. */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* interpolate vertex speed vectors to get hit point velocity */
|
|
|
|
|
interp_v3_v3v3v3(brushPointVelocity,
|
|
|
|
|
brushVelocity[v1].v,
|
|
|
|
|
brushVelocity[v2].v,
|
|
|
|
|
brushVelocity[v3].v, weights);
|
|
|
|
|
|
|
|
|
|
/* substract canvas point velocity */
|
|
|
|
|
if (bData->velocity) {
|
|
|
|
|
sub_v3_v3v3(velocity, brushPointVelocity, bData->velocity[index].v);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v3_v3(velocity, brushPointVelocity);
|
|
|
|
|
}
|
|
|
|
|
velocity_val = normalize_v3(velocity);
|
|
|
|
|
|
|
|
|
|
/* if brush has smudge enabled store brush velocity */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT &&
|
|
|
|
|
brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)
|
|
|
|
|
{
|
|
|
|
|
copy_v3_v3(&bData->brush_velocity[index * 4], velocity);
|
|
|
|
|
bData->brush_velocity[index * 4 + 3] = velocity_val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Process hit color and alpha
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
*/
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
float sampleColor[3];
|
|
|
|
|
float alpha_factor = 1.0f;
|
|
|
|
|
|
|
|
|
|
sampleColor[0] = brush->r;
|
|
|
|
|
sampleColor[1] = brush->g;
|
|
|
|
|
sampleColor[2] = brush->b;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Sample proximity colorband if required */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if ((hit_found == HIT_PROXIMITY) &&
|
|
|
|
|
(brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP))
|
|
|
|
|
{
|
|
|
|
|
if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) {
|
|
|
|
|
sampleColor[0] = prox_colorband[0];
|
|
|
|
|
sampleColor[1] = prox_colorband[1];
|
|
|
|
|
sampleColor[2] = prox_colorband[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add AA sample */
|
|
|
|
|
paintColor[0] += sampleColor[0];
|
|
|
|
|
paintColor[1] += sampleColor[1];
|
|
|
|
|
paintColor[2] += sampleColor[2];
|
|
|
|
|
sampleStrength *= alpha_factor;
|
|
|
|
|
numOfHits++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* apply sample strength */
|
|
|
|
|
brushStrength += sampleStrength;
|
|
|
|
|
} // end supersampling
|
|
|
|
|
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* if any sample was inside paint range */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (brushStrength > 0.0f || depth > 0.0f) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* apply supersampling results */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (samples > 1) {
|
|
|
|
|
brushStrength /= total_sample;
|
|
|
|
|
}
|
|
|
|
|
CLAMP(brushStrength, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Get final pixel color and alpha */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
paintColor[0] /= numOfHits;
|
|
|
|
|
paintColor[1] /= numOfHits;
|
|
|
|
|
paintColor[2] /= numOfHits;
|
|
|
|
|
}
|
|
|
|
|
/* get final object space depth */
|
|
|
|
|
else if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
|
|
|
|
depth /= bData->bNormal[index].normal_scale * total_sample;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dynamicPaint_updatePointData(surface, index, brush, paintColor, brushStrength, depth, velocity_val, timescale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-11 14:39:38 +02:00
|
|
|
static int dynamicPaint_paintMesh(Depsgraph *depsgraph, DynamicPaintSurface *surface,
|
2011-11-10 12:28:26 +00:00
|
|
|
DynamicPaintBrushSettings *brush,
|
|
|
|
|
Object *brushOb,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
float timescale)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = NULL;
|
2011-08-03 18:31:48 +00:00
|
|
|
Vec3f *brushVelocity = NULL;
|
2011-05-24 07:08:58 +00:00
|
|
|
MVert *mvert = NULL;
|
2015-07-27 15:52:54 +10:00
|
|
|
const MLoopTri *mlooptri = NULL;
|
|
|
|
|
const MLoop *mloop = NULL;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_USES_VELOCITY)
|
2018-04-06 12:07:27 +02:00
|
|
|
dynamicPaint_brushMeshCalculateVelocity(depsgraph, scene, brushOb, brush, &brushVelocity, timescale);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
if (!brush->mesh)
|
2016-05-12 12:08:03 +02:00
|
|
|
return 0;
|
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2013-08-07 03:36:05 +00:00
|
|
|
BVHTreeFromMesh treeData = {NULL};
|
2011-09-10 08:55:44 +00:00
|
|
|
float avg_brushNor[3] = {0.0f};
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float brush_radius = brush->paint_distance * surface->radius_scale;
|
2011-05-24 07:08:58 +00:00
|
|
|
int numOfVerts;
|
|
|
|
|
int ii;
|
2016-07-04 17:30:05 +02:00
|
|
|
Bounds3D mesh_bb = {{0}};
|
2011-09-05 16:04:15 +00:00
|
|
|
VolumeGrid *grid = bData->grid;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
mesh = BKE_mesh_copy_for_eval(brush->mesh, false);
|
|
|
|
|
mvert = mesh->mvert;
|
|
|
|
|
mlooptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
|
|
|
|
mloop = mesh->mloop;
|
|
|
|
|
numOfVerts = mesh->totvert;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Transform collider vertices to global space
|
|
|
|
|
* (Faster than transforming per surface point
|
|
|
|
|
* coordinates and normals to object space) */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (ii = 0; ii < numOfVerts; ii++) {
|
2011-06-16 10:41:00 +00:00
|
|
|
mul_m4_v3(brushOb->obmat, mvert[ii].co);
|
2011-09-05 16:04:15 +00:00
|
|
|
boundInsert(&mesh_bb, mvert[ii].co);
|
2011-09-10 08:55:44 +00:00
|
|
|
|
2012-01-24 17:28:50 +00:00
|
|
|
/* for proximity project calculate average normal */
|
|
|
|
|
if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) {
|
2011-09-10 08:55:44 +00:00
|
|
|
float nor[3];
|
|
|
|
|
normal_short_to_float_v3(nor, mvert[ii].no);
|
|
|
|
|
mul_mat3_m4_v3(brushOb->obmat, nor);
|
|
|
|
|
normalize_v3(nor);
|
|
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
add_v3_v3(avg_brushNor, nor);
|
2011-09-10 08:55:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-24 17:28:50 +00:00
|
|
|
if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) {
|
2012-05-12 16:11:34 +00:00
|
|
|
mul_v3_fl(avg_brushNor, 1.0f / (float)numOfVerts);
|
2011-09-10 08:55:44 +00:00
|
|
|
/* instead of null vector use positive z */
|
2015-08-21 17:05:48 +10:00
|
|
|
if (UNLIKELY(normalize_v3(avg_brushNor) == 0.0f)) {
|
2011-09-10 08:55:44 +00:00
|
|
|
avg_brushNor[2] = 1.0f;
|
2015-08-21 17:05:48 +10:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
/* check bounding box collision */
|
2012-05-12 16:11:34 +00:00
|
|
|
if (grid && meshBrush_boundsIntersect(&grid->grid_bounds, &mesh_bb, brush, brush_radius)) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Build a bvh tree from transformed vertices */
|
2018-09-24 16:32:29 +02:00
|
|
|
if (BKE_bvhtree_from_mesh_get(&treeData, mesh, BVHTREE_FROM_LOOPTRI, 4)) {
|
2012-05-12 16:11:34 +00:00
|
|
|
int c_index;
|
|
|
|
|
int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2];
|
|
|
|
|
|
|
|
|
|
/* loop through space partitioning grid */
|
|
|
|
|
for (c_index = 0; c_index < total_cells; c_index++) {
|
|
|
|
|
/* check grid cell bounding box */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!grid->s_num[c_index] ||
|
|
|
|
|
!meshBrush_boundsIntersect(&grid->bounds[c_index], &mesh_bb, brush, brush_radius))
|
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
continue;
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2011-07-08 11:03:37 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
/* loop through cell points and process brush */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintPaintData data = {
|
2016-06-19 06:25:54 +10:00
|
|
|
.surface = surface,
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
.brush = brush, .brushOb = brushOb,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
.scene = scene, .timescale = timescale, .c_index = c_index,
|
2018-09-24 16:32:29 +02:00
|
|
|
.mesh = mesh, .mvert = mvert, .mloop = mloop, .mlooptri = mlooptri,
|
2016-06-19 06:25:54 +10:00
|
|
|
.brush_radius = brush_radius, .avg_brushNor = avg_brushNor, .brushVelocity = brushVelocity,
|
2019-01-07 00:06:58 +11:00
|
|
|
.treeData = &treeData,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (grid->s_num[c_index] > 250);
|
|
|
|
|
BLI_task_parallel_range(0, grid->s_num[c_index],
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_paint_mesh_cell_point_cb_ex,
|
|
|
|
|
&settings);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
/* free bvh tree */
|
2011-05-24 07:08:58 +00:00
|
|
|
free_bvhtree_from_mesh(&treeData);
|
2018-09-24 16:32:29 +02:00
|
|
|
BKE_id_free(NULL, mesh);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* free brush velocity data */
|
|
|
|
|
if (brushVelocity)
|
|
|
|
|
MEM_freeN(brushVelocity);
|
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Paint a particle system to the surface
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
static void dynamic_paint_paint_particle_cell_point_cb_ex(
|
2018-01-10 12:49:51 +01:00
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int id,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
const DynamicPaintPaintData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const PaintBakeData *bData = sData->bData;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintBrushSettings *brush = data->brush;
|
|
|
|
|
|
|
|
|
|
const ParticleSystem *psys = data->psys;
|
|
|
|
|
|
|
|
|
|
const float timescale = data->timescale;
|
|
|
|
|
const int c_index = data->c_index;
|
|
|
|
|
|
|
|
|
|
KDTree *tree = data->treeData;
|
|
|
|
|
|
|
|
|
|
const float solidradius = data->solidradius;
|
|
|
|
|
const float smooth = brush->particle_smooth * surface->radius_scale;
|
|
|
|
|
const float range = solidradius + smooth;
|
|
|
|
|
const float particle_timestep = 0.04f * psys->part->timetweak;
|
|
|
|
|
|
|
|
|
|
const int index = grid->t_index[grid->s_pos[c_index] + id];
|
|
|
|
|
float disp_intersect = 0.0f;
|
|
|
|
|
float radius = 0.0f;
|
|
|
|
|
float strength = 0.0f;
|
|
|
|
|
int part_index = -1;
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* With predefined radius, there is no variation between particles.
|
|
|
|
|
* It's enough to just find the nearest one.
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
KDTreeNearest nearest;
|
|
|
|
|
float smooth_range, part_solidradius;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Find nearest particle and get distance to it */
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_kdtree_find_nearest(tree, bData->realCoord[bData->s_pos[index]].v, &nearest);
|
|
|
|
|
/* if outside maximum range, no other particle can influence either */
|
|
|
|
|
if (nearest.dist > range)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (brush->flags & MOD_DPAINT_PART_RAD) {
|
|
|
|
|
/* use particles individual size */
|
|
|
|
|
ParticleData *pa = psys->particles + nearest.index;
|
|
|
|
|
part_solidradius = pa->size;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
part_solidradius = solidradius;
|
|
|
|
|
}
|
|
|
|
|
radius = part_solidradius + smooth;
|
|
|
|
|
if (nearest.dist < radius) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* distances inside solid radius has maximum influence -> dist = 0 */
|
2016-12-28 17:30:58 +01:00
|
|
|
smooth_range = max_ff(0.0f, (nearest.dist - part_solidradius));
|
2018-11-14 12:53:15 +11:00
|
|
|
/* do smoothness if enabled */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (smooth)
|
|
|
|
|
smooth_range /= smooth;
|
|
|
|
|
|
|
|
|
|
strength = 1.0f - smooth_range;
|
|
|
|
|
disp_intersect = radius - nearest.dist;
|
|
|
|
|
part_index = nearest.index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If using random per particle radius and closest particle didn't give max influence */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (brush->flags & MOD_DPAINT_PART_RAD && strength < 1.0f && psys->part->randsize > 0.0f) {
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* If we use per particle radius, we have to sample all particles
|
|
|
|
|
* within max radius range
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
KDTreeNearest *nearest;
|
|
|
|
|
|
|
|
|
|
float smooth_range = smooth * (1.0f - strength), dist;
|
|
|
|
|
/* calculate max range that can have particles with higher influence than the nearest one */
|
|
|
|
|
const float max_range = smooth - strength * smooth + solidradius;
|
|
|
|
|
/* Make gcc happy! */
|
|
|
|
|
dist = max_range;
|
|
|
|
|
|
|
|
|
|
const int particles = BLI_kdtree_range_search(
|
|
|
|
|
tree, bData->realCoord[bData->s_pos[index]].v, &nearest, max_range);
|
|
|
|
|
|
|
|
|
|
/* Find particle that produces highest influence */
|
|
|
|
|
for (int n = 0; n < particles; n++) {
|
|
|
|
|
ParticleData *pa = &psys->particles[nearest[n].index];
|
|
|
|
|
|
|
|
|
|
/* skip if out of range */
|
|
|
|
|
if (nearest[n].dist > (pa->size + smooth))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* update hit data */
|
|
|
|
|
const float s_range = nearest[n].dist - pa->size;
|
|
|
|
|
/* skip if higher influence is already found */
|
|
|
|
|
if (smooth_range < s_range)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* update hit data */
|
|
|
|
|
smooth_range = s_range;
|
|
|
|
|
dist = nearest[n].dist;
|
|
|
|
|
part_index = nearest[n].index;
|
|
|
|
|
|
|
|
|
|
/* If inside solid range and no disp depth required, no need to seek further */
|
|
|
|
|
if ((s_range < 0.0f) && !ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nearest)
|
|
|
|
|
MEM_freeN(nearest);
|
|
|
|
|
|
|
|
|
|
/* now calculate influence for this particle */
|
|
|
|
|
const float rad = radius + smooth;
|
|
|
|
|
if ((rad - dist) > disp_intersect) {
|
|
|
|
|
disp_intersect = radius - dist;
|
|
|
|
|
radius = rad;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* do smoothness if enabled */
|
2016-12-28 17:30:58 +01:00
|
|
|
CLAMP_MIN(smooth_range, 0.0f);
|
|
|
|
|
if (smooth)
|
|
|
|
|
smooth_range /= smooth;
|
|
|
|
|
|
|
|
|
|
const float str = 1.0f - smooth_range;
|
2018-11-14 12:53:15 +11:00
|
|
|
/* if influence is greater, use this one */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (str > strength)
|
|
|
|
|
strength = str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strength > 0.001f) {
|
|
|
|
|
float paintColor[4] = {0.0f};
|
|
|
|
|
float depth = 0.0f;
|
|
|
|
|
float velocity_val = 0.0f;
|
|
|
|
|
|
|
|
|
|
/* apply velocity */
|
|
|
|
|
if ((brush->flags & MOD_DPAINT_USES_VELOCITY) && (part_index != -1)) {
|
|
|
|
|
float velocity[3];
|
|
|
|
|
ParticleData *pa = psys->particles + part_index;
|
|
|
|
|
mul_v3_v3fl(velocity, pa->state.vel, particle_timestep);
|
|
|
|
|
|
|
|
|
|
/* substract canvas point velocity */
|
|
|
|
|
if (bData->velocity) {
|
|
|
|
|
sub_v3_v3(velocity, bData->velocity[index].v);
|
|
|
|
|
}
|
|
|
|
|
velocity_val = normalize_v3(velocity);
|
|
|
|
|
|
|
|
|
|
/* store brush velocity for smudge */
|
|
|
|
|
if ((surface->type == MOD_DPAINT_SURFACE_T_PAINT) &&
|
|
|
|
|
(brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity))
|
|
|
|
|
{
|
|
|
|
|
copy_v3_v3(&bData->brush_velocity[index * 4], velocity);
|
|
|
|
|
bData->brush_velocity[index * 4 + 3] = velocity_val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
copy_v3_v3(paintColor, &brush->r);
|
|
|
|
|
}
|
|
|
|
|
else if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* get displace depth */
|
2016-12-28 17:30:58 +01:00
|
|
|
disp_intersect = (1.0f - sqrtf(disp_intersect / radius)) * radius;
|
|
|
|
|
depth = max_ff(0.0f, (radius - disp_intersect) / bData->bNormal[index].normal_scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int dynamicPaint_paintParticles(DynamicPaintSurface *surface,
|
|
|
|
|
ParticleSystem *psys,
|
|
|
|
|
DynamicPaintBrushSettings *brush,
|
|
|
|
|
float timescale)
|
|
|
|
|
{
|
|
|
|
|
ParticleSettings *part = psys->part;
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
|
|
|
|
VolumeGrid *grid = bData->grid;
|
|
|
|
|
|
|
|
|
|
KDTree *tree;
|
|
|
|
|
int particlesAdded = 0;
|
|
|
|
|
int invalidParticles = 0;
|
|
|
|
|
int p = 0;
|
|
|
|
|
|
|
|
|
|
const float solidradius = surface->radius_scale *
|
|
|
|
|
((brush->flags & MOD_DPAINT_PART_RAD) ? part->size : brush->particle_radius);
|
|
|
|
|
const float smooth = brush->particle_smooth * surface->radius_scale;
|
|
|
|
|
|
|
|
|
|
const float range = solidradius + smooth;
|
|
|
|
|
|
|
|
|
|
Bounds3D part_bb = {{0}};
|
|
|
|
|
|
|
|
|
|
if (psys->totpart < 1)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Build a kd-tree to optimize distance search
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
tree = BLI_kdtree_new(psys->totpart);
|
|
|
|
|
|
2018-03-23 11:51:19 +01:00
|
|
|
/* loop through particles and insert valid ones to the tree */
|
2016-12-28 17:30:58 +01:00
|
|
|
p = 0;
|
|
|
|
|
for (ParticleData *pa = psys->particles; p < psys->totpart; p++, pa++) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Proceed only if particle is active */
|
2016-12-28 17:30:58 +01:00
|
|
|
if ((pa->alive == PARS_UNBORN && (part->flag & PART_UNBORN) == 0) ||
|
|
|
|
|
(pa->alive == PARS_DEAD && (part->flag & PART_DIED) == 0) ||
|
|
|
|
|
(pa->flag & PARS_UNEXIST))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* for debug purposes check if any NAN particle proceeds
|
|
|
|
|
* For some reason they get past activity check, this should rule most of them out */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (isnan(pa->state.co[0]) || isnan(pa->state.co[1]) || isnan(pa->state.co[2])) {
|
|
|
|
|
invalidParticles++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make sure particle is close enough to canvas */
|
|
|
|
|
if (!boundIntersectPoint(&grid->grid_bounds, pa->state.co, range))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
BLI_kdtree_insert(tree, p, pa->state.co);
|
|
|
|
|
|
|
|
|
|
/* calc particle system bounds */
|
|
|
|
|
boundInsert(&part_bb, pa->state.co);
|
|
|
|
|
|
|
|
|
|
particlesAdded++;
|
|
|
|
|
}
|
|
|
|
|
if (invalidParticles)
|
2019-02-01 12:44:19 +11:00
|
|
|
CLOG_WARN(&LOG, "Invalid particle(s) found!");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* If no suitable particles were found, exit */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (particlesAdded < 1) {
|
|
|
|
|
BLI_kdtree_free(tree);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* begin thread safe malloc */
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_threaded_malloc_begin();
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
/* only continue if particle bb is close enough to canvas bb */
|
|
|
|
|
if (boundsIntersectDist(&grid->grid_bounds, &part_bb, range)) {
|
|
|
|
|
int c_index;
|
|
|
|
|
int total_cells = grid->dim[0] * grid->dim[1] * grid->dim[2];
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* balance tree */
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_kdtree_balance(tree);
|
|
|
|
|
|
|
|
|
|
/* loop through space partitioning grid */
|
|
|
|
|
for (c_index = 0; c_index < total_cells; c_index++) {
|
|
|
|
|
/* check cell bounding box */
|
|
|
|
|
if (!grid->s_num[c_index] ||
|
|
|
|
|
!boundsIntersectDist(&grid->bounds[c_index], &part_bb, range))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* loop through cell points */
|
|
|
|
|
DynamicPaintPaintData data = {
|
|
|
|
|
.surface = surface,
|
|
|
|
|
.brush = brush, .psys = psys,
|
|
|
|
|
.solidradius = solidradius, .timescale = timescale, .c_index = c_index,
|
|
|
|
|
.treeData = tree,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (grid->s_num[c_index] > 250);
|
|
|
|
|
BLI_task_parallel_range(0, grid->s_num[c_index],
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_paint_particle_cell_point_cb_ex,
|
|
|
|
|
&settings);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_threaded_malloc_end();
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_kdtree_free(tree);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* paint a single point of defined proximity radius to the surface */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
static void dynamic_paint_paint_single_point_cb_ex(
|
2018-01-10 12:49:51 +01:00
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2011-07-08 11:03:37 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintPaintData *data = userdata;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const PaintBakeData *bData = sData->bData;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintBrushSettings *brush = data->brush;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float timescale = data->timescale;
|
2011-07-10 16:08:26 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float brush_radius = data->brush_radius;
|
|
|
|
|
const Vec3f *brushVelocity = data->brushVelocity;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
float *pointCoord = data->pointCoord;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float distance = len_v3v3(pointCoord, bData->realCoord[bData->s_pos[index]].v);
|
|
|
|
|
float colorband[4] = {0.0f};
|
|
|
|
|
float strength;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (distance > brush_radius)
|
|
|
|
|
return;
|
2011-07-10 16:08:26 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Smooth range or color ramp */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH ||
|
|
|
|
|
brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)
|
|
|
|
|
{
|
|
|
|
|
strength = 1.0f - distance / brush_radius;
|
|
|
|
|
CLAMP(strength, 0.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strength = 1.0f;
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
2011-08-04 07:09:21 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (strength >= 0.001f) {
|
|
|
|
|
float paintColor[3] = {0.0f};
|
|
|
|
|
float depth = 0.0f;
|
|
|
|
|
float velocity_val = 0.0f;
|
2011-08-04 07:09:21 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* color ramp */
|
|
|
|
|
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP &&
|
2017-12-07 15:52:59 +11:00
|
|
|
BKE_colorband_evaluate(brush->paint_ramp, (1.0f - strength), colorband))
|
2012-05-20 19:49:27 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
strength = colorband[3];
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (brush->flags & MOD_DPAINT_USES_VELOCITY) {
|
|
|
|
|
float velocity[3];
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* substract canvas point velocity */
|
|
|
|
|
if (bData->velocity) {
|
|
|
|
|
sub_v3_v3v3(velocity, brushVelocity->v, bData->velocity[index].v);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
else {
|
|
|
|
|
copy_v3_v3(velocity, brushVelocity->v);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
velocity_val = len_v3(velocity);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* store brush velocity for smudge */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT &&
|
|
|
|
|
brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity)
|
2016-05-14 01:28:21 +10:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
mul_v3_v3fl(&bData->brush_velocity[index * 4], velocity, 1.0f / velocity_val);
|
|
|
|
|
bData->brush_velocity[index * 4 + 3] = velocity_val;
|
2011-06-18 18:41:20 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
2011-07-10 16:08:26 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP &&
|
|
|
|
|
!(brush->flags & MOD_DPAINT_RAMP_ALPHA))
|
2012-05-12 16:11:34 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
paintColor[0] = colorband[0];
|
|
|
|
|
paintColor[1] = colorband[1];
|
|
|
|
|
paintColor[2] = colorband[2];
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
else {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
paintColor[0] = brush->r;
|
|
|
|
|
paintColor[1] = brush->g;
|
|
|
|
|
paintColor[2] = brush->b;
|
2011-06-18 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
else if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
2018-11-14 12:53:15 +11:00
|
|
|
/* get displace depth */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float disp_intersect = (1.0f - sqrtf((brush_radius - distance) / brush_radius)) * brush_radius;
|
|
|
|
|
depth = max_ff(0.0f, (brush_radius - disp_intersect) / bData->bNormal[index].normal_scale);
|
|
|
|
|
}
|
|
|
|
|
dynamicPaint_updatePointData(surface, index, brush, paintColor, strength, depth, velocity_val, timescale);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int dynamicPaint_paintSinglePoint(
|
2018-06-11 14:39:38 +02:00
|
|
|
Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
Object *brushOb, Scene *scene, float timescale)
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
float brush_radius = brush->paint_distance * surface->radius_scale;
|
|
|
|
|
Vec3f brushVel;
|
|
|
|
|
|
|
|
|
|
if (brush->flags & MOD_DPAINT_USES_VELOCITY)
|
2018-04-06 12:07:27 +02:00
|
|
|
dynamicPaint_brushObjectCalculateVelocity(depsgraph, scene, brushOb, &brushVel, timescale);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
const MVert *mvert = brush->mesh->mvert;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Loop through every surface point
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
*/
|
|
|
|
|
DynamicPaintPaintData data = {
|
2016-06-19 06:25:54 +10:00
|
|
|
.surface = surface,
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
.brush = brush, .brushOb = brushOb,
|
2016-06-19 06:25:54 +10:00
|
|
|
.scene = scene, .timescale = timescale,
|
|
|
|
|
.mvert = mvert,
|
|
|
|
|
.brush_radius = brush_radius, .brushVelocity = &brushVel,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
.pointCoord = pointCoord,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_paint_single_point_cb_ex,
|
|
|
|
|
&settings);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/***************************** Dynamic Paint Step / Baking ******************************/
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-07-02 18:06:39 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Calculate current frame distances and directions for adjacency data
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_prepare_adjacency_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = userdata;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
|
|
|
|
BakeAdjPoint *bNeighs = bData->bNeighs;
|
|
|
|
|
PaintAdjData *adj_data = sData->adj_data;
|
|
|
|
|
Vec3f *realCoord = bData->realCoord;
|
|
|
|
|
|
|
|
|
|
const int num_neighs = adj_data->n_num[index];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num_neighs; i++) {
|
|
|
|
|
const int n_index = adj_data->n_index[index] + i;
|
|
|
|
|
const int t_index = adj_data->n_target[n_index];
|
|
|
|
|
|
|
|
|
|
/* dir vec */
|
|
|
|
|
sub_v3_v3v3(bNeighs[n_index].dir, realCoord[bData->s_pos[t_index]].v, realCoord[bData->s_pos[index]].v);
|
|
|
|
|
/* dist */
|
|
|
|
|
bNeighs[n_index].dist = normalize_v3(bNeighs[n_index].dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, const bool force_init)
|
2011-07-02 18:06:39 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintBakeData *bData = sData->bData;
|
2012-01-24 17:28:50 +00:00
|
|
|
BakeAdjPoint *bNeighs;
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintAdjData *adj_data = sData->adj_data;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
int index;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if ((!surface_usesAdjDistance(surface) && !force_init) || !sData->adj_data)
|
|
|
|
|
return;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (bData->bNeighs)
|
|
|
|
|
MEM_freeN(bData->bNeighs);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bNeighs = bData->bNeighs = MEM_mallocN(sData->adj_data->total_targets * sizeof(*bNeighs), "PaintEffectBake");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!bNeighs)
|
|
|
|
|
return;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
sData,
|
|
|
|
|
dynamic_paint_prepare_adjacency_cb,
|
|
|
|
|
&settings);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* calculate average values (single thread).
|
|
|
|
|
* Note: tried to put this in threaded callback (using _finalize feature), but gave ~30% slower result! */
|
|
|
|
|
bData->average_dist = 0.0;
|
2012-04-28 06:31:57 +00:00
|
|
|
for (index = 0; index < sData->total_points; index++) {
|
2011-08-03 18:31:48 +00:00
|
|
|
int numOfNeighs = adj_data->n_num[index];
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int i = 0; i < numOfNeighs; i++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
bData->average_dist += (double)bNeighs[adj_data->n_index[index] + i].dist;
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bData->average_dist /= adj_data->total_targets;
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* find two adjacency points (closest_id) and influence (closest_d) to move paint towards when affected by a force */
|
2016-05-12 12:08:03 +02:00
|
|
|
static void surface_determineForceTargetPoints(
|
2016-05-18 22:04:58 +02:00
|
|
|
const PaintSurfaceData *sData, const int index, const float force[3], float closest_d[2], int closest_id[2])
|
2011-09-05 16:04:15 +00:00
|
|
|
{
|
2012-01-24 17:28:50 +00:00
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
2016-05-18 22:04:58 +02:00
|
|
|
const int numOfNeighs = sData->adj_data->n_num[index];
|
2011-09-05 16:04:15 +00:00
|
|
|
int i;
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
closest_id[0] = closest_id[1] = -1;
|
|
|
|
|
closest_d[0] = closest_d[1] = -1.0f;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
|
/* find closest neigh */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfNeighs; i++) {
|
2016-05-18 22:04:58 +02:00
|
|
|
const int n_index = sData->adj_data->n_index[index] + i;
|
|
|
|
|
const float dir_dot = dot_v3v3(bNeighs[n_index].dir, force);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (dir_dot > closest_d[0] && dir_dot > 0.0f) {
|
|
|
|
|
closest_d[0] = dir_dot;
|
|
|
|
|
closest_id[0] = n_index;
|
|
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (closest_d[0] < 0.0f)
|
|
|
|
|
return;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
|
/* find second closest neigh */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfNeighs; i++) {
|
2016-05-18 22:04:58 +02:00
|
|
|
const int n_index = sData->adj_data->n_index[index] + i;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (n_index == closest_id[0])
|
|
|
|
|
continue;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
const float dir_dot = dot_v3v3(bNeighs[n_index].dir, force);
|
|
|
|
|
const float closest_dot = dot_v3v3(bNeighs[n_index].dir, bNeighs[closest_id[0]].dir);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2012-03-01 12:20:18 +00:00
|
|
|
/* only accept neighbor at "other side" of the first one in relation to force dir
|
2018-09-02 18:28:27 +10:00
|
|
|
* so make sure angle between this and closest neigh is greater than first angle. */
|
2012-05-12 16:11:34 +00:00
|
|
|
if (dir_dot > closest_d[1] && closest_dot < closest_d[0] && dir_dot > 0.0f) {
|
2016-05-18 22:04:58 +02:00
|
|
|
closest_d[1] = dir_dot;
|
|
|
|
|
closest_id[1] = n_index;
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
/* if two valid neighs found, calculate how force effect is divided evenly between them
|
|
|
|
|
* (so that d[0] + d[1] = 1.0) */
|
2011-09-05 16:04:15 +00:00
|
|
|
if (closest_id[1] != -1) {
|
|
|
|
|
float force_proj[3];
|
|
|
|
|
float tangent[3];
|
2016-05-18 22:04:58 +02:00
|
|
|
const float neigh_diff = acosf(dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
|
2011-09-05 16:04:15 +00:00
|
|
|
float force_intersect;
|
|
|
|
|
float temp;
|
|
|
|
|
|
2012-08-24 23:22:34 +00:00
|
|
|
/* project force vector on the plane determined by these two neighbor points
|
2018-09-02 18:28:27 +10:00
|
|
|
* and calculate relative force angle from it. */
|
2011-09-05 16:04:15 +00:00
|
|
|
cross_v3_v3v3(tangent, bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir);
|
|
|
|
|
normalize_v3(tangent);
|
|
|
|
|
force_intersect = dot_v3v3(force, tangent);
|
2012-05-12 16:11:34 +00:00
|
|
|
madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f) * force_intersect);
|
2011-09-05 16:04:15 +00:00
|
|
|
normalize_v3(force_proj);
|
|
|
|
|
|
2012-03-09 00:41:09 +00:00
|
|
|
/* get drip factor based on force dir in relation to angle between those neighbors */
|
2011-09-05 16:04:15 +00:00
|
|
|
temp = dot_v3v3(bNeighs[closest_id[0]].dir, force_proj);
|
|
|
|
|
CLAMP(temp, -1.0f, 1.0f); /* float precision might cause values > 1.0f that return infinite */
|
2012-05-12 16:11:34 +00:00
|
|
|
closest_d[1] = acosf(temp) / neigh_diff;
|
2011-09-05 16:04:15 +00:00
|
|
|
closest_d[0] = 1.0f - closest_d[1];
|
|
|
|
|
|
|
|
|
|
/* and multiply depending on how deeply force intersects surface */
|
2014-03-01 14:20:54 +11:00
|
|
|
temp = fabsf(force_intersect);
|
2011-09-05 16:04:15 +00:00
|
|
|
CLAMP(temp, 0.0f, 1.0f);
|
2012-05-12 16:42:12 +00:00
|
|
|
mul_v2_fl(closest_d, acosf(temp) / (float)M_PI_2);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-01 12:20:18 +00:00
|
|
|
/* if only single neighbor, still linearize force intersection effect */
|
2012-05-12 16:42:12 +00:00
|
|
|
closest_d[0] = 1.0f - acosf(closest_d[0]) / (float)M_PI_2;
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-04 07:09:21 +00:00
|
|
|
static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, float timescale)
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
2012-01-24 17:28:50 +00:00
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
2011-08-03 18:31:48 +00:00
|
|
|
int index, steps, step;
|
|
|
|
|
float eff_scale, max_velocity = 0.0f;
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!sData->adj_data)
|
|
|
|
|
return;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* find max velocity */
|
|
|
|
|
for (index = 0; index < sData->total_points; index++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
float vel = bData->brush_velocity[index * 4 + 3];
|
2016-05-12 12:08:03 +02:00
|
|
|
CLAMP_MIN(max_velocity, vel);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-22 04:05:38 +10:00
|
|
|
steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale);
|
2011-08-03 18:31:48 +00:00
|
|
|
CLAMP(steps, 0, 12);
|
2012-05-12 16:11:34 +00:00
|
|
|
eff_scale = brush->smudge_strength / (float)steps * timescale;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (step = 0; step < steps; step++) {
|
2011-08-03 18:31:48 +00:00
|
|
|
for (index = 0; index < sData->total_points; index++) {
|
|
|
|
|
int i;
|
2017-01-03 18:50:15 +03:00
|
|
|
|
|
|
|
|
if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
float smudge_str = bData->brush_velocity[index * 4 + 3];
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* force targets */
|
|
|
|
|
int closest_id[2];
|
|
|
|
|
float closest_d[2];
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!smudge_str)
|
|
|
|
|
continue;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* get force affect points */
|
2012-05-12 16:11:34 +00:00
|
|
|
surface_determineForceTargetPoints(sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* Apply movement towards those two points */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2011-08-03 18:31:48 +00:00
|
|
|
int n_index = closest_id[i];
|
2012-05-12 16:11:34 +00:00
|
|
|
if (n_index != -1 && closest_d[i] > 0.0f) {
|
2011-08-03 18:31:48 +00:00
|
|
|
float dir_dot = closest_d[i], dir_factor;
|
2012-05-12 16:11:34 +00:00
|
|
|
float speed_scale = eff_scale * smudge_str / bNeighs[n_index].dist;
|
|
|
|
|
PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[sData->adj_data->n_target[n_index]];
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* just skip if angle is too extreme */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (dir_dot <= 0.0f)
|
|
|
|
|
continue;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
dir_factor = dir_dot * speed_scale;
|
2015-07-27 15:52:54 +10:00
|
|
|
CLAMP_MAX(dir_factor, brush->smudge_strength);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* mix new color and alpha */
|
2015-07-27 15:52:54 +10:00
|
|
|
mixColors(ePoint->color, ePoint->color[3], pPoint->color, pPoint->color[3], dir_factor);
|
|
|
|
|
ePoint->color[3] = ePoint->color[3] * (1.0f - dir_factor) + pPoint->color[3] * dir_factor;
|
2011-08-05 09:31:35 +00:00
|
|
|
|
2011-10-31 13:01:06 +00:00
|
|
|
/* smudge "wet layer" */
|
2015-07-27 15:52:54 +10:00
|
|
|
mixColors(ePoint->e_color, ePoint->e_color[3], pPoint->e_color, pPoint->e_color[3], dir_factor);
|
|
|
|
|
ePoint->e_color[3] = ePoint->e_color[3] * (1.0f - dir_factor) + pPoint->e_color[3] * dir_factor;
|
2012-05-12 16:11:34 +00:00
|
|
|
pPoint->wetness *= (1.0f - dir_factor);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
typedef struct DynamicPaintEffectData {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface;
|
2016-05-18 22:04:58 +02:00
|
|
|
Scene *scene;
|
|
|
|
|
|
|
|
|
|
float *force;
|
|
|
|
|
ListBase *effectors;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const void *prevPoint;
|
2016-05-18 22:04:58 +02:00
|
|
|
const float eff_scale;
|
|
|
|
|
|
|
|
|
|
uint8_t *point_locks;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
const float wave_speed;
|
|
|
|
|
const float wave_scale;
|
|
|
|
|
const float wave_max_slope;
|
|
|
|
|
|
|
|
|
|
const float dt;
|
|
|
|
|
const float min_dist;
|
|
|
|
|
const float damp_factor;
|
|
|
|
|
const bool reset_wave;
|
2016-05-18 22:04:58 +02:00
|
|
|
} DynamicPaintEffectData;
|
|
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Prepare data required by effects for current frame.
|
|
|
|
|
* Returns number of steps required
|
2012-05-12 16:11:34 +00:00
|
|
|
*/
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_prepare_effect_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintEffectData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const PaintBakeData *bData = sData->bData;
|
|
|
|
|
Vec3f *realCoord = bData->realCoord;
|
|
|
|
|
|
|
|
|
|
Scene *scene = data->scene;
|
|
|
|
|
|
|
|
|
|
float *force = data->force;
|
|
|
|
|
ListBase *effectors = data->effectors;
|
|
|
|
|
|
|
|
|
|
float forc[3] = {0};
|
|
|
|
|
float vel[3] = {0};
|
2011-08-05 09:31:35 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* apply force fields */
|
|
|
|
|
if (effectors) {
|
|
|
|
|
EffectedPoint epoint;
|
|
|
|
|
pd_point_from_loc(scene, realCoord[bData->s_pos[index]].v, vel, index, &epoint);
|
|
|
|
|
epoint.vel_to_sec = 1.0f;
|
2018-06-21 19:45:39 +02:00
|
|
|
BKE_effectors_apply(effectors, NULL, surface->effector_weights, &epoint, forc, NULL);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if global gravity is enabled, add it too */
|
|
|
|
|
if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY)
|
|
|
|
|
/* also divide by 10 to about match default grav
|
2018-09-02 18:28:27 +10:00
|
|
|
* with default force strength (1.0). */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
madd_v3_v3fl(forc, scene->physics_settings.gravity,
|
|
|
|
|
surface->effector_weights->global_gravity * surface->effector_weights->weight[0] / 10.f);
|
|
|
|
|
|
|
|
|
|
/* add surface point velocity and acceleration if enabled */
|
|
|
|
|
if (bData->velocity) {
|
|
|
|
|
if (surface->drip_vel)
|
|
|
|
|
madd_v3_v3fl(forc, bData->velocity[index].v, surface->drip_vel * (-1.0f));
|
|
|
|
|
|
|
|
|
|
/* acceleration */
|
|
|
|
|
if (bData->prev_velocity && surface->drip_acc) {
|
|
|
|
|
float acc[3];
|
|
|
|
|
copy_v3_v3(acc, bData->velocity[index].v);
|
|
|
|
|
sub_v3_v3(acc, bData->prev_velocity[index].v);
|
|
|
|
|
madd_v3_v3fl(forc, acc, surface->drip_acc * (-1.0f));
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
/* force strength, and normalize force vec */
|
|
|
|
|
force[index * 4 + 3] = normalize_v3_v3(&force[index * 4], forc);
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static int dynamicPaint_prepareEffectStep(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale)
|
2011-06-27 07:30:58 +00:00
|
|
|
{
|
|
|
|
|
double average_force = 0.0f;
|
2012-05-12 16:11:34 +00:00
|
|
|
float shrink_speed = 0.0f, spread_speed = 0.0f;
|
2012-01-16 17:18:07 +00:00
|
|
|
float fastest_effect, avg_dist;
|
2011-06-27 07:30:58 +00:00
|
|
|
int steps;
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintBakeData *bData = sData->bData;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
/* Init force data if required */
|
|
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) {
|
2018-06-22 14:42:03 +02:00
|
|
|
ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, surface->effector_weights);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
/* allocate memory for force data (dir vector + strength) */
|
2012-05-12 16:11:34 +00:00
|
|
|
*force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces");
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
if (*force) {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintEffectData data = {
|
|
|
|
|
.surface = surface, .scene = scene,
|
|
|
|
|
.force = *force, .effectors = effectors,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_prepare_effect_cb,
|
|
|
|
|
&settings);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* calculate average values (single thread) */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int index = 0; index < sData->total_points; index++) {
|
2016-07-22 04:05:38 +10:00
|
|
|
average_force += (double)(*force)[index * 4 + 3];
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
average_force /= sData->total_points;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
2018-06-21 19:45:39 +02:00
|
|
|
BKE_effectors_free(effectors);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-26 20:05:38 +00:00
|
|
|
/* Get number of required steps using average point distance
|
2018-09-02 18:28:27 +10:00
|
|
|
* so that just a few ultra close pixels wont up substeps to max. */
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
/* adjust number of required substep by fastest active effect */
|
|
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD)
|
|
|
|
|
spread_speed = surface->spread_speed;
|
|
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK)
|
|
|
|
|
shrink_speed = surface->shrink_speed;
|
|
|
|
|
|
2012-12-21 05:07:26 +00:00
|
|
|
fastest_effect = max_fff(spread_speed, shrink_speed, average_force);
|
2016-07-22 04:05:38 +10:00
|
|
|
avg_dist = bData->average_dist * (double)CANVAS_REL_SIZE / (double)getSurfaceDimension(sData);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
steps = (int)ceilf(1.5f * EFF_MOVEMENT_PER_FRAME * fastest_effect / avg_dist * timescale);
|
2012-01-16 17:18:07 +00:00
|
|
|
CLAMP(steps, 1, 20);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
|
|
|
|
return steps;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-09 18:28:30 +00:00
|
|
|
/**
|
2018-11-14 12:53:15 +11:00
|
|
|
* Processes active effect step.
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_effect_spread_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2011-06-27 07:30:58 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintEffectData *data = userdata;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL)
|
|
|
|
|
return;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int numOfNeighs = sData->adj_data->n_num[index];
|
2012-01-24 17:28:50 +00:00
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
2016-05-18 22:04:58 +02:00
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
const PaintPoint *prevPoint = data->prevPoint;
|
|
|
|
|
const float eff_scale = data->eff_scale;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int *n_index = sData->adj_data->n_index;
|
2016-05-18 22:04:58 +02:00
|
|
|
const int *n_target = sData->adj_data->n_target;
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Loop through neighboring points */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int i = 0; i < numOfNeighs; i++) {
|
|
|
|
|
const int n_idx = n_index[index] + i;
|
|
|
|
|
float w_factor;
|
|
|
|
|
const PaintPoint *pPoint_prev = &prevPoint[n_target[n_idx]];
|
|
|
|
|
const float speed_scale = (bNeighs[n_idx].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_idx].dist;
|
|
|
|
|
const float color_mix = min_fff(pPoint_prev->wetness, pPoint->wetness, 1.0f) * 0.25f * surface->color_spread_speed;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* do color mixing */
|
|
|
|
|
if (color_mix)
|
|
|
|
|
mixColors(pPoint->e_color, pPoint->e_color[3], pPoint_prev->e_color, pPoint_prev->e_color[3], color_mix);
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Only continue if surrounding point has higher wetness */
|
|
|
|
|
if (pPoint_prev->wetness < pPoint->wetness || pPoint_prev->wetness < MIN_WETNESS)
|
|
|
|
|
continue;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
w_factor = 1.0f / numOfNeighs * min_ff(pPoint_prev->wetness, 1.0f) * speed_scale;
|
|
|
|
|
CLAMP(w_factor, 0.0f, 1.0f);
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* mix new wetness and color */
|
2017-01-04 19:40:34 +03:00
|
|
|
pPoint->wetness = pPoint->wetness + w_factor * (pPoint_prev->wetness - pPoint->wetness);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
pPoint->e_color[3] = mixColors(pPoint->e_color, pPoint->e_color[3],
|
|
|
|
|
pPoint_prev->e_color, pPoint_prev->e_color[3], w_factor);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-18 22:04:58 +02:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_effect_shrink_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintEffectData *data = userdata;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
2017-01-03 18:50:15 +03:00
|
|
|
if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL)
|
|
|
|
|
return;
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int numOfNeighs = sData->adj_data->n_num[index];
|
|
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
|
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
const PaintPoint *prevPoint = data->prevPoint;
|
|
|
|
|
const float eff_scale = data->eff_scale;
|
|
|
|
|
float totalAlpha = 0.0f;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const int *n_index = sData->adj_data->n_index;
|
|
|
|
|
const int *n_target = sData->adj_data->n_target;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Loop through neighboring points */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
for (int i = 0; i < numOfNeighs; i++) {
|
|
|
|
|
const int n_idx = n_index[index] + i;
|
|
|
|
|
const float speed_scale = (bNeighs[n_idx].dist < eff_scale) ? 1.0f : eff_scale / bNeighs[n_idx].dist;
|
|
|
|
|
const PaintPoint *pPoint_prev = &prevPoint[n_target[n_idx]];
|
|
|
|
|
float a_factor, ea_factor, w_factor;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
totalAlpha += pPoint_prev->e_color[3];
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Check if neighboring point has lower alpha,
|
2018-09-02 18:28:27 +10:00
|
|
|
* if so, decrease this point's alpha as well. */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (pPoint->color[3] <= 0.0f && pPoint->e_color[3] <= 0.0f && pPoint->wetness <= 0.0f)
|
|
|
|
|
continue;
|
2016-05-18 22:04:58 +02:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* decrease factor for dry paint alpha */
|
|
|
|
|
a_factor = max_ff((1.0f - pPoint_prev->color[3]) / numOfNeighs * (pPoint->color[3] - pPoint_prev->color[3]) * speed_scale, 0.0f);
|
|
|
|
|
/* decrease factor for wet paint alpha */
|
|
|
|
|
ea_factor = max_ff((1.0f - pPoint_prev->e_color[3]) / 8 * (pPoint->e_color[3] - pPoint_prev->e_color[3]) * speed_scale, 0.0f);
|
|
|
|
|
/* decrease factor for paint wetness */
|
|
|
|
|
w_factor = max_ff((1.0f - pPoint_prev->wetness) / 8 * (pPoint->wetness - pPoint_prev->wetness) * speed_scale, 0.0f);
|
|
|
|
|
|
|
|
|
|
pPoint->color[3] -= a_factor;
|
|
|
|
|
CLAMP_MIN(pPoint->color[3], 0.0f);
|
|
|
|
|
pPoint->e_color[3] -= ea_factor;
|
|
|
|
|
CLAMP_MIN(pPoint->e_color[3], 0.0f);
|
|
|
|
|
pPoint->wetness -= w_factor;
|
|
|
|
|
CLAMP_MIN(pPoint->wetness, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-18 22:04:58 +02:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_effect_drip_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintEffectData *data = userdata;
|
|
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
2017-01-03 18:50:15 +03:00
|
|
|
|
|
|
|
|
if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
|
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
const PaintPoint *prevPoint = data->prevPoint;
|
|
|
|
|
const PaintPoint *pPoint_prev = &prevPoint[index];
|
|
|
|
|
const float *force = data->force;
|
|
|
|
|
const float eff_scale = data->eff_scale;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
const int *n_target = sData->adj_data->n_target;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
uint8_t *point_locks = data->point_locks;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
int closest_id[2];
|
|
|
|
|
float closest_d[2];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* adjust drip speed depending on wetness */
|
|
|
|
|
float w_factor = pPoint_prev->wetness - 0.025f;
|
|
|
|
|
if (w_factor <= 0)
|
|
|
|
|
return;
|
|
|
|
|
CLAMP(w_factor, 0.0f, 1.0f);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-09-27 13:54:26 +02:00
|
|
|
float ppoint_wetness_diff = 0.0f;
|
|
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* get force affect points */
|
|
|
|
|
surface_determineForceTargetPoints(sData, index, &force[index * 4], closest_d, closest_id);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* Apply movement towards those two points */
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
const int n_idx = closest_id[i];
|
|
|
|
|
if (n_idx != -1 && closest_d[i] > 0.0f) {
|
|
|
|
|
const float dir_dot = closest_d[i];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* just skip if angle is too extreme */
|
|
|
|
|
if (dir_dot <= 0.0f)
|
|
|
|
|
continue;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
float dir_factor, a_factor;
|
|
|
|
|
const float speed_scale = eff_scale * force[index * 4 + 3] / bNeighs[n_idx].dist;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
const unsigned int n_trgt = (unsigned int)n_target[n_idx];
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* Sort of spinlock, but only for given ePoint.
|
|
|
|
|
* Since the odds a same ePoint is modified at the same time by several threads is very low, this is
|
2016-07-08 00:48:03 +10:00
|
|
|
* much more efficient than a global spin lock. */
|
2016-09-27 13:54:26 +02:00
|
|
|
const unsigned int epointlock_idx = n_trgt / 8;
|
|
|
|
|
const uint8_t epointlock_bitmask = 1 << (n_trgt & 7); /* 7 == 0b111 */
|
|
|
|
|
while (atomic_fetch_and_or_uint8(&point_locks[epointlock_idx], epointlock_bitmask) & epointlock_bitmask);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[n_trgt];
|
|
|
|
|
const float e_wet = ePoint->wetness;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
dir_factor = min_ff(0.5f, dir_dot * min_ff(speed_scale, 1.0f) * w_factor);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* mix new wetness */
|
|
|
|
|
ePoint->wetness += dir_factor;
|
|
|
|
|
CLAMP(ePoint->wetness, 0.0f, MAX_WETNESS);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
/* mix new color */
|
|
|
|
|
a_factor = dir_factor / pPoint_prev->wetness;
|
|
|
|
|
CLAMP(a_factor, 0.0f, 1.0f);
|
|
|
|
|
mixColors(ePoint->e_color, ePoint->e_color[3], pPoint_prev->e_color, pPoint_prev->e_color[3], a_factor);
|
|
|
|
|
/* dripping is supposed to preserve alpha level */
|
|
|
|
|
if (pPoint_prev->e_color[3] > ePoint->e_color[3]) {
|
|
|
|
|
ePoint->e_color[3] += a_factor * pPoint_prev->e_color[3];
|
|
|
|
|
CLAMP_MAX(ePoint->e_color[3], pPoint_prev->e_color[3]);
|
|
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2016-09-27 13:54:26 +02:00
|
|
|
/* Decrease paint wetness on current point
|
|
|
|
|
* (just store diff here, that way we can only lock current point once at the end to apply it). */
|
|
|
|
|
ppoint_wetness_diff += (ePoint->wetness - e_wet);
|
2016-05-18 22:04:58 +02:00
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2016-09-27 13:54:26 +02:00
|
|
|
{
|
|
|
|
|
uint8_t ret = atomic_fetch_and_and_uint8(&point_locks[epointlock_idx], ~epointlock_bitmask);
|
|
|
|
|
BLI_assert(ret & epointlock_bitmask);
|
|
|
|
|
}
|
2016-05-18 22:04:58 +02:00
|
|
|
#else
|
2016-09-27 13:54:26 +02:00
|
|
|
atomic_fetch_and_and_uint8(&point_locks[epointlock_idx], ~epointlock_bitmask);
|
2016-05-18 22:04:58 +02:00
|
|
|
#endif
|
2016-06-19 06:25:54 +10:00
|
|
|
}
|
2016-05-18 22:04:58 +02:00
|
|
|
}
|
2016-09-27 13:54:26 +02:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const unsigned int ppointlock_idx = index / 8;
|
|
|
|
|
const uint8_t ppointlock_bitmask = 1 << (index & 7); /* 7 == 0b111 */
|
|
|
|
|
while (atomic_fetch_and_or_uint8(&point_locks[ppointlock_idx], ppointlock_bitmask) & ppointlock_bitmask);
|
|
|
|
|
|
|
|
|
|
pPoint->wetness -= ppoint_wetness_diff;
|
|
|
|
|
CLAMP(pPoint->wetness, 0.0f, MAX_WETNESS);
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
{
|
|
|
|
|
uint8_t ret = atomic_fetch_and_and_uint8(&point_locks[ppointlock_idx], ~ppointlock_bitmask);
|
|
|
|
|
BLI_assert(ret & ppointlock_bitmask);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
atomic_fetch_and_and_uint8(&point_locks[ppointlock_idx], ~ppointlock_bitmask);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2016-05-18 22:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static void dynamicPaint_doEffectStep(
|
|
|
|
|
DynamicPaintSurface *surface, float *force, PaintPoint *prevPoint, float timescale, float steps)
|
2011-06-27 07:30:58 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
|
|
|
|
const float distance_scale = getSurfaceDimension(sData) / CANVAS_REL_SIZE;
|
2011-10-13 20:00:22 +00:00
|
|
|
timescale /= steps;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!sData->adj_data)
|
|
|
|
|
return;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Spread Effect
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
2012-02-27 10:35:39 +00:00
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_SPREAD) {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->spread_speed * timescale;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Copy current surface to the previous points array to read unmodified values */
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint));
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintEffectData data = {
|
|
|
|
|
.surface = surface, .prevPoint = prevPoint, .eff_scale = eff_scale,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_effect_spread_cb,
|
|
|
|
|
&settings);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Shrink Effect
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
2012-02-27 10:35:39 +00:00
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_SHRINK) {
|
2016-05-18 22:04:58 +02:00
|
|
|
const float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * surface->shrink_speed * timescale;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Copy current surface to the previous points array to read unmodified values */
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint));
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintEffectData data = {
|
|
|
|
|
.surface = surface, .prevPoint = prevPoint, .eff_scale = eff_scale,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_effect_shrink_cb,
|
|
|
|
|
&settings);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Drip Effect
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
2012-04-28 06:31:57 +00:00
|
|
|
if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP && force) {
|
2016-05-18 22:04:58 +02:00
|
|
|
const float eff_scale = distance_scale * EFF_MOVEMENT_PER_FRAME * timescale / 2.0f;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
/* Same as BLI_bitmask, but handled atomicaly as 'ePoint' locks. */
|
|
|
|
|
const size_t point_locks_size = (sData->total_points / 8) + 1;
|
|
|
|
|
uint8_t *point_locks = MEM_callocN(sizeof(*point_locks) * point_locks_size, __func__);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Copy current surface to the previous points array to read unmodified values */
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(struct PaintPoint));
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
DynamicPaintEffectData data = {
|
2016-06-19 06:25:54 +10:00
|
|
|
.surface = surface, .prevPoint = prevPoint,
|
2016-05-18 22:04:58 +02:00
|
|
|
.eff_scale = eff_scale, .force = force,
|
|
|
|
|
.point_locks = point_locks,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_effect_drip_cb,
|
|
|
|
|
&settings);
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2016-05-18 22:04:58 +02:00
|
|
|
MEM_freeN(point_locks);
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_border_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int b_index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2017-01-03 18:50:15 +03:00
|
|
|
{
|
|
|
|
|
const DynamicPaintEffectData *data = userdata;
|
|
|
|
|
|
|
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
|
|
|
|
|
const int index = sData->adj_data->border[b_index];
|
|
|
|
|
|
|
|
|
|
const int numOfNeighs = sData->adj_data->n_num[index];
|
|
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
|
|
|
|
|
const int *n_index = sData->adj_data->n_index;
|
|
|
|
|
const int *n_target = sData->adj_data->n_target;
|
|
|
|
|
|
|
|
|
|
/* Average neighboring points. Intermediaries use premultiplied alpha. */
|
|
|
|
|
float mix_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
float mix_e_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
float mix_wetness = 0.0f;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numOfNeighs; i++) {
|
|
|
|
|
const int n_idx = n_index[index] + i;
|
|
|
|
|
const int target = n_target[n_idx];
|
|
|
|
|
|
|
|
|
|
PaintPoint *pPoint2 = &((PaintPoint *)sData->type_data)[target];
|
|
|
|
|
|
|
|
|
|
assert(!(sData->adj_data->flags[target] & ADJ_BORDER_PIXEL));
|
|
|
|
|
|
|
|
|
|
madd_v3_v3fl(mix_color, pPoint2->color, pPoint2->color[3]);
|
|
|
|
|
mix_color[3] += pPoint2->color[3];
|
|
|
|
|
|
|
|
|
|
madd_v3_v3fl(mix_e_color, pPoint2->e_color, pPoint2->e_color[3]);
|
|
|
|
|
mix_e_color[3] += pPoint2->e_color[3];
|
|
|
|
|
|
|
|
|
|
mix_wetness += pPoint2->wetness;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float divisor = 1.0f / numOfNeighs;
|
|
|
|
|
|
|
|
|
|
if (mix_color[3]) {
|
|
|
|
|
pPoint->color[3] = mix_color[3] * divisor;
|
|
|
|
|
mul_v3_v3fl(pPoint->color, mix_color, divisor / pPoint->color[3]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pPoint->color[3] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mix_e_color[3]) {
|
|
|
|
|
pPoint->e_color[3] = mix_e_color[3] * divisor;
|
|
|
|
|
mul_v3_v3fl(pPoint->e_color, mix_e_color, divisor / pPoint->e_color[3]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pPoint->e_color[3] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pPoint->wetness = mix_wetness / numOfNeighs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void dynamicPaint_doBorderStep(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
|
|
|
|
|
if (!sData->adj_data || !sData->adj_data->border)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Don't use prevPoint, relying on the condition that neighbors are never border pixels. */
|
|
|
|
|
DynamicPaintEffectData data = {
|
2019-01-07 00:06:58 +11:00
|
|
|
.surface = surface,
|
2017-01-03 18:50:15 +03:00
|
|
|
};
|
|
|
|
|
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->adj_data->total_border > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->adj_data->total_border,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_border_cb,
|
|
|
|
|
&settings);
|
2017-01-03 18:50:15 +03:00
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_wave_step_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintEffectData *data = userdata;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
|
|
|
|
const PaintWavePoint *prevPoint = data->prevPoint;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float wave_speed = data->wave_speed;
|
|
|
|
|
const float wave_scale = data->wave_scale;
|
|
|
|
|
const float wave_max_slope = data->wave_max_slope;
|
2011-06-27 07:30:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float dt = data->dt;
|
|
|
|
|
const float min_dist = data->min_dist;
|
|
|
|
|
const float damp_factor = data->damp_factor;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
PaintWavePoint *wPoint = &((PaintWavePoint *)sData->type_data)[index];
|
|
|
|
|
const int numOfNeighs = sData->adj_data->n_num[index];
|
|
|
|
|
float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f, avg_n_height = 0.0f;
|
|
|
|
|
int numOfN = 0, numOfRN = 0;
|
|
|
|
|
|
|
|
|
|
if (wPoint->state > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int *n_index = sData->adj_data->n_index;
|
|
|
|
|
const int *n_target = sData->adj_data->n_target;
|
|
|
|
|
const int *adj_flags = sData->adj_data->flags;
|
|
|
|
|
|
|
|
|
|
/* calculate force from surrounding points */
|
|
|
|
|
for (int i = 0; i < numOfNeighs; i++) {
|
|
|
|
|
const int n_idx = n_index[index] + i;
|
|
|
|
|
float dist = bNeighs[n_idx].dist * wave_scale;
|
|
|
|
|
const PaintWavePoint *tPoint = &prevPoint[n_target[n_idx]];
|
|
|
|
|
|
|
|
|
|
if (!dist || tPoint->state > 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
CLAMP_MIN(dist, min_dist);
|
|
|
|
|
avg_dist += dist;
|
|
|
|
|
numOfN++;
|
|
|
|
|
|
|
|
|
|
/* count average height for edge points for open borders */
|
|
|
|
|
if (!(adj_flags[n_target[n_idx]] & ADJ_ON_MESH_EDGE)) {
|
|
|
|
|
avg_n_height += tPoint->height;
|
|
|
|
|
numOfRN++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
force += (tPoint->height - wPoint->height) / (dist * dist);
|
|
|
|
|
avg_height += tPoint->height;
|
|
|
|
|
}
|
|
|
|
|
avg_dist = (numOfN) ? avg_dist / numOfN : 0.0f;
|
|
|
|
|
|
|
|
|
|
if (surface->flags & MOD_DPAINT_WAVE_OPEN_BORDERS && adj_flags[index] & ADJ_ON_MESH_EDGE) {
|
|
|
|
|
/* if open borders, apply a fake height to keep waves going on */
|
|
|
|
|
avg_n_height = (numOfRN) ? avg_n_height / numOfRN : 0.0f;
|
|
|
|
|
wPoint->height = (dt * wave_speed * avg_n_height + wPoint->height * avg_dist) /
|
|
|
|
|
(avg_dist + dt * wave_speed);
|
|
|
|
|
}
|
|
|
|
|
/* else do wave eq */
|
|
|
|
|
else {
|
|
|
|
|
/* add force towards zero height based on average dist */
|
|
|
|
|
if (avg_dist)
|
|
|
|
|
force += (0.0f - wPoint->height) * surface->wave_spring / (avg_dist * avg_dist) / 2.0f;
|
|
|
|
|
|
|
|
|
|
/* change point velocity */
|
|
|
|
|
wPoint->velocity += force * dt * wave_speed * wave_speed;
|
|
|
|
|
/* damping */
|
|
|
|
|
wPoint->velocity *= damp_factor;
|
|
|
|
|
/* and new height */
|
|
|
|
|
wPoint->height += wPoint->velocity * dt;
|
|
|
|
|
|
|
|
|
|
/* limit wave slope steepness */
|
|
|
|
|
if (wave_max_slope && avg_dist) {
|
|
|
|
|
const float max_offset = wave_max_slope * avg_dist;
|
|
|
|
|
const float offset = (numOfN) ? (avg_height / numOfN - wPoint->height) : 0.0f;
|
|
|
|
|
if (offset > max_offset)
|
|
|
|
|
wPoint->height += offset - max_offset;
|
|
|
|
|
else if (offset < -max_offset)
|
|
|
|
|
wPoint->height += offset + max_offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data->reset_wave) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* if there wasn't any brush intersection, clear isect height */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (wPoint->state == DPAINT_WAVE_NONE) {
|
|
|
|
|
wPoint->brush_isect = 0.0f;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
wPoint->state = DPAINT_WAVE_NONE;
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale)
|
2011-07-02 18:06:39 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
2012-01-24 17:28:50 +00:00
|
|
|
BakeAdjPoint *bNeighs = sData->bData->bNeighs;
|
2011-07-02 18:06:39 +00:00
|
|
|
int index;
|
|
|
|
|
int steps, ss;
|
|
|
|
|
float dt, min_dist, damp_factor;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float wave_speed = surface->wave_speed;
|
|
|
|
|
const float wave_max_slope = (surface->wave_smoothness >= 0.01f) ? (0.5f / surface->wave_smoothness) : 0.0f;
|
2011-07-02 18:06:39 +00:00
|
|
|
double average_dist = 0.0f;
|
2012-12-21 05:07:26 +00:00
|
|
|
const float canvas_size = getSurfaceDimension(sData);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const float wave_scale = CANVAS_REL_SIZE / canvas_size;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
/* allocate memory */
|
2016-07-22 04:05:38 +10:00
|
|
|
PaintWavePoint *prevPoint = MEM_mallocN(
|
|
|
|
|
sData->total_points * sizeof(PaintWavePoint), __func__);
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!prevPoint)
|
|
|
|
|
return;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
/* calculate average neigh distance (single thread) */
|
2012-04-28 06:31:57 +00:00
|
|
|
for (index = 0; index < sData->total_points; index++) {
|
2011-07-02 18:06:39 +00:00
|
|
|
int i;
|
2011-07-08 11:03:37 +00:00
|
|
|
int numOfNeighs = sData->adj_data->n_num[index];
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfNeighs; i++) {
|
2016-07-22 04:05:38 +10:00
|
|
|
average_dist += (double)bNeighs[sData->adj_data->n_index[index] + i].dist;
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-22 04:05:38 +10:00
|
|
|
average_dist *= (double)wave_scale / sData->adj_data->total_targets;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
|
|
|
|
/* determine number of required steps */
|
2016-07-22 04:05:38 +10:00
|
|
|
steps = (int)ceil((double)(WAVE_TIME_FAC * timescale * surface->wave_timescale) /
|
|
|
|
|
(average_dist / (double)wave_speed / 3));
|
2011-11-16 18:32:28 +00:00
|
|
|
CLAMP(steps, 1, 20);
|
2011-07-02 18:06:39 +00:00
|
|
|
timescale /= steps;
|
|
|
|
|
|
|
|
|
|
/* apply simulation values for final timescale */
|
2012-05-12 16:11:34 +00:00
|
|
|
dt = WAVE_TIME_FAC * timescale * surface->wave_timescale;
|
|
|
|
|
min_dist = wave_speed * dt * 1.5f;
|
|
|
|
|
damp_factor = pow((1.0f - surface->wave_damping), timescale * surface->wave_timescale);
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
for (ss = 0; ss < steps; ss++) {
|
2011-07-02 18:06:39 +00:00
|
|
|
/* copy previous frame data */
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(prevPoint, sData->type_data, sData->total_points * sizeof(PaintWavePoint));
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintEffectData data = {
|
|
|
|
|
.surface = surface, .prevPoint = prevPoint,
|
|
|
|
|
.wave_speed = wave_speed, .wave_scale = wave_scale, .wave_max_slope = wave_max_slope,
|
|
|
|
|
.dt = dt, .min_dist = min_dist, .damp_factor = damp_factor, .reset_wave = (ss == steps - 1),
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data, dynamic_paint_wave_step_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
MEM_freeN(prevPoint);
|
|
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Do dissolve and fading effects */
|
|
|
|
|
static bool dynamic_paint_surface_needs_dry_dissolve(DynamicPaintSurface *surface)
|
|
|
|
|
{
|
|
|
|
|
return (((surface->type == MOD_DPAINT_SURFACE_T_PAINT) &&
|
|
|
|
|
(surface->flags & (MOD_DPAINT_USE_DRYING | MOD_DPAINT_DISSOLVE))) ||
|
|
|
|
|
(ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WEIGHT) &&
|
|
|
|
|
(surface->flags & MOD_DPAINT_DISSOLVE)));
|
|
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintDissolveDryData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
const float timescale;
|
|
|
|
|
} DynamicPaintDissolveDryData;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_surface_pre_step_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
const DynamicPaintDissolveDryData *data = userdata;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const float timescale = data->timescale;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* Do drying dissolve effects */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
PaintPoint *pPoint = &((PaintPoint *)sData->type_data)[index];
|
|
|
|
|
/* drying */
|
|
|
|
|
if (surface->flags & MOD_DPAINT_USE_DRYING) {
|
|
|
|
|
if (pPoint->wetness >= MIN_WETNESS) {
|
|
|
|
|
int i;
|
|
|
|
|
float dry_ratio, f_color[4];
|
|
|
|
|
float p_wetness = pPoint->wetness;
|
|
|
|
|
|
|
|
|
|
value_dissolve(&pPoint->wetness, surface->dry_speed, timescale,
|
|
|
|
|
(surface->flags & MOD_DPAINT_DRY_LOG) != 0);
|
|
|
|
|
CLAMP_MIN(pPoint->wetness, 0.0f);
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (pPoint->wetness < surface->color_dry_threshold) {
|
|
|
|
|
dry_ratio = pPoint->wetness / p_wetness;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Slowly "shift" paint from wet layer to dry layer as it drys:
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
*/
|
|
|
|
|
/* make sure alpha values are within proper range */
|
|
|
|
|
CLAMP(pPoint->color[3], 0.0f, 1.0f);
|
|
|
|
|
CLAMP(pPoint->e_color[3], 0.0f, 1.0f);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* get current final blended color of these layers */
|
|
|
|
|
blendColors(pPoint->color, pPoint->color[3], pPoint->e_color, pPoint->e_color[3], f_color);
|
|
|
|
|
/* reduce wet layer alpha by dry factor */
|
|
|
|
|
pPoint->e_color[3] *= dry_ratio;
|
|
|
|
|
|
|
|
|
|
/* now calculate new alpha for dry layer that keeps final blended color unchanged */
|
|
|
|
|
pPoint->color[3] = (f_color[3] - pPoint->e_color[3]) / (1.0f - pPoint->e_color[3]);
|
|
|
|
|
/* for each rgb component, calculate a new dry layer color that keeps the final blend color
|
2018-09-24 17:27:41 +02:00
|
|
|
* with these new alpha values. (wet layer color doesn't change)*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (pPoint->color[3]) {
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_color[3]) /
|
2016-06-19 06:25:54 +10:00
|
|
|
(pPoint->color[3] * (1.0f - pPoint->e_color[3]));
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2011-11-05 07:39:59 +00:00
|
|
|
}
|
2012-01-16 17:18:07 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
pPoint->state = DPAINT_PAINT_WET;
|
|
|
|
|
}
|
|
|
|
|
/* in case of just dryed paint, just mix it to the dry layer and mark it empty */
|
|
|
|
|
else if (pPoint->state > 0) {
|
|
|
|
|
float f_color[4];
|
|
|
|
|
blendColors(pPoint->color, pPoint->color[3], pPoint->e_color, pPoint->e_color[3], f_color);
|
|
|
|
|
copy_v4_v4(pPoint->color, f_color);
|
|
|
|
|
/* clear wet layer */
|
|
|
|
|
pPoint->wetness = 0.0f;
|
|
|
|
|
pPoint->e_color[3] = 0.0f;
|
|
|
|
|
pPoint->state = DPAINT_PAINT_DRY;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (surface->flags & MOD_DPAINT_DISSOLVE) {
|
|
|
|
|
value_dissolve(&pPoint->color[3], surface->diss_speed, timescale,
|
2016-06-19 06:25:54 +10:00
|
|
|
(surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
CLAMP_MIN(pPoint->color[3], 0.0f);
|
|
|
|
|
|
|
|
|
|
value_dissolve(&pPoint->e_color[3], surface->diss_speed, timescale,
|
2016-06-19 06:25:54 +10:00
|
|
|
(surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
CLAMP_MIN(pPoint->e_color[3], 0.0f);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
/* dissolve for float types */
|
|
|
|
|
else if (surface->flags & MOD_DPAINT_DISSOLVE &&
|
2016-06-19 06:25:54 +10:00
|
|
|
(surface->type == MOD_DPAINT_SURFACE_T_DISPLACE || surface->type == MOD_DPAINT_SURFACE_T_WEIGHT))
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
{
|
|
|
|
|
float *point = &((float *)sData->type_data)[index];
|
|
|
|
|
/* log or linear */
|
|
|
|
|
value_dissolve(point, surface->diss_speed, timescale, (surface->flags & MOD_DPAINT_DISSOLVE_LOG) != 0);
|
|
|
|
|
CLAMP_MIN(*point, 0.0f);
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = surface->canvas->mesh;
|
|
|
|
|
MVert *mvert = mesh->mvert;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
int numOfVerts = mesh->totvert;
|
2011-07-22 18:37:30 +00:00
|
|
|
int i;
|
|
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!bData->prev_verts)
|
|
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* matrix comparison */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!equals_m4m4(bData->prev_obmat, ob->obmat))
|
|
|
|
|
return true;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* vertices */
|
2012-05-12 16:11:34 +00:00
|
|
|
for (i = 0; i < numOfVerts; i++) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!equals_v3v3(bData->prev_verts[i].co, mvert[i].co)) {
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
return true;
|
2016-05-12 12:08:03 +02:00
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
return false;
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Prepare for surface step by creating PaintBakeNormal data */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
typedef struct DynamicPaintGenerateBakeData {
|
|
|
|
|
const DynamicPaintSurface *surface;
|
|
|
|
|
Object *ob;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const MVert *mvert;
|
|
|
|
|
const Vec3f *canvas_verts;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const bool do_velocity_data;
|
|
|
|
|
const bool new_bdata;
|
|
|
|
|
} DynamicPaintGenerateBakeData;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void dynamic_paint_generate_bake_data_cb(
|
|
|
|
|
void *__restrict userdata,
|
|
|
|
|
const int index,
|
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2011-08-03 18:31:48 +00:00
|
|
|
{
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintGenerateBakeData *data = userdata;
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
const DynamicPaintSurface *surface = data->surface;
|
|
|
|
|
const PaintSurfaceData *sData = surface->data;
|
|
|
|
|
const PaintAdjData *adj_data = sData->adj_data;
|
|
|
|
|
const PaintBakeData *bData = sData->bData;
|
|
|
|
|
|
|
|
|
|
Object *ob = data->ob;
|
|
|
|
|
|
|
|
|
|
const MVert *mvert = data->mvert;
|
|
|
|
|
const Vec3f *canvas_verts = data->canvas_verts;
|
|
|
|
|
|
|
|
|
|
const bool do_velocity_data = data->do_velocity_data;
|
|
|
|
|
const bool new_bdata = data->new_bdata;
|
|
|
|
|
|
|
|
|
|
float prev_point[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
float temp_nor[3];
|
|
|
|
|
|
|
|
|
|
if (do_velocity_data && !new_bdata) {
|
|
|
|
|
copy_v3_v3(prev_point, bData->realCoord[bData->s_pos[index]].v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Calculate current 3D-position and normal of each surface point
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
*/
|
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
|
|
|
|
|
float n1[3], n2[3], n3[3];
|
|
|
|
|
const ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data;
|
|
|
|
|
const PaintUVPoint *tPoint = &((PaintUVPoint *)f_data->uv_p)[index];
|
|
|
|
|
|
|
|
|
|
bData->s_num[index] = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
|
|
|
|
|
bData->s_pos[index] = index * bData->s_num[index];
|
|
|
|
|
|
|
|
|
|
/* per sample coordinates */
|
|
|
|
|
for (int ss = 0; ss < bData->s_num[index]; ss++) {
|
|
|
|
|
interp_v3_v3v3v3(bData->realCoord[bData->s_pos[index] + ss].v,
|
|
|
|
|
canvas_verts[tPoint->v1].v,
|
|
|
|
|
canvas_verts[tPoint->v2].v,
|
|
|
|
|
canvas_verts[tPoint->v3].v,
|
|
|
|
|
f_data->barycentricWeights[index * bData->s_num[index] + ss].v);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Calculate current pixel surface normal */
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
normal_short_to_float_v3(n1, mvert[tPoint->v1].no);
|
|
|
|
|
normal_short_to_float_v3(n2, mvert[tPoint->v2].no);
|
|
|
|
|
normal_short_to_float_v3(n3, mvert[tPoint->v3].no);
|
|
|
|
|
|
|
|
|
|
interp_v3_v3v3v3(temp_nor, n1, n2, n3, f_data->barycentricWeights[index * bData->s_num[index]].v);
|
|
|
|
|
normalize_v3(temp_nor);
|
|
|
|
|
if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
|
|
|
|
/* Prepare surface normal directional scale to easily convert
|
|
|
|
|
* brush intersection amount between global and local space */
|
|
|
|
|
float scaled_nor[3];
|
2019-02-18 15:43:06 +11:00
|
|
|
mul_v3_v3v3(scaled_nor, temp_nor, ob->scale);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bData->bNormal[index].normal_scale = len_v3(scaled_nor);
|
|
|
|
|
}
|
|
|
|
|
mul_mat3_m4_v3(ob->obmat, temp_nor);
|
|
|
|
|
normalize_v3(temp_nor);
|
|
|
|
|
negate_v3_v3(bData->bNormal[index].invNorm, temp_nor);
|
|
|
|
|
}
|
|
|
|
|
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
|
|
|
|
int ss;
|
|
|
|
|
if (surface->flags & MOD_DPAINT_ANTIALIAS && adj_data) {
|
|
|
|
|
bData->s_num[index] = adj_data->n_num[index] + 1;
|
|
|
|
|
bData->s_pos[index] = adj_data->n_index[index] + index;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bData->s_num[index] = 1;
|
|
|
|
|
bData->s_pos[index] = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate position for each sample */
|
|
|
|
|
for (ss = 0; ss < bData->s_num[index]; ss++) {
|
|
|
|
|
/* first sample is always point center */
|
|
|
|
|
copy_v3_v3(bData->realCoord[bData->s_pos[index] + ss].v, canvas_verts[index].v);
|
|
|
|
|
if (ss > 0) {
|
|
|
|
|
int t_index = adj_data->n_index[index] + (ss - 1);
|
|
|
|
|
/* get vertex position at 1/3 of each neigh edge */
|
|
|
|
|
mul_v3_fl(bData->realCoord[bData->s_pos[index] + ss].v, 2.0f / 3.0f);
|
|
|
|
|
madd_v3_v3fl(bData->realCoord[bData->s_pos[index] + ss].v,
|
|
|
|
|
canvas_verts[adj_data->n_target[t_index]].v, 1.0f / 3.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* normal */
|
|
|
|
|
normal_short_to_float_v3(temp_nor, mvert[index].no);
|
|
|
|
|
if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
|
|
|
|
|
/* Prepare surface normal directional scale to easily convert
|
|
|
|
|
* brush intersection amount between global and local space */
|
|
|
|
|
float scaled_nor[3];
|
2019-02-18 15:43:06 +11:00
|
|
|
mul_v3_v3v3(scaled_nor, temp_nor, ob->scale);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bData->bNormal[index].normal_scale = len_v3(scaled_nor);
|
|
|
|
|
}
|
|
|
|
|
mul_mat3_m4_v3(ob->obmat, temp_nor);
|
|
|
|
|
normalize_v3(temp_nor);
|
|
|
|
|
negate_v3_v3(bData->bNormal[index].invNorm, temp_nor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate speed vector */
|
|
|
|
|
if (do_velocity_data && !new_bdata && !bData->clear) {
|
|
|
|
|
sub_v3_v3v3(bData->velocity[index].v, bData->realCoord[bData->s_pos[index]].v, prev_point);
|
|
|
|
|
}
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Depsgraph *depsgraph, Object *ob)
|
2011-07-22 18:37:30 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
|
|
|
|
PaintBakeData *bData = sData->bData;
|
2018-09-24 16:32:29 +02:00
|
|
|
Mesh *mesh = surface->canvas->mesh;
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
int index;
|
|
|
|
|
bool new_bdata = false;
|
2016-05-12 12:08:03 +02:00
|
|
|
const bool do_velocity_data = ((surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) ||
|
2018-06-08 19:26:46 +02:00
|
|
|
(surface_getBrushFlags(surface, depsgraph) & BRUSH_USES_VELOCITY));
|
2016-05-12 12:08:03 +02:00
|
|
|
const bool do_accel_data = (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) != 0;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2018-09-24 16:32:29 +02:00
|
|
|
int canvasNumOfVerts = mesh->totvert;
|
|
|
|
|
MVert *mvert = mesh->mvert;
|
2011-07-22 18:37:30 +00:00
|
|
|
Vec3f *canvas_verts;
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
if (bData) {
|
2016-05-12 12:08:03 +02:00
|
|
|
const bool surface_moved = dynamicPaint_surfaceHasMoved(surface, ob);
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* get previous speed for accelertaion */
|
|
|
|
|
if (do_accel_data && bData->prev_velocity && bData->velocity)
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f));
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* reset speed vectors */
|
|
|
|
|
if (do_velocity_data && bData->velocity && (bData->clear || !surface_moved))
|
2012-05-12 16:11:34 +00:00
|
|
|
memset(bData->velocity, 0, sData->total_points * sizeof(Vec3f));
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* if previous data exists and mesh hasn't moved, no need to recalc */
|
|
|
|
|
if (!surface_moved)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
canvas_verts = (struct Vec3f *) MEM_mallocN(canvasNumOfVerts * sizeof(struct Vec3f), "Dynamic Paint transformed canvas verts");
|
2016-05-12 12:08:03 +02:00
|
|
|
if (!canvas_verts)
|
|
|
|
|
return 0;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* allocate memory if required */
|
2011-07-22 18:37:30 +00:00
|
|
|
if (!bData) {
|
|
|
|
|
sData->bData = bData = (struct PaintBakeData *) MEM_callocN(sizeof(struct PaintBakeData), "Dynamic Paint bake data");
|
|
|
|
|
if (!bData) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (canvas_verts)
|
|
|
|
|
MEM_freeN(canvas_verts);
|
2011-07-22 18:37:30 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Init bdata */
|
2012-05-12 16:11:34 +00:00
|
|
|
bData->bNormal = (struct PaintBakeNormal *) MEM_mallocN(sData->total_points * sizeof(struct PaintBakeNormal), "Dynamic Paint step data");
|
|
|
|
|
bData->s_pos = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_pos");
|
|
|
|
|
bData->s_num = MEM_mallocN(sData->total_points * sizeof(unsigned int), "Dynamic Paint bData s_num");
|
|
|
|
|
bData->realCoord = (struct Vec3f *) MEM_mallocN(surface_totalSamples(surface) * sizeof(Vec3f), "Dynamic Paint point coords");
|
|
|
|
|
bData->prev_verts = MEM_mallocN(canvasNumOfVerts * sizeof(MVert), "Dynamic Paint bData prev_verts");
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* if any allocation failed, free everything */
|
2011-07-22 18:37:30 +00:00
|
|
|
if (!bData->bNormal || !bData->s_pos || !bData->s_num || !bData->realCoord || !canvas_verts) {
|
2016-05-12 12:08:03 +02:00
|
|
|
if (bData->bNormal)
|
|
|
|
|
MEM_freeN(bData->bNormal);
|
|
|
|
|
if (bData->s_pos)
|
|
|
|
|
MEM_freeN(bData->s_pos);
|
|
|
|
|
if (bData->s_num)
|
|
|
|
|
MEM_freeN(bData->s_num);
|
|
|
|
|
if (bData->realCoord)
|
|
|
|
|
MEM_freeN(bData->realCoord);
|
|
|
|
|
if (canvas_verts)
|
|
|
|
|
MEM_freeN(canvas_verts);
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2012-10-26 17:32:50 +00:00
|
|
|
return setError(surface->canvas, N_("Not enough free memory"));
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
2011-08-03 18:31:48 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
new_bdata = true;
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_velocity_data && !bData->velocity) {
|
2012-05-12 16:11:34 +00:00
|
|
|
bData->velocity = (struct Vec3f *) MEM_callocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint velocity");
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
if (do_accel_data && !bData->prev_velocity) {
|
2012-05-12 16:11:34 +00:00
|
|
|
bData->prev_velocity = (struct Vec3f *) MEM_mallocN(sData->total_points * sizeof(Vec3f), "Dynamic Paint prev velocity");
|
2011-08-03 18:31:48 +00:00
|
|
|
/* copy previous vel */
|
|
|
|
|
if (bData->prev_velocity && bData->velocity)
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(bData->prev_velocity, bData->velocity, sData->total_points * sizeof(Vec3f));
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Make a transformed copy of canvas derived mesh vertices to avoid recalculation.
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
bData->mesh_bounds.valid = false;
|
2012-05-12 16:11:34 +00:00
|
|
|
for (index = 0; index < canvasNumOfVerts; index++) {
|
2011-10-28 14:46:09 +00:00
|
|
|
copy_v3_v3(canvas_verts[index].v, mvert[index].co);
|
2011-07-22 18:37:30 +00:00
|
|
|
mul_m4_v3(ob->obmat, canvas_verts[index].v);
|
2011-11-16 18:32:28 +00:00
|
|
|
boundInsert(&bData->mesh_bounds, canvas_verts[index].v);
|
2011-07-22 18:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-11-14 12:53:15 +11:00
|
|
|
* Prepare each surface point for a new step
|
2012-03-09 18:28:30 +00:00
|
|
|
*/
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
DynamicPaintGenerateBakeData data = {
|
|
|
|
|
.surface = surface, .ob = ob,
|
2016-06-19 06:25:54 +10:00
|
|
|
.mvert = mvert, .canvas_verts = canvas_verts,
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
.do_velocity_data = do_velocity_data, .new_bdata = new_bdata,
|
|
|
|
|
};
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_generate_bake_data_cb,
|
|
|
|
|
&settings);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-27 07:30:58 +00:00
|
|
|
MEM_freeN(canvas_verts);
|
2011-07-22 18:37:30 +00:00
|
|
|
|
|
|
|
|
/* generate surface space partitioning grid */
|
|
|
|
|
surfaceGenerateGrid(surface);
|
2012-01-24 17:28:50 +00:00
|
|
|
/* calculate current frame adjacency point distances and global dirs */
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_prepareAdjacencyData(surface, false);
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* Copy current frame vertices to check against in next frame */
|
2011-07-22 18:37:30 +00:00
|
|
|
copy_m4_m4(bData->prev_obmat, ob->obmat);
|
2012-05-12 16:11:34 +00:00
|
|
|
memcpy(bData->prev_verts, mvert, canvasNumOfVerts * sizeof(MVert));
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
bData->clear = 0;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
return 1;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* Do Dynamic Paint step. Paints scene brush objects of current state/frame to the surface.
|
|
|
|
|
*/
|
2018-05-31 12:27:47 +02:00
|
|
|
static int dynamicPaint_doStep(
|
2018-06-11 14:39:38 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene,
|
2018-05-31 12:27:47 +02:00
|
|
|
Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
|
|
|
|
PaintSurfaceData *sData = surface->data;
|
2011-07-22 18:37:30 +00:00
|
|
|
PaintBakeData *bData = sData->bData;
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas = surface->canvas;
|
2018-06-21 16:30:34 +02:00
|
|
|
const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
|
2011-06-27 07:30:58 +00:00
|
|
|
int ret = 1;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2016-05-12 12:08:03 +02:00
|
|
|
if (sData->total_points < 1)
|
|
|
|
|
return 0;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
if (dynamic_paint_surface_needs_dry_dissolve(surface)) {
|
2019-01-07 00:06:58 +11:00
|
|
|
DynamicPaintDissolveDryData data = { .surface = surface, .timescale = timescale, };
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
settings.use_threading = (sData->total_points > 1000);
|
|
|
|
|
BLI_task_parallel_range(0, sData->total_points,
|
|
|
|
|
&data,
|
|
|
|
|
dynamic_paint_surface_pre_step_cb,
|
|
|
|
|
&settings);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* Loop through surface's target paint objects and do painting
|
|
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2018-06-25 14:21:15 +02:00
|
|
|
unsigned int numobjects;
|
|
|
|
|
Object **objects = BKE_collision_objects_create(depsgraph, NULL, surface->brush_group, &numobjects, eModifierType_DynamicPaint);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
/* backup current scene frame */
|
|
|
|
|
int scene_frame = scene->r.cfra;
|
|
|
|
|
float scene_subframe = scene->r.subframe;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2018-06-25 14:21:15 +02:00
|
|
|
for (int i = 0; i < numobjects; i++) {
|
|
|
|
|
Object *brushObj = objects[i];
|
2016-05-12 12:08:03 +02:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* check if target has an active dp modifier */
|
2018-06-25 14:21:15 +02:00
|
|
|
ModifierData *md = modifiers_findByType(brushObj, eModifierType_DynamicPaint);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
|
2011-05-24 07:08:58 +00:00
|
|
|
DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)md;
|
2018-11-14 12:53:15 +11:00
|
|
|
/* make sure we're dealing with a brush */
|
2012-04-28 06:31:57 +00:00
|
|
|
if (pmd2->brush) {
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintBrushSettings *brush = pmd2->brush;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* calculate brush speed vectors if required */
|
2011-11-20 10:52:25 +00:00
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) {
|
2012-05-12 16:11:34 +00:00
|
|
|
bData->brush_velocity = MEM_callocN(sData->total_points * sizeof(float) * 4, "Dynamic Paint brush velocity");
|
2011-08-03 18:31:48 +00:00
|
|
|
/* init adjacency data if not already */
|
|
|
|
|
if (!sData->adj_data)
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_initAdjacencyData(surface, true);
|
2011-08-03 18:31:48 +00:00
|
|
|
if (!bData->bNeighs)
|
2016-05-12 12:08:03 +02:00
|
|
|
dynamicPaint_prepareAdjacencyData(surface, true);
|
2011-08-03 18:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* update object data on this subframe */
|
2011-06-16 10:41:00 +00:00
|
|
|
if (subframe) {
|
|
|
|
|
scene_setSubframe(scene, subframe);
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION,
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* Apply brush on the surface depending on it's collision type */
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (brush->psys && brush->psys->part &&
|
2018-04-21 20:42:27 +02:00
|
|
|
ELEM(brush->psys->part->type, PART_EMITTER, PART_FLUID) &&
|
2018-06-21 16:30:34 +02:00
|
|
|
psys_check_enabled(brushObj, brush->psys, for_render))
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
{
|
|
|
|
|
/* Paint a particle system */
|
|
|
|
|
dynamicPaint_paintParticles(surface, brush->psys, brush, timescale);
|
|
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
/* Object center distance: */
|
2016-06-21 12:14:49 +10:00
|
|
|
if (brush->collision == MOD_DPAINT_COL_POINT && brushObj != ob) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
dynamicPaint_paintSinglePoint(depsgraph, surface, brushObj->loc, brush, brushObj, scene, timescale);
|
2011-07-08 11:03:37 +00:00
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
/* Mesh volume/proximity: */
|
|
|
|
|
else if (brushObj != ob) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
dynamicPaint_paintMesh(depsgraph, surface, brush, brushObj, scene, timescale);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
/* reset object to it's original state */
|
2011-06-16 10:41:00 +00:00
|
|
|
if (subframe) {
|
|
|
|
|
scene->r.cfra = scene_frame;
|
|
|
|
|
scene->r.subframe = scene_subframe;
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION,
|
2016-05-12 12:08:03 +02:00
|
|
|
BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
2011-08-03 18:31:48 +00:00
|
|
|
|
|
|
|
|
/* process special brush effects, like smudge */
|
|
|
|
|
if (bData->brush_velocity) {
|
2011-11-20 10:52:25 +00:00
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE)
|
2011-08-04 07:09:21 +00:00
|
|
|
dynamicPaint_doSmudge(surface, brush, timescale);
|
2011-08-03 18:31:48 +00:00
|
|
|
MEM_freeN(bData->brush_velocity);
|
|
|
|
|
bData->brush_velocity = NULL;
|
|
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-25 14:21:15 +02:00
|
|
|
|
|
|
|
|
BKE_collision_objects_free(objects);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
/* surfaces operations that use adjacency data */
|
2012-03-07 04:53:43 +00:00
|
|
|
if (sData->adj_data && bData->bNeighs) {
|
2011-07-22 18:37:30 +00:00
|
|
|
/* wave type surface simulation step */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_WAVE) {
|
|
|
|
|
dynamicPaint_doWaveStep(surface, timescale);
|
|
|
|
|
}
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
/* paint surface effects */
|
2012-03-07 04:53:43 +00:00
|
|
|
if (surface->effect && surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
2011-07-22 18:37:30 +00:00
|
|
|
int steps = 1, s;
|
|
|
|
|
PaintPoint *prevPoint;
|
|
|
|
|
float *force = NULL;
|
2011-07-02 18:06:39 +00:00
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Allocate memory for surface previous points to read unchanged values from */
|
2012-05-12 16:11:34 +00:00
|
|
|
prevPoint = MEM_mallocN(sData->total_points * sizeof(struct PaintPoint), "PaintSurfaceDataCopy");
|
2011-08-03 18:31:48 +00:00
|
|
|
if (!prevPoint)
|
2012-10-26 17:32:50 +00:00
|
|
|
return setError(canvas, N_("Not enough free memory"));
|
2011-06-27 07:30:58 +00:00
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
/* Prepare effects and get number of required steps */
|
2018-04-06 12:07:27 +02:00
|
|
|
steps = dynamicPaint_prepareEffectStep(depsgraph, surface, scene, ob, &force, timescale);
|
2011-09-05 16:04:15 +00:00
|
|
|
for (s = 0; s < steps; s++) {
|
2011-08-03 18:31:48 +00:00
|
|
|
dynamicPaint_doEffectStep(surface, force, prevPoint, timescale, (float)steps);
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-14 12:53:15 +11:00
|
|
|
/* Free temporary effect data */
|
2016-05-12 12:08:03 +02:00
|
|
|
if (prevPoint)
|
|
|
|
|
MEM_freeN(prevPoint);
|
|
|
|
|
if (force)
|
|
|
|
|
MEM_freeN(force);
|
2011-07-02 18:06:39 +00:00
|
|
|
}
|
2017-01-03 18:50:15 +03:00
|
|
|
|
|
|
|
|
/* paint island border pixels */
|
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
|
dynamicPaint_doBorderStep(surface);
|
|
|
|
|
}
|
2011-06-27 07:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* Calculate a single frame and included subframes for surface
|
|
|
|
|
*/
|
2017-08-16 12:45:11 +10:00
|
|
|
int dynamicPaint_calculateFrame(
|
2018-04-06 12:07:27 +02:00
|
|
|
DynamicPaintSurface *surface, struct Depsgraph *depsgraph,
|
2017-08-16 12:45:11 +10:00
|
|
|
Scene *scene, Object *cObject, int frame)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2011-06-16 10:41:00 +00:00
|
|
|
float timescale = 1.0f;
|
2011-07-22 18:37:30 +00:00
|
|
|
|
2011-08-05 09:31:35 +00:00
|
|
|
/* apply previous displace on derivedmesh if incremental surface */
|
|
|
|
|
if (surface->flags & MOD_DPAINT_DISP_INCREMENTAL)
|
2018-09-24 16:32:29 +02:00
|
|
|
dynamicPaint_applySurfaceDisplace(surface, surface->canvas->mesh);
|
2011-08-05 09:31:35 +00:00
|
|
|
|
2011-07-22 18:37:30 +00:00
|
|
|
/* update bake data */
|
2018-06-08 19:26:46 +02:00
|
|
|
dynamicPaint_generateBakeData(surface, depsgraph, cObject);
|
DynamicPaint: massive refactor, replace all OpenMP usage by BLI_task and other optimizations.
This commit makes Dynamicpaint modifier evaluation (during playback) a few percents quicker.
However, it makes dynapaint's 'image sequence' baking about 33% quicker (from 119 to 77 seconds
in own heavy test), partly due to switch to BLI_task itself (about 20%), and partly due to
optimizations (remaining ~13%).
As usual, did a lot of tests here to ensure nothing is broken, but a lot more users' testing would definitively
be welcome too! ;)
Note that some quite meaningless omp forloops have been removed (parallelizing thousands of vec copy does
make it two or three times quicker, but the few hundreds of microseconds gained do not make any difference
in a hundreds millisecond process).
Also, this code could still use a lot more cleanup (naming etc.), the way it (tries to) handle malloc faults
is also totally flacky and makes the code horribly verbose and convoluted in some places - without actually
catching all possible faults (memarena could make it more easy to handle here), etc.
2016-05-21 15:22:04 +02:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* don't do substeps for first frame */
|
2011-06-16 10:41:00 +00:00
|
|
|
if (surface->substeps && (frame != surface->start_frame)) {
|
|
|
|
|
int st;
|
2012-05-12 16:11:34 +00:00
|
|
|
timescale = 1.0f / (surface->substeps + 1);
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
for (st = 1; st <= surface->substeps; st++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
float subframe = ((float) st) / (surface->substeps + 1);
|
2018-04-06 12:07:27 +02:00
|
|
|
if (!dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, subframe))
|
2016-05-12 12:08:03 +02:00
|
|
|
return 0;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
return dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, 0.0f);
|
2011-11-10 17:43:37 +00:00
|
|
|
}
|