Commit: 0997eff30c4583ede4b38f73b0978e5aaa924ee0 Author: Pablo Dobarro Date: Tue Jul 2 15:32:47 2019 +0200 Branches: sculpt-mode-features https://developer.blender.org/rB0997eff30c4583ede4b38f73b0978e5aaa924ee0
Sculpt vertex colors: add color blend modes to the paint brush This makes all color blend modes available from the paint mode dropdown. Source alpha is currently hardcoded to 1 to avoid confusion. The viewport can't display it properly. =================================================================== M source/blender/editors/sculpt_paint/sculpt.c M source/blender/makesdna/DNA_brush_types.h M source/blender/makesrna/intern/rna_brush.c =================================================================== diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 549bcbd505e..43d4f837b0b 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -32,6 +32,7 @@ #include "BLI_ghash.h" #include "BLI_stack.h" #include "BLI_gsqueue.h" +#include "BLI_math_color_blend.h" #include "BLT_translation.h" @@ -2684,15 +2685,83 @@ static void apply_color(SculptSession *ss, PBVHVertexIter *vd, const Brush *brus { float factor = ss->cache ? fade * fabs(ss->cache->bstrength) : fade; CLAMP(factor, 0.0f, 1.0f); - char r = brush->rgb[0] * 255; - char g = brush->rgb[1] * 255; - char b = brush->rgb[2] * 255; - - char brushColor[4] = {r, g, b, 0}; - /* TODO (Pablo): Implement proper blend modes */ - vd->col->r = vd->col->r * (1 - factor) + brushColor[0] * factor; - vd->col->g = vd->col->g * (1 - factor) + brushColor[1] * factor; - vd->col->b = vd->col->b * (1 - factor) + brushColor[2] * factor; + unsigned char r = brush->rgb[0] * 255; + unsigned char g = brush->rgb[1] * 255; + unsigned char b = brush->rgb[2] * 255; + unsigned char a = factor * 255; + unsigned char brushColor[4] = {r, g, b, a}; + unsigned char *col = (unsigned char *)vd->col; + switch (brush->sculpt_color_mix_mode) { + case BRUSH_SCULPT_COLOR_MIX: + blend_color_mix_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_ADD: + blend_color_add_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_SUB: + blend_color_sub_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_MUL: + blend_color_mul_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_LIGHTEN: + blend_color_lighten_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_DARKEN: + blend_color_darken_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_ERASE_ALPHA: + blend_color_erase_alpha_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_ADD_ALPHA: + blend_color_add_alpha_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_OVERLAY: + blend_color_overlay_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_HARDLIGHT: + blend_color_hardlight_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_BURN: + blend_color_burn_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_LINEARBURN: + blend_color_linearburn_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_DODGE: + blend_color_dodge_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_SCREEN: + blend_color_screen_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_SOFTLIGHT: + blend_color_softlight_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_PINLIGHT: + blend_color_pinlight_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_LINEARLIGHT: + blend_color_linearlight_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_VIVIDLIGHT: + blend_color_vividlight_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_DIFFERENCE: + blend_color_difference_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_EXCLUSION: + blend_color_exclusion_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_COLOR: + blend_color_color_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_HUE: + blend_color_hue_byte(col, col, brushColor); + break; + case BRUSH_SCULPT_COLOR_LUMINOSITY: + blend_color_luminosity_byte(col, col, brushColor); + break; + } } static void do_paint_brush_task_cb_ex(void *__restrict userdata, diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index ed415edea44..395407ca2e1 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -207,6 +207,28 @@ typedef enum eAutomaskingMode { typedef enum eSculptColorMode { BRUSH_SCULPT_COLOR_NONE = 0, BRUSH_SCULPT_COLOR_MIX = 1, + BRUSH_SCULPT_COLOR_ADD = 2, + BRUSH_SCULPT_COLOR_SUB = 3, + BRUSH_SCULPT_COLOR_MUL = 4, + BRUSH_SCULPT_COLOR_LIGHTEN = 5, + BRUSH_SCULPT_COLOR_DARKEN = 6, + BRUSH_SCULPT_COLOR_ERASE_ALPHA = 7, + BRUSH_SCULPT_COLOR_ADD_ALPHA = 8, + BRUSH_SCULPT_COLOR_OVERLAY = 9, + BRUSH_SCULPT_COLOR_HARDLIGHT = 10, + BRUSH_SCULPT_COLOR_BURN = 11, + BRUSH_SCULPT_COLOR_LINEARBURN = 12, + BRUSH_SCULPT_COLOR_DODGE = 13, + BRUSH_SCULPT_COLOR_SCREEN = 14, + BRUSH_SCULPT_COLOR_SOFTLIGHT = 15, + BRUSH_SCULPT_COLOR_PINLIGHT = 16, + BRUSH_SCULPT_COLOR_LINEARLIGHT = 17, + BRUSH_SCULPT_COLOR_VIVIDLIGHT = 18, + BRUSH_SCULPT_COLOR_DIFFERENCE = 19, + BRUSH_SCULPT_COLOR_EXCLUSION = 20, + BRUSH_SCULPT_COLOR_COLOR = 21, + BRUSH_SCULPT_COLOR_HUE = 22, + BRUSH_SCULPT_COLOR_LUMINOSITY = 23, } eSculptColorMode; typedef struct Brush { diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 4f1b4d4f9be..4a2e283e1e9 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -1586,6 +1586,27 @@ static void rna_def_brush(BlenderRNA *brna) static const EnumPropertyItem brush_sculpt_color_mix_mode_items[] = { {BRUSH_SCULPT_COLOR_NONE, "NONE", 0, "Disabled", ""}, {BRUSH_SCULPT_COLOR_MIX, "MIX", 0, "Mix", ""}, + {BRUSH_SCULPT_COLOR_ADD, "ADD", 0, "Add", ""}, + {BRUSH_SCULPT_COLOR_SUB, "SUB", 0, "Substract", ""}, + {BRUSH_SCULPT_COLOR_MUL, "MUL", 0, "Multiply", ""}, + {BRUSH_SCULPT_COLOR_LIGHTEN, "LIGHTEN", 0, "Lighten", ""}, + {BRUSH_SCULPT_COLOR_ERASE_ALPHA, "ERASEALPHA", 0, "Erase Alpha", ""}, + {BRUSH_SCULPT_COLOR_ADD_ALPHA, "ADDALPHA", 0, "Add Alpha", ""}, + {BRUSH_SCULPT_COLOR_OVERLAY, "OVERLAY", 0, "Overlay", ""}, + {BRUSH_SCULPT_COLOR_HARDLIGHT, "HARDLIGHT", 0, "Hard Light", ""}, + {BRUSH_SCULPT_COLOR_BURN, "BURN", 0, "Burn", ""}, + {BRUSH_SCULPT_COLOR_LINEARBURN, "LINEARBURN", 0, "Linear Burn", ""}, + {BRUSH_SCULPT_COLOR_DODGE, "DODGE", 0, "Dodge", ""}, + {BRUSH_SCULPT_COLOR_SCREEN, "SCREEN", 0, "Screen", ""}, + {BRUSH_SCULPT_COLOR_SOFTLIGHT, "SOFTLIGHT", 0, "Soft Light", ""}, + {BRUSH_SCULPT_COLOR_PINLIGHT, "PINLIGHT", 0, "Pin Light", ""}, + {BRUSH_SCULPT_COLOR_LINEARLIGHT, "LINEARLIGHT", 0, "Linear Light", ""}, + {BRUSH_SCULPT_COLOR_VIVIDLIGHT, "VIVIDLIGHT", 0, "Vivid Light", ""}, + {BRUSH_SCULPT_COLOR_DIFFERENCE, "DIFFERENCE", 0, "Difference", ""}, + {BRUSH_SCULPT_COLOR_EXCLUSION, "EXCLUSION", 0, "Exclusion", ""}, + {BRUSH_SCULPT_COLOR_COLOR, "COLOR", 0, "Color", ""}, + {BRUSH_SCULPT_COLOR_HUE, "HUE", 0, "Hue", ""}, + {BRUSH_SCULPT_COLOR_LUMINOSITY, "LUMINOSITY", 0, "Luminosity", ""}, {0, NULL, 0, NULL, NULL}, }; _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs