Vertex Paint: use squared distance test
authorCampbell Barton <ideasman42@gmail.com>
Sun, 1 Oct 2017 13:44:04 +0000 (00:44 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 1 Oct 2017 13:44:04 +0000 (00:44 +1100)
Avoids sqrt for verts that are later ignored

source/blender/editors/sculpt_paint/paint_vertex.c

index 638a2616fc4a17bddc21ecf5fb6deabefc2d160d..ee7616b568237740ee7a34e1a2708a2f53307c31 100644 (file)
@@ -2360,7 +2360,7 @@ static void do_vpaint_brush_draw_task_cb_ex(
        BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
        {
                /* Test to see if the vertex coordinates are within the spherical brush region. */
-               if (sculpt_brush_test(&test, vd.co)) {
+               if (sculpt_brush_test_sq(&test, vd.co)) {
                        /* Note: Grids are 1:1 with corners (aka loops).
                         * For grid based pbvh, take the vert whose loop cooresponds to the current grid.
                         * Otherwise, take the current vert. */
@@ -2374,7 +2374,7 @@ static void do_vpaint_brush_draw_task_cb_ex(
                                 * (ie splash prevention factor), and only paint front facing verts. */
                                const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0;
                                if (view_dot > 0.0f) {
-                                       const float brush_fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
+                                       const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
                                        uint color_final = data->vpd->paintcol;
 
                                        /* If we're painting with a texture, sample the texture color and alpha. */
@@ -2451,7 +2451,7 @@ static void do_vpaint_brush_blur_task_cb_ex(
        BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
        {
                /* Test to see if the vertex coordinates are within the spherical brush region. */
-               if (sculpt_brush_test(&test, vd.co)) {
+               if (sculpt_brush_test_sq(&test, vd.co)) {
                        /* For grid based pbvh, take the vert whose loop cooresponds to the current grid. 
                         * Otherwise, take the current vert. */
                        const int v_index = ccgdm ? data->me->mloop[vd.grid_indices[vd.g]].v : vd.vert_indices[vd.i];
@@ -2460,7 +2460,7 @@ static void do_vpaint_brush_blur_task_cb_ex(
 
                        const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0;
                        if (view_dot > 0.0f) {
-                               const float brush_fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
+                               const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
 
                                /* If the vertex is selected for painting. */
                                if (!use_vert_sel || mv->flag & SELECT) {
@@ -2561,7 +2561,7 @@ static void do_vpaint_brush_smear_task_cb_ex(
                BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
                {
                        /* Test to see if the vertex coordinates are within the spherical brush region. */
-                       if (sculpt_brush_test(&test, vd.co)) {
+                       if (sculpt_brush_test_sq(&test, vd.co)) {
                                /* For grid based pbvh, take the vert whose loop cooresponds to the current grid.
                                 * Otherwise, take the current vert. */
                                const int v_index = ccgdm ? data->me->mloop[vd.grid_indices[vd.g]].v : vd.vert_indices[vd.i];
@@ -2574,7 +2574,7 @@ static void do_vpaint_brush_smear_task_cb_ex(
                                         * (ie splash prevention factor), and only paint front facing verts. */
                                        const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0;
                                        if (view_dot > 0.0f) {
-                                               const float brush_fade = BKE_brush_curve_strength(brush, test.dist, cache->radius);
+                                               const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
 
                                                bool do_color = false;
                                                /* Minimum dot product between brush direction and current