Commit: c2b1f2ae557ad81795bc98aa563da7860bf713c0
Author: Antony Riakiotakis
Date:   Fri Mar 7 18:13:11 2014 +0200
https://developer.blender.org/rBc2b1f2ae557ad81795bc98aa563da7860bf713c0

Deduplicate some gradient evaluation code

Fix: Fill tool in projection painting could still use secondary color

===================================================================

M       source/blender/editors/sculpt_paint/paint_image_2d.c
M       source/blender/editors/sculpt_paint/paint_image_proj.c
M       source/blender/editors/sculpt_paint/paint_intern.h
M       source/blender/editors/sculpt_paint/paint_utils.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c 
b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 26e50d2..7904ec9 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -296,32 +296,7 @@ static ImBuf *brush_painter_imbuf_new(BrushPainter 
*painter, int size, float pre
 
        /* get brush color */
        if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
-               if (painter->cache.invert)
-                       copy_v3_v3(brush_rgb, brush->secondary_rgb);
-               else {
-                       if (brush->flag & BRUSH_USE_GRADIENT) {
-                               switch (brush->gradient_stroke_mode) {
-                                       case BRUSH_GRADIENT_PRESSURE:
-                                               do_colorband(brush->gradient, 
pressure, brush_rgb);
-                                               break;
-                                       case BRUSH_GRADIENT_SPACING_REPEAT:
-                                       {
-                                               float coord = fmod(distance / 
brush->gradient_spacing, 1.0);
-                                               do_colorband(brush->gradient, 
coord, brush_rgb);
-                                               break;
-                                       }
-                                       case BRUSH_GRADIENT_SPACING_CLAMP:
-                                       {
-                                               do_colorband(brush->gradient, 
distance / brush->gradient_spacing, brush_rgb);
-                                               break;
-                                       }
-                               }
-                       }
-                       else
-                               copy_v3_v3(brush_rgb, brush->rgb);
-               }
-               if (use_color_correction)
-                       srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
+               paint_brush_color_get(brush, use_color_correction, 
painter->cache.invert, distance, pressure, brush_rgb);
        }
        else {
                brush_rgb[0] = 1.0f;
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 06f3c9a..60ffee1 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4344,33 +4344,14 @@ void paint_proj_stroke(const bContext *C, void *pps, 
const float prev_pos[2], co
        }
 
        /* handle gradient and inverted stroke color here */
-       if (ELEM(ps->tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) {
-               if (ps->mode == BRUSH_STROKE_INVERT)
-                       copy_v3_v3(ps->paint_color, brush->secondary_rgb);
-               else {
-                       if (brush->flag & BRUSH_USE_GRADIENT) {
-                               switch (brush->gradient_stroke_mode) {
-                                       case BRUSH_GRADIENT_PRESSURE:
-                                               do_colorband(brush->gradient, 
pressure, ps->paint_color);
-                                               break;
-                                       case BRUSH_GRADIENT_SPACING_REPEAT:
-                                       {
-                                               float coord = fmod(distance / 
brush->gradient_spacing, 1.0);
-                                               do_colorband(brush->gradient, 
coord, ps->paint_color);
-                                               break;
-                                       }
-                                       case BRUSH_GRADIENT_SPACING_CLAMP:
-                                       {
-                                               do_colorband(brush->gradient, 
distance / brush->gradient_spacing, ps->paint_color);
-                                               break;
-                                       }
-                               }
-                       }
-                       else
-                               copy_v3_v3(ps->paint_color, brush->rgb);
-
-                       srgb_to_linearrgb_v3_v3(ps->paint_color_linear, 
ps->paint_color);
-               }
+       if (ps->tool == PAINT_TOOL_DRAW) {
+               paint_brush_color_get(brush, false, ps->mode == 
BRUSH_STROKE_INVERT, distance, pressure,  ps->paint_color);
+               srgb_to_linearrgb_v3_v3(ps->paint_color_linear, 
ps->paint_color);
+       }
+       else if (ps->tool == PAINT_TOOL_FILL)
+       {
+               copy_v3_v3(ps->paint_color, brush->rgb);
+               srgb_to_linearrgb_v3_v3(ps->paint_color_linear, 
ps->paint_color);
        }
 
        /* continue adding to existing partial redraw rects until redraw */
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h 
b/source/blender/editors/sculpt_paint/paint_intern.h
index 7aa0248..0f35afa 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -211,6 +211,7 @@ void imapaint_pick_uv(struct Scene *scene, struct Object 
*ob, unsigned int facei
 void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void 
*customdata);
 
 void paint_sample_color(bContext *C, struct ARegion *ar, int x, int y, bool 
texpaint_proj, bool palette);
+void paint_brush_color_get(struct Brush *br, bool color_correction, bool 
invert, float distance, float pressure, float color[3]);
 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
 
 void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c 
b/source/blender/editors/sculpt_paint/paint_utils.c
index 0273d2a..f8f5bc7 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -54,6 +54,7 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_material.h"
 #include "BKE_paint.h"
+#include "BKE_texture.h"
 #include "BKE_report.h"
 #include "BKE_image.h"
 
@@ -497,6 +498,36 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, 
int y, bool texpaint_pr
        }
 }
 
+void paint_brush_color_get(struct Brush *br, bool color_correction, bool 
invert, float distance, float pressure, float color[3])
+{
+       if (invert)
+               copy_v3_v3(color, br->secondary_rgb);
+       else {
+               if (br->flag & BRUSH_USE_GRADIENT) {
+                       switch (br->gradient_stroke_mode) {
+                               case BRUSH_GRADIENT_PRESSURE:
+                                       do_colorband(br->gradient, pressure, 
color);
+                                       break;
+                               case BRUSH_GRADIENT_SPACING_REPEAT:
+                               {
+                                       float coord = fmod(distance / 
br->gradient_spacing, 1.0);
+                                       do_colorband(br->gradient, coord, 
color);
+                                       break;
+                               }
+                               case BRUSH_GRADIENT_SPACING_CLAMP:
+                               {
+                                       do_colorband(br->gradient, distance / 
br->gradient_spacing, color);
+                                       break;
+                               }
+                       }
+               }
+               else
+                       copy_v3_v3(color, br->rgb);
+       }
+       if (color_correction)
+               srgb_to_linearrgb_v3_v3(color, color);
+}
+
 static int brush_curve_preset_exec(bContext *C, wmOperator *op)
 {
        Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C));

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to