[Bf-blender-cvs] [de00b7e174c] temp-sculpt-cavity-mask: Merge branch 'master' into temp-sculpt-cavity-mask
Joseph Eagar
noreply at git.blender.org
Wed Jun 8 12:48:25 CEST 2022
Commit: de00b7e174cb19bdef22c73479b058f1e9fb6383
Author: Joseph Eagar
Date: Wed Jun 8 03:35:27 2022 -0700
Branches: temp-sculpt-cavity-mask
https://developer.blender.org/rBde00b7e174cb19bdef22c73479b058f1e9fb6383
Merge branch 'master' into temp-sculpt-cavity-mask
===================================================================
===================================================================
diff --cc source/blender/editors/sculpt_paint/sculpt_automasking.cc
index 7e9cc7897dc,94417defe48..b2ff961a89e
--- a/source/blender/editors/sculpt_paint/sculpt_automasking.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_automasking.cc
@@@ -51,20 -47,7 +51,9 @@@
#include <math.h>
#include <stdlib.h>
- /* Disable optimization for a function (for debugging use only!)*/
- #ifdef __clang__
- # define ATTR_NO_OPT __attribute__((optnone))
- #elif defined(_MSC_VER)
- # define ATTR_NO_OPT __pragma(optimize("", off))
- #elif defined(__GNUC__)
- # define ATTR_NO_OPT __attribute__((optimize("O0")))
- #else
- # define ATTR_NO_OPT
- #endif
-
using blender::IndexRange;
+using blender::Set;
+using blender::Vector;
AutomaskingCache *SCULPT_automasking_active_cache_get(SculptSession *ss)
{
@@@ -133,186 -114,6 +122,186 @@@ static bool SCULPT_automasking_needs_fa
return false;
}
+float SCULPT_calc_cavity(SculptSession *ss, const int vertex)
+{
+ SculptVertexNeighborIter ni;
+ const float *co = SCULPT_vertex_co_get(ss, vertex);
+ float avg[3];
+ float elen = 0.0f;
+ float e_num = 0.0f;
+
+ zero_v3(avg);
+
+ SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vertex, ni) {
+ const float *co2 = SCULPT_vertex_co_get(ss, ni.index);
+
+ elen += len_v3v3(co, co2);
+ e_num += 1.0f;
+ add_v3_v3(avg, co2);
+ }
+ SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
+
+ if (e_num == 0.0f) {
+ return 0.0f;
+ }
+
+ mul_v3_fl(avg, 1.0f / (float)e_num);
+ elen /= e_num;
+
+ float no[3];
+
+ SCULPT_vertex_normal_get(ss, vertex, no);
+
+ sub_v3_v3(avg, co);
+
+ /* Use distance to plane. */
+ float factor = dot_v3v3(avg, no) / elen;
+
+ return factor;
+}
+
- ATTR_NO_OPT static float sculpt_automasking_cavity_factor_intern(SculptSession *ss,
++static float sculpt_automasking_cavity_factor_intern(SculptSession *ss,
+ AutomaskingCache *automasking,
+ int vert)
+{
+ float factor = SCULPT_calc_cavity(ss, vert);
+ float sign = signf(factor);
+
+ factor = fabsf(factor) * automasking->settings.cavity_factor * 50.0f;
+
+ factor = factor * sign * 0.5f + 0.5f;
+ CLAMP(factor, 0.0f, 1.0f);
+
+ return (automasking->settings.flags & BRUSH_AUTOMASKING_CAVITY_INVERT) ? 1.0f - factor : factor;
+}
+
+struct CavityBlurVert {
+ int vertex;
+ float dist;
+ int depth;
+
+ CavityBlurVert(int vertex_, float dist_, int depth_)
+ : vertex(vertex_), dist(dist_), depth(depth_)
+ {
+ }
+
+ CavityBlurVert()
+ {
+ }
+
+ CavityBlurVert(const CavityBlurVert &b)
+ {
+ vertex = b.vertex;
+ dist = b.dist;
+ depth = b.depth;
+ }
+};
+
+ATTR_NO_OPT static void sculpt_calc_blurred_cavity(SculptSession *ss,
+ AutomaskingCache *automasking,
+ int steps,
+ int vertex)
+{
+ if (steps == 0) {
+ ss->cavity_factor[vertex] = sculpt_automasking_cavity_factor_intern(ss, automasking, vertex);
+ ss->cavity_stroke_id[vertex] = ss->stroke_id;
+
+ return;
+ }
+
+ Vector<CavityBlurVert, 64> queue;
+ Set<int, 64> visit;
+
+ int start = 0, end = 0;
+
+ queue.resize(64);
+
+ CavityBlurVert initial(vertex, 0.0f, 0);
+
+ visit.add_new(vertex);
+ queue[0] = initial;
+ end = 1;
+
+ float f_sum = 0.0f;
+ int f_num = 0;
+
+ f_sum += sculpt_automasking_cavity_factor_intern(ss, automasking, vertex);
+ f_num++;
+
+ while (start != end) {
+ CavityBlurVert &blurvert = queue[start];
+ int v = blurvert.vertex;
+ start = (start + 1) % queue.size();
+
+ if (blurvert.depth >= steps) {
+ break;
+ }
+
+ SculptVertexNeighborIter ni;
+ SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, v, ni) {
+ int v2 = ni.index;
+
+ if (visit.contains(v2)) {
+ continue;
+ }
+
+ float dist = len_v3v3(SCULPT_vertex_co_get(ss, v2), SCULPT_vertex_co_get(ss, v));
+
+ f_sum += sculpt_automasking_cavity_factor_intern(ss, automasking, v2);
+ f_num++;
+
+ visit.add_new(v2);
+ CavityBlurVert blurvert2(v2, dist, blurvert.depth + 1);
+
+ int nextend = (end + 1) % queue.size();
+
+ if (nextend == start) {
+ int oldsize = queue.size();
+
+ queue.resize(queue.size() << 1);
+
+ if (end < start) {
+ int n = oldsize - start;
+
+ for (int i = 0; i < n; i++) {
+ queue[queue.size() - n + i] = queue[i + start];
+ }
+
+ start = queue.size() - n;
+ }
+ }
+
+ queue[end] = blurvert2;
+ end = (end + 1) % queue.size();
+ }
+ SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
+ }
+
+ if (f_num != 0.0f) {
+ f_sum /= f_num;
+ }
+
+ ss->cavity_factor[vertex] = f_sum;
+ ss->cavity_stroke_id[vertex] = ss->stroke_id;
+}
+
+ATTR_NO_OPT static float sculpt_automasking_cavity_factor(AutomaskingCache *automasking,
+ SculptSession *ss,
+ int vertex)
+{
+ if (ss->cavity_stroke_id[vertex] != ss->stroke_id) {
+ sculpt_calc_blurred_cavity(ss, automasking, automasking->settings.cavity_blur_steps, vertex);
+ }
+
+ float factor = ss->cavity_factor[vertex];
+
+ if (automasking->settings.flags & BRUSH_AUTOMASKING_CAVITY_USE_CURVE) {
+ factor = BKE_curvemapping_evaluateF(automasking->settings.cavity_curve, 0, factor);
+ }
+
+ return factor;
+}
+
float SCULPT_automasking_factor_get(AutomaskingCache *automasking, SculptSession *ss, int vert)
{
if (!automasking) {
More information about the Bf-blender-cvs
mailing list