Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt_filter_color.c
| Show All 36 Lines | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_mapping.h" | #include "BKE_mesh_mapping.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_pbvh.h" | #include "BKE_pbvh.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "IMB_colormanagement.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "WM_toolsystem.h" | #include "WM_toolsystem.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_sculpt.h" | #include "ED_sculpt.h" | ||||
| #include "paint_intern.h" | #include "paint_intern.h" | ||||
| #include "sculpt_intern.h" | #include "sculpt_intern.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "bmesh.h" | #include "bmesh.h" | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| typedef enum eSculptColorFilterTypes { | typedef enum eSculptColorFilterTypes { | ||||
| COLOR_FILTER_FILL, | |||||
| COLOR_FILTER_HUE, | COLOR_FILTER_HUE, | ||||
| COLOR_FILTER_SATURATION, | COLOR_FILTER_SATURATION, | ||||
| COLOR_FILTER_VALUE, | COLOR_FILTER_VALUE, | ||||
| COLOR_FILTER_BRIGHTNESS, | COLOR_FILTER_BRIGHTNESS, | ||||
| COLOR_FILTER_CONTRAST, | COLOR_FILTER_CONTRAST, | ||||
| COLOR_FILTER_RED, | COLOR_FILTER_RED, | ||||
| COLOR_FILTER_GREEN, | COLOR_FILTER_GREEN, | ||||
| COLOR_FILTER_BLUE, | COLOR_FILTER_BLUE, | ||||
| COLOR_FILTER_SMOOTH, | COLOR_FILTER_SMOOTH, | ||||
| } eSculptColorFilterTypes; | } eSculptColorFilterTypes; | ||||
| EnumPropertyItem prop_color_filter_types[] = { | EnumPropertyItem prop_color_filter_types[] = { | ||||
| {COLOR_FILTER_FILL, "FILL", 0, "Fill", "Fill with a specific color"}, | |||||
| {COLOR_FILTER_HUE, "HUE", 0, "Hue", "Change hue"}, | {COLOR_FILTER_HUE, "HUE", 0, "Hue", "Change hue"}, | ||||
| {COLOR_FILTER_SATURATION, "SATURATION", 0, "Saturation", "Change saturation"}, | {COLOR_FILTER_SATURATION, "SATURATION", 0, "Saturation", "Change saturation"}, | ||||
| {COLOR_FILTER_VALUE, "VALUE", 0, "Value", "Change value"}, | {COLOR_FILTER_VALUE, "VALUE", 0, "Value", "Change value"}, | ||||
| {COLOR_FILTER_BRIGHTNESS, "BRIGTHNESS", 0, "Brightness", "Change brightness"}, | {COLOR_FILTER_BRIGHTNESS, "BRIGTHNESS", 0, "Brightness", "Change brightness"}, | ||||
| {COLOR_FILTER_CONTRAST, "CONTRAST", 0, "Contrast", "Change contrast"}, | {COLOR_FILTER_CONTRAST, "CONTRAST", 0, "Contrast", "Change contrast"}, | ||||
| {COLOR_FILTER_SMOOTH, "SMOOTH", 0, "Smooth", "Smooth colors"}, | {COLOR_FILTER_SMOOTH, "SMOOTH", 0, "Smooth", "Smooth colors"}, | ||||
| Show All 25 Lines | BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) | ||||
| float brightness, contrast, gain, delta, offset; | float brightness, contrast, gain, delta, offset; | ||||
| float fade = vd.mask ? *vd.mask : 0.0f; | float fade = vd.mask ? *vd.mask : 0.0f; | ||||
| fade = 1.0f - fade; | fade = 1.0f - fade; | ||||
| fade *= data->filter_strength; | fade *= data->filter_strength; | ||||
| copy_v3_v3(orig_color, orig_data.col); | copy_v3_v3(orig_color, orig_data.col); | ||||
| switch (mode) { | switch (mode) { | ||||
| case COLOR_FILTER_FILL: { | |||||
| float fill_color_rgba[4]; | |||||
| copy_v3_v3(fill_color_rgba, data->filter_fill_color); | |||||
| fill_color_rgba[3] = 1.0f; | |||||
| CLAMP(fade, 0.0f, 1.0f); | |||||
| mul_v4_fl(fill_color_rgba, fade); | |||||
| blend_color_mix_float(final_color, orig_data.col, fill_color_rgba); | |||||
| break; | |||||
| } | |||||
| case COLOR_FILTER_HUE: | case COLOR_FILTER_HUE: | ||||
| rgb_to_hsv_v(orig_color, hsv_color); | rgb_to_hsv_v(orig_color, hsv_color); | ||||
| hue = hsv_color[0] + fade; | hue = hsv_color[0] + fade; | ||||
| hsv_color[0] = fabs((hsv_color[0] + fade) - hue); | hsv_color[0] = fabs((hsv_color[0] + fade) - hue); | ||||
| hsv_to_rgb_v(hsv_color, final_color); | hsv_to_rgb_v(hsv_color, final_color); | ||||
| break; | break; | ||||
| case COLOR_FILTER_SATURATION: | case COLOR_FILTER_SATURATION: | ||||
| rgb_to_hsv_v(orig_color, hsv_color); | rgb_to_hsv_v(orig_color, hsv_color); | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| if (event->type != MOUSEMOVE) { | if (event->type != MOUSEMOVE) { | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| float len = event->prevclickx - event->mval[0]; | float len = event->prevclickx - event->mval[0]; | ||||
| filter_strength = filter_strength * -len * 0.001f; | filter_strength = filter_strength * -len * 0.001f; | ||||
| float fill_color[3]; | |||||
| RNA_float_get_array(op->ptr, "fill_color", fill_color); | |||||
| IMB_colormanagement_srgb_to_scene_linear_v3(fill_color); | |||||
| SculptThreadedTaskData data = { | SculptThreadedTaskData data = { | ||||
| .sd = sd, | .sd = sd, | ||||
| .ob = ob, | .ob = ob, | ||||
| .nodes = ss->filter_cache->nodes, | .nodes = ss->filter_cache->nodes, | ||||
| .filter_type = mode, | .filter_type = mode, | ||||
| .filter_strength = filter_strength, | .filter_strength = filter_strength, | ||||
| .filter_fill_color = fill_color, | |||||
| }; | }; | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); | BKE_pbvh_parallel_range_settings(&settings, true, ss->filter_cache->totnode); | ||||
| BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, color_filter_task_cb, &settings); | BLI_task_parallel_range(0, ss->filter_cache->totnode, &data, color_filter_task_cb, &settings); | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | void SCULPT_OT_color_filter(struct wmOperatorType *ot) | ||||
| ot->poll = SCULPT_mode_poll; | ot->poll = SCULPT_mode_poll; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* rna */ | /* rna */ | ||||
| RNA_def_enum(ot->srna, "type", prop_color_filter_types, COLOR_FILTER_HUE, "Filter type", ""); | RNA_def_enum(ot->srna, "type", prop_color_filter_types, COLOR_FILTER_HUE, "Filter type", ""); | ||||
| RNA_def_float( | RNA_def_float( | ||||
| ot->srna, "strength", 1.0f, -10.0f, 10.0f, "Strength", "Filter Strength", -10.0f, 10.0f); | ot->srna, "strength", 1.0f, -10.0f, 10.0f, "Strength", "Filter Strength", -10.0f, 10.0f); | ||||
| PropertyRNA *prop = RNA_def_float_color( | |||||
| ot->srna, "fill_color", 3, NULL, 0.0f, FLT_MAX, "Fill Color", "fill color", 0.0f, 1.0f); | |||||
| RNA_def_property_subtype(prop, PROP_COLOR_GAMMA); | |||||
| } | } | ||||