Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_smooth.c
| Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| CLAMP(bstrength, 0.0f, 1.0f); | CLAMP(bstrength, 0.0f, 1.0f); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor( | const float fade = bstrength * SCULPT_brush_strength_factor( | ||||
| ss, | ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f), | smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f), | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| if (smooth_mask) { | if (smooth_mask) { | ||||
| float val = SCULPT_neighbor_mask_average(ss, vd.vert_indices[vd.i]) - *vd.mask; | float val = SCULPT_neighbor_mask_average(ss, vd.vert_indices[vd.i]) - *vd.mask; | ||||
| val *= fade * bstrength; | val *= fade * bstrength; | ||||
| *vd.mask += val; | *vd.mask += val; | ||||
| CLAMP(*vd.mask, 0.0f, 1.0f); | CLAMP(*vd.mask, 0.0f, 1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| float avg[3], val[3]; | float avg[3], val[3]; | ||||
| Show All 27 Lines | static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| CLAMP(bstrength, 0.0f, 1.0f); | CLAMP(bstrength, 0.0f, 1.0f); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor(ss, | const float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| smooth_mask ? 0.0f : *vd.mask, | smooth_mask ? 0.0f : *vd.mask, | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| if (smooth_mask) { | if (smooth_mask) { | ||||
| float val = SCULPT_neighbor_mask_average(ss, vd.index) - *vd.mask; | float val = SCULPT_neighbor_mask_average(ss, vd.index) - *vd.mask; | ||||
| val *= fade * bstrength; | val *= fade * bstrength; | ||||
| *vd.mask += val; | *vd.mask += val; | ||||
| CLAMP(*vd.mask, 0.0f, 1.0f); | CLAMP(*vd.mask, 0.0f, 1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| float avg[3], val[3]; | float avg[3], val[3]; | ||||
| Show All 28 Lines | static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| CLAMP(bstrength, 0.0f, 1.0f); | CLAMP(bstrength, 0.0f, 1.0f); | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = bstrength * SCULPT_brush_strength_factor( | const float fade = bstrength * SCULPT_brush_strength_factor( | ||||
| ss, | ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| sqrtf(test.dist), | sqrtf(test.dist), | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f), | smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f), | ||||
| vd.index, | vd.index, | ||||
| tls->thread_id); | thread_id); | ||||
| if (smooth_mask) { | if (smooth_mask) { | ||||
| float val = SCULPT_neighbor_mask_average(ss, vd.index) - *vd.mask; | float val = SCULPT_neighbor_mask_average(ss, vd.index) - *vd.mask; | ||||
| val *= fade * bstrength; | val *= fade * bstrength; | ||||
| *vd.mask += val; | *vd.mask += val; | ||||
| CLAMP(*vd.mask, 0.0f, 1.0f); | CLAMP(*vd.mask, 0.0f, 1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| float avg[3], val[3]; | float avg[3], val[3]; | ||||
| Show All 40 Lines | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .smooth_mask = smooth_mask, | .smooth_mask = smooth_mask, | ||||
| .strength = strength, | .strength = strength, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| switch (type) { | switch (type) { | ||||
| case PBVH_GRIDS: | case PBVH_GRIDS: | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings); | ||||
| break; | break; | ||||
| case PBVH_FACES: | case PBVH_FACES: | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_mesh_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_mesh_task_cb_ex, &settings); | ||||
| break; | break; | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, do_smooth_brush_bmesh_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_bmesh_task_cb_ex, &settings); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void SCULPT_do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | void SCULPT_do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| { | { | ||||
| SculptSession *ss = ob->sculpt; | SculptSession *ss = ob->sculpt; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static void SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex( | ||||
| float alpha = brush->surface_smooth_shape_preservation; | float alpha = brush->surface_smooth_shape_preservation; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptOrigVertData orig_data; | SculptOrigVertData orig_data; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); | ||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| SCULPT_orig_vert_data_update(&orig_data, &vd); | SCULPT_orig_vert_data_update(&orig_data, &vd); | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = | const float fade = | ||||
| bstrength * | bstrength * | ||||
| SCULPT_brush_strength_factor( | SCULPT_brush_strength_factor( | ||||
| ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, tls->thread_id); | ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, thread_id); | ||||
| float disp[3]; | float disp[3]; | ||||
| SCULPT_surface_smooth_laplacian_step(ss, | SCULPT_surface_smooth_laplacian_step(ss, | ||||
| disp, | disp, | ||||
| vd.co, | vd.co, | ||||
| ss->cache->surface_smooth_laplacian_disp, | ss->cache->surface_smooth_laplacian_disp, | ||||
| vd.index, | vd.index, | ||||
| orig_data.co, | orig_data.co, | ||||
| Show All 16 Lines | static void SCULPT_do_surface_smooth_brush_displace_task_cb_ex( | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| const float beta = brush->surface_smooth_current_vertex; | const float beta = brush->surface_smooth_current_vertex; | ||||
| PBVHVertexIter vd; | PBVHVertexIter vd; | ||||
| SculptBrushTest test; | SculptBrushTest test; | ||||
| SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape( | ||||
| ss, &test, data->brush->falloff_shape); | ss, &test, data->brush->falloff_shape); | ||||
| const int thread_id = BLI_task_parallel_thread_id(tls); | |||||
| BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| { | { | ||||
| if (sculpt_brush_test_sq_fn(&test, vd.co)) { | if (sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| const float fade = | const float fade = | ||||
| bstrength * | bstrength * | ||||
| SCULPT_brush_strength_factor( | SCULPT_brush_strength_factor( | ||||
| ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, tls->thread_id); | ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, thread_id); | ||||
| SCULPT_surface_smooth_displace_step( | SCULPT_surface_smooth_displace_step( | ||||
| ss, vd.co, ss->cache->surface_smooth_laplacian_disp, vd.index, beta, fade); | ss, vd.co, ss->cache->surface_smooth_laplacian_disp, vd.index, beta, fade); | ||||
| } | } | ||||
| } | } | ||||
| BKE_pbvh_vertex_iter_end; | BKE_pbvh_vertex_iter_end; | ||||
| } | } | ||||
| void SCULPT_do_surface_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | void SCULPT_do_surface_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| Show All 11 Lines | void SCULPT_do_surface_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) | ||||
| /* Threaded loop over nodes. */ | /* Threaded loop over nodes. */ | ||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .brush = brush, | .brush = brush, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | BKE_pbvh_parallel_range_settings(&settings, (sd->flags & SCULPT_USE_OPENMP), totnode); | ||||
| for (int i = 0; i < brush->surface_smooth_iterations; i++) { | for (int i = 0; i < brush->surface_smooth_iterations; i++) { | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &data, SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex, &settings); | 0, totnode, &data, SCULPT_do_surface_smooth_brush_laplacian_task_cb_ex, &settings); | ||||
| BKE_pbvh_parallel_range( | BLI_task_parallel_range( | ||||
| 0, totnode, &data, SCULPT_do_surface_smooth_brush_displace_task_cb_ex, &settings); | 0, totnode, &data, SCULPT_do_surface_smooth_brush_displace_task_cb_ex, &settings); | ||||
| } | } | ||||
| } | } | ||||