[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59062] branches/soc-2013-paint/source/ blender: Gradient stroke guided by pressure for 2d and projective texturing .

Antony Riakiotakis kalast at gmail.com
Sun Aug 11 12:35:12 CEST 2013


Revision: 59062
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59062
Author:   psy-fi
Date:     2013-08-11 10:35:11 +0000 (Sun, 11 Aug 2013)
Log Message:
-----------
Gradient stroke guided by pressure for 2d and projective texturing.

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h

Modified: branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c	2013-08-11 08:29:56 UTC (rev 59061)
+++ branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c	2013-08-11 10:35:11 UTC (rev 59062)
@@ -1850,7 +1850,7 @@
 }
 
 /* ************ READ Palette *************** */
-static void lib_link_palette(FileData *fd, Main *main)
+static void lib_link_palette(FileData *UNUSED(fd), Main *main)
 {
 	Palette *palette;
 

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-08-11 08:29:56 UTC (rev 59061)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-08-11 10:35:11 UTC (rev 59062)
@@ -554,6 +554,19 @@
 	ViewContext vc;
 } PaintOperation;
 
+bool paint_use_opacity_masking(Brush *brush)
+{
+	return ((brush->flag & BRUSH_AIRBRUSH) ||
+	        (brush->flag & BRUSH_DRAG_DOT) ||
+	        (brush->flag & BRUSH_ANCHORED) ||
+	        (brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
+	        (brush->flag & BRUSH_USE_GRADIENT) ||
+	        (brush->mtex.tex && !ELEM3(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ||
+	        brush->flag & BRUSH_ACCUMULATE) ?
+				false : true;
+}
+
+
 void paint_brush_init_tex(Brush *brush)
 {
 	/* init mtex nodes */
@@ -689,10 +702,10 @@
 	}
 
 	if (pop->mode == PAINT_MODE_3D_PROJECT) {
-		paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse);
+		paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse, pressure);
 	}
 	else {
-		paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser);
+		paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure);
 	}
 
 	pop->prevmouse[0] = mouse[0];

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-08-11 08:29:56 UTC (rev 59061)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-08-11 10:35:11 UTC (rev 59062)
@@ -86,6 +86,7 @@
 	float lastjitter;
 	float last_tex_rotation;
 	float last_mask_rotation;
+	float last_pressure;
 
 	ImBuf *ibuf;
 	ImBuf *texibuf;
@@ -266,7 +267,7 @@
 
 
 /* create imbuf with brush color */
-static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size)
+static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size, float pressure)
 {
 	Scene *scene = painter->scene;
 	Brush *brush = painter->brush;
@@ -295,9 +296,19 @@
 	if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
 		if (painter->cache.invert_color)
 			copy_v3_v3(brush_rgb, brush->secondary_rgb);
-		else
-			copy_v3_v3(brush_rgb, brush->rgb);
-
+		else {
+			if (brush->flag & BRUSH_USE_GRADIENT) {
+				switch (brush->gradient_source) {
+					case BRUSH_GRADIENT_PRESSURE:
+						do_colorband(brush->gradient, pressure, brush_rgb);
+						break;
+					case BRUSH_GRADIENT_SPACING:
+						break;
+				}
+			}
+			else
+				copy_v3_v3(brush_rgb, brush->rgb);
+		}
 		if (use_color_correction)
 			srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
 	}
@@ -581,7 +592,7 @@
 	}
 }
 
-static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2], const float mouse[2])
+static void brush_painter_2d_refresh_cache(ImagePaintState *s, BrushPainter *painter, const float pos[2], const float mouse[2], float pressure)
 {
 	const Scene *scene = painter->scene;
 	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
@@ -594,6 +605,9 @@
 	bool do_random = false;
 	bool do_partial_update = false;
 	bool do_view = false;
+	bool update_color = (brush->flag & BRUSH_USE_GRADIENT) &&
+	                    ((brush->gradient_source == BRUSH_GRADIENT_SPACING)
+	                     || (cache->last_pressure != pressure));
 	float tex_rotation = -brush->mtex.rot;
 	float mask_rotation = -brush->mask_mtex.rot;
 
@@ -605,7 +619,7 @@
 		}
 		else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM)
 			do_random = true;
-		else if (!(brush->flag & BRUSH_ANCHORED))
+		else if (!(brush->flag & BRUSH_ANCHORED) || update_color)
 			do_partial_update = true;
 
 		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos, mouse,
@@ -682,7 +696,8 @@
 	    brush->jitter != cache->lastjitter ||
 	    tex_rotation != cache->last_tex_rotation ||
 	    mask_rotation != cache->last_mask_rotation ||
-	    do_random)
+	    do_random ||
+	    update_color)
 	{
 		if (cache->ibuf) {
 			IMB_freeImBuf(cache->ibuf);
@@ -695,7 +710,7 @@
 		}
 		else {
 			/* create brush and mask from scratch */
-			cache->ibuf = brush_painter_imbuf_new(painter, size);
+			cache->ibuf = brush_painter_imbuf_new(painter, size, pressure);
 		}
 
 		cache->lastsize = diameter;
@@ -703,6 +718,7 @@
 		cache->lastjitter = brush->jitter;
 		cache->last_tex_rotation = tex_rotation;
 		cache->last_mask_rotation = mask_rotation;
+		cache->last_pressure = pressure;
 	}
 	else if (do_partial_update) {
 		/* do only partial update of texture */
@@ -1063,13 +1079,7 @@
 	}
 
 	/* set masking */
-	s->do_masking = ((s->brush->flag & BRUSH_AIRBRUSH) ||
-	                 (s->brush->flag & BRUSH_DRAG_DOT) ||
-	                 (s->brush->flag & BRUSH_ANCHORED) ||
-	                 (s->brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
-	                 (s->brush->mtex.tex && !ELEM3(s->brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ||
-	                 s->brush->flag & BRUSH_ACCUMULATE)
-	                 ? false : true;
+	s->do_masking = paint_use_opacity_masking(s->brush);
 	
 	return 1;
 }
@@ -1083,7 +1093,7 @@
 		image_undo_remove_masks();
 }
 
-void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser)
+void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser, float pressure)
 {
 	float newuv[2], olduv[2];
 	ImagePaintState *s = ps;
@@ -1128,7 +1138,7 @@
 	 */
 	brush_painter_2d_require_imbuf(painter, (ibuf->rect_float != NULL), !is_data, s->do_masking);
 
-	brush_painter_2d_refresh_cache(s, painter, newuv, mval);
+	brush_painter_2d_refresh_cache(s, painter, newuv, mval, pressure);
 
 	if (paint_2d_op(s, painter->cache.ibuf, painter->cache.curve_mask, painter->cache.max_mask, olduv, newuv))
 		s->need_redraw = true;

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-08-11 08:29:56 UTC (rev 59061)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-08-11 10:35:11 UTC (rev 59062)
@@ -59,6 +59,7 @@
 #include "DNA_object_types.h"
 
 #include "BKE_camera.h"
+#include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
@@ -73,7 +74,7 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
-#include "BKE_colortools.h"
+#include "BKE_texture.h"
 
 #include "BKE_editmesh.h"
 
@@ -191,6 +192,8 @@
 
 	/* the paint color. It can change depending of interted mode or not */
 	float paint_color[3];
+	float paint_color_linear[3];
+	bool invert_color;
 
 	Brush *brush;
 	short tool, blend, mode;
@@ -3935,7 +3938,7 @@
 {
 	float rgba[4];
 
-	srgb_to_linearrgb_v3_v3(rgba, ps->paint_color);
+	copy_v3_v3(rgba, ps->paint_color_linear);
 
 	if (ps->is_texbrush)
 		mul_v3_v3(rgba, texrgb);
@@ -4306,9 +4309,10 @@
 }
 
 
-void paint_proj_stroke(bContext *C, void *pps, const float prev_pos[2], const float pos[2])
+void paint_proj_stroke(bContext *C, void *pps, const float prev_pos[2], const float pos[2], float pressure)
 {
 	ProjPaintState *ps = pps;
+	Brush *brush = ps->brush;
 	int a;
 
 	/* clone gets special treatment here to avoid going through image initialization */
@@ -4328,6 +4332,26 @@
 		return;
 	}
 
+	if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
+		if (ps->invert_color)
+			copy_v3_v3(ps->paint_color, brush->secondary_rgb);
+		else {
+			if (brush->flag & BRUSH_USE_GRADIENT) {
+				switch (brush->gradient_source) {
+					case BRUSH_GRADIENT_PRESSURE:
+						do_colorband(brush->gradient, pressure, ps->paint_color);
+						break;
+					case BRUSH_GRADIENT_SPACING:
+						break;
+				}
+			}
+			else
+				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 */
 	if (!ps->need_redraw) {
 		for (a = 0; a < ps->image_tot; a++)
@@ -4354,13 +4378,7 @@
 		ps->blend = brush->blend;
 
 		/* disable for 3d mapping also because painting on mirrored mesh can create "stripes" */
-		ps->do_masking = ((brush->flag & BRUSH_AIRBRUSH) ||
-	                      (brush->flag & BRUSH_DRAG_DOT) ||
-	                      (brush->flag & BRUSH_ANCHORED) ||
-		                  (brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
-		                  (brush->mtex.tex && !ELEM3(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_3D)) ||
-		                  brush->flag & BRUSH_ACCUMULATE)
-		                 ? false : true;
+		ps->do_masking = paint_use_opacity_masking(brush);
 		ps->is_texbrush = (brush->mtex.tex && brush->imagepaint_tool == PAINT_TOOL_DRAW) ? true : false;
 		ps->is_maskbrush = (brush->mask_mtex.tex)? true : false;
 	}
@@ -4416,10 +4434,9 @@
 		ps->do_mask_normal = FALSE;  /* no need to do blending */
 
 	if (ps->tool == PAINT_TOOL_DRAW) {
-		if (mode == BRUSH_STROKE_INVERT)
-			copy_v3_v3(ps->paint_color, ps->brush->secondary_rgb);
-		else
-			copy_v3_v3(ps->paint_color, ps->brush->rgb);
+		if (mode == BRUSH_STROKE_INVERT) {
+			ps->invert_color = true;
+		}
 	}
 	return;
 }

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-08-11 08:29:56 UTC (rev 59061)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-08-11 10:35:11 UTC (rev 59062)
@@ -157,13 +157,15 @@

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list