Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_paint_color.c
| Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | static void do_color_smooth_task_cb_exec(void *__restrict userdata, | ||||
| 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); | const int thread_id = BLI_task_parallel_thread_id(tls); | ||||
| AutomaskingNodeData automask_data; | |||||
| SCULPT_automasking_node_begin( | |||||
| data->ob, ss, ss->cache->automasking, &automask_data, 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) { | ||||
| if (!sculpt_brush_test_sq_fn(&test, vd.co)) { | if (!sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| SCULPT_automasking_node_update(ss, &automask_data, &vd); | |||||
| 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, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.vertex, | vd.vertex, | ||||
| thread_id); | thread_id, | ||||
| &automask_data); | |||||
| float smooth_color[4]; | float smooth_color[4]; | ||||
| SCULPT_neighbor_color_average(ss, smooth_color, vd.vertex); | SCULPT_neighbor_color_average(ss, smooth_color, vd.vertex); | ||||
| float col[4]; | float col[4]; | ||||
| SCULPT_vertex_color_get(ss, vd.vertex, col); | SCULPT_vertex_color_get(ss, vd.vertex, col); | ||||
| blend_color_interpolate_float(col, col, smooth_color, fade); | blend_color_interpolate_float(col, col, smooth_color, fade); | ||||
| SCULPT_vertex_color_set(ss, vd.vertex, col); | SCULPT_vertex_color_set(ss, vd.vertex, col); | ||||
| Show All 26 Lines | static void do_paint_brush_task_cb_ex(void *__restrict userdata, | ||||
| float brush_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | float brush_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | ||||
| copy_v3_v3(brush_color, | copy_v3_v3(brush_color, | ||||
| ss->cache->invert ? BKE_brush_secondary_color_get(ss->scene, brush) : | ss->cache->invert ? BKE_brush_secondary_color_get(ss->scene, brush) : | ||||
| BKE_brush_color_get(ss->scene, brush)); | BKE_brush_color_get(ss->scene, brush)); | ||||
| IMB_colormanagement_srgb_to_scene_linear_v3(brush_color, brush_color); | IMB_colormanagement_srgb_to_scene_linear_v3(brush_color, brush_color); | ||||
| AutomaskingNodeData automask_data; | |||||
| SCULPT_automasking_node_begin( | |||||
| data->ob, ss, ss->cache->automasking, &automask_data, data->nodes[n]); | |||||
| if (brush->flag & BRUSH_USE_GRADIENT) { | if (brush->flag & BRUSH_USE_GRADIENT) { | ||||
| switch (brush->gradient_stroke_mode) { | switch (brush->gradient_stroke_mode) { | ||||
| case BRUSH_GRADIENT_PRESSURE: | case BRUSH_GRADIENT_PRESSURE: | ||||
| BKE_colorband_evaluate(brush->gradient, ss->cache->pressure, brush_color); | BKE_colorband_evaluate(brush->gradient, ss->cache->pressure, brush_color); | ||||
| break; | break; | ||||
| case BRUSH_GRADIENT_SPACING_REPEAT: { | case BRUSH_GRADIENT_SPACING_REPEAT: { | ||||
| float coord = fmod(ss->cache->stroke_distance / brush->gradient_spacing, 1.0); | float coord = fmod(ss->cache->stroke_distance / brush->gradient_spacing, 1.0); | ||||
| BKE_colorband_evaluate(brush->gradient, coord, brush_color); | BKE_colorband_evaluate(brush->gradient, coord, brush_color); | ||||
| Show All 20 Lines | else { | ||||
| affect_vertex = sculpt_brush_test_sq_fn(&test, vd.co); | affect_vertex = sculpt_brush_test_sq_fn(&test, vd.co); | ||||
| distance_to_stroke_location = sqrtf(test.dist); | distance_to_stroke_location = sqrtf(test.dist); | ||||
| } | } | ||||
| if (!affect_vertex) { | if (!affect_vertex) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| SCULPT_automasking_node_update(ss, &automask_data, &vd); | |||||
| float fade = bstrength * SCULPT_brush_strength_factor(ss, | float fade = bstrength * SCULPT_brush_strength_factor(ss, | ||||
| brush, | brush, | ||||
| vd.co, | vd.co, | ||||
| distance_to_stroke_location, | distance_to_stroke_location, | ||||
| vd.no, | vd.no, | ||||
| vd.fno, | vd.fno, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.vertex, | vd.vertex, | ||||
| thread_id); | thread_id, | ||||
| &automask_data); | |||||
| /* Density. */ | /* Density. */ | ||||
| float noise = 1.0f; | float noise = 1.0f; | ||||
| const float density = ss->cache->paint_brush.density; | const float density = ss->cache->paint_brush.density; | ||||
| if (density < 1.0f) { | if (density < 1.0f) { | ||||
| const float hash_noise = (float)BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index); | const float hash_noise = (float)BLI_hash_int_01(ss->cache->density_seed * 1000 * vd.index); | ||||
| if (hash_noise > density) { | if (hash_noise > density) { | ||||
| noise = density * hash_noise; | noise = density * hash_noise; | ||||
| Show All 9 Lines | BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { | ||||
| mul_v4_v4fl(paint_color, brush_color, fade * ss->cache->paint_brush.flow); | mul_v4_v4fl(paint_color, brush_color, fade * ss->cache->paint_brush.flow); | ||||
| mul_v4_v4fl(wet_mix_color, data->wet_mix_sampled_color, fade * ss->cache->paint_brush.flow); | mul_v4_v4fl(wet_mix_color, data->wet_mix_sampled_color, fade * ss->cache->paint_brush.flow); | ||||
| /* Interpolate with the wet_mix color for wet paint mixing. */ | /* Interpolate with the wet_mix color for wet paint mixing. */ | ||||
| blend_color_interpolate_float( | blend_color_interpolate_float( | ||||
| paint_color, paint_color, wet_mix_color, ss->cache->paint_brush.wet_mix); | paint_color, paint_color, wet_mix_color, ss->cache->paint_brush.wet_mix); | ||||
| blend_color_mix_float(color_buffer->color[vd.i], color_buffer->color[vd.i], paint_color); | blend_color_mix_float(color_buffer->color[vd.i], color_buffer->color[vd.i], paint_color); | ||||
| /* Final mix over the original color using brush alpha. */ | /* Final mix over the original color using brush alpha. We apply auto-making again | ||||
| mul_v4_v4fl(buffer_color, color_buffer->color[vd.i], brush->alpha); | * at this point to avoid washing out non-binary masking modes like cavity masking. */ | ||||
| float automasking = SCULPT_automasking_factor_get( | |||||
| ss->cache->automasking, ss, vd.vertex, &automask_data); | |||||
| mul_v4_v4fl(buffer_color, color_buffer->color[vd.i], brush->alpha * automasking); | |||||
| float col[4]; | float col[4]; | ||||
| SCULPT_vertex_color_get(ss, vd.vertex, col); | SCULPT_vertex_color_get(ss, vd.vertex, col); | ||||
| IMB_blend_color_float(col, orig_data.col, buffer_color, brush->blend); | IMB_blend_color_float(col, orig_data.col, buffer_color, brush->blend); | ||||
| CLAMP4(col, 0.0f, 1.0f); | CLAMP4(col, 0.0f, 1.0f); | ||||
| SCULPT_vertex_color_set(ss, vd.vertex, col); | SCULPT_vertex_color_set(ss, vd.vertex, col); | ||||
| } | } | ||||
| BKE_pbvh_vertex_iter_end; | BKE_pbvh_vertex_iter_end; | ||||
| ▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | SculptThreadedTaskData data = { | ||||
| .mat = mat, | .mat = mat, | ||||
| }; | }; | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BLI_task_parallel_range(0, totnode, &data, do_paint_brush_task_cb_ex, &settings); | BLI_task_parallel_range(0, totnode, &data, do_paint_brush_task_cb_ex, &settings); | ||||
| } | } | ||||
| void SCULPT_paint_batches_flush(PaintModeSettings *paint_mode_settings, Sculpt *sd, Object *ob) | |||||
| { | |||||
| if (!SCULPT_use_image_paint_brush(paint_mode_settings, ob)) { | |||||
| return; | |||||
| } | |||||
| SCULPT_paint_image_batches_flush(paint_mode_settings, sd, ob); | |||||
| } | |||||
| static void do_smear_brush_task_cb_exec(void *__restrict userdata, | static void do_smear_brush_task_cb_exec(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict tls) | const TaskParallelTLS *__restrict tls) | ||||
| { | { | ||||
| SculptThreadedTaskData *data = userdata; | SculptThreadedTaskData *data = userdata; | ||||
| SculptSession *ss = data->ob->sculpt; | SculptSession *ss = data->ob->sculpt; | ||||
| const Brush *brush = data->brush; | const Brush *brush = data->brush; | ||||
| const float bstrength = ss->cache->bstrength; | const float bstrength = ss->cache->bstrength; | ||||
| Show All 9 Lines | static void do_smear_brush_task_cb_exec(void *__restrict userdata, | ||||
| if (brush->flag & BRUSH_ANCHORED) { | if (brush->flag & BRUSH_ANCHORED) { | ||||
| copy_v3_v3(brush_delta, ss->cache->grab_delta_symmetry); | copy_v3_v3(brush_delta, ss->cache->grab_delta_symmetry); | ||||
| } | } | ||||
| else { | else { | ||||
| sub_v3_v3v3(brush_delta, ss->cache->location, ss->cache->last_location); | sub_v3_v3v3(brush_delta, ss->cache->location, ss->cache->last_location); | ||||
| } | } | ||||
| AutomaskingNodeData automask_data; | |||||
| SCULPT_automasking_node_begin( | |||||
| data->ob, ss, ss->cache->automasking, &automask_data, 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) { | ||||
| if (!sculpt_brush_test_sq_fn(&test, vd.co)) { | if (!sculpt_brush_test_sq_fn(&test, vd.co)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| SCULPT_automasking_node_update(ss, &automask_data, &vd); | |||||
| 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, | ||||
| vd.mask ? *vd.mask : 0.0f, | vd.mask ? *vd.mask : 0.0f, | ||||
| vd.vertex, | vd.vertex, | ||||
| thread_id); | thread_id, | ||||
| &automask_data); | |||||
| float current_disp[3]; | float current_disp[3]; | ||||
| float current_disp_norm[3]; | float current_disp_norm[3]; | ||||
| float interp_color[4]; | float interp_color[4]; | ||||
| copy_v4_v4(interp_color, ss->cache->prev_colors[vd.index]); | copy_v4_v4(interp_color, ss->cache->prev_colors[vd.index]); | ||||
| float no[3]; | float no[3]; | ||||
| SCULPT_vertex_normal_get(ss, vd.vertex, no); | SCULPT_vertex_normal_get(ss, vd.vertex, no); | ||||
| ▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines | |||||