[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59967] branches/soc-2013-paint/source/ blender/editors/sculpt_paint: Implementation of gradient fill tool for projective texturing with same

Antony Riakiotakis kalast at gmail.com
Mon Sep 9 21:49:08 CEST 2013


Revision: 59967
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59967
Author:   psy-fi
Date:     2013-09-09 19:49:07 +0000 (Mon, 09 Sep 2013)
Log Message:
-----------
Implementation of gradient fill tool for projective texturing with same
restrictions as regular fill tool currently (only part of mesh inside
camera is filled)

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c

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-09-09 19:06:44 UTC (rev 59966)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-09-09 19:49:07 UTC (rev 59967)
@@ -744,6 +744,12 @@
 			if (pop->mode == PAINT_MODE_2D) {
 				paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
 			}
+			else {
+				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0);
+				/* two redraws, one for GPU update, one for notification */
+				paint_proj_redraw(C, pop->custom_paint, false);
+				paint_proj_redraw(C, pop->custom_paint, true);
+			}
 		}
 		else {
 			if (pop->mode == PAINT_MODE_2D) {
@@ -751,7 +757,8 @@
 
 				srgb_to_linearrgb_v3_v3(color, brush->rgb);
 				paint_2d_bucket_fill(C, color);
-			} else {
+			}
+			else {
 				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, 1.0, 0.0);
 				/* two redraws, one for GPU update, one for notification */
 				paint_proj_redraw(C, pop->custom_paint, false);

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-09-09 19:06:44 UTC (rev 59966)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-09-09 19:49:07 UTC (rev 59967)
@@ -4061,21 +4061,63 @@
 
 				/* fill tools */
 				if (ps->source == PROJ_SRC_VIEW_FILL) {
-					if (is_floatbuf) {
-						float newColor_f[4];
-						newColor_f[3] = ((float)projPixel->mask) * (1.0f / 65535.0f);
-						copy_v3_v3(newColor_f, ps->paint_color_linear);
+					if (brush->flag & BRUSH_USE_GRADIENT) {
+						/* these could probably be cached instead of being done per pixel */
+						float tangent[2];
+						float line_len_sq_inv, line_len;
+						float f;
+						float color_f[4];
+						float p[2] = {projPixel->projCoSS[0] - lastpos[0], projPixel->projCoSS[1] - lastpos[1]};
 
-						blend_color_mix_float(projPixel->pixel.f_pt,  projPixel->origColor.f_pt,
-						                      newColor_f);
+						sub_v2_v2v2(tangent, pos, lastpos);
+						line_len = len_squared_v2(tangent);
+						line_len_sq_inv = 1.0/line_len;
+						line_len = sqrt(line_len);
+
+						switch (brush->gradient_fill_mode) {
+							case BRUSH_GRADIENT_LINEAR:
+							{
+								f = dot_v2v2(p, tangent)*line_len_sq_inv;
+								break;
+							}
+							case BRUSH_GRADIENT_RADIAL:
+							{
+								f = len_v2(p)/line_len;
+								break;
+							}
+						}
+						do_colorband(brush->gradient, f, color_f);
+						color_f[3] *= ((float)projPixel->mask) * (1.0f / 65535.0f);
+
+						if (is_floatbuf) {
+							/* convert to premultipied */
+							mul_v3_fl(color_f, color_f[3]);
+							blend_color_mix_float(projPixel->pixel.f_pt,  projPixel->origColor.f_pt,
+							                      color_f);
+						}
+						else {
+							rgba_float_to_uchar(projPixel->newColor.ch, color_f);
+							blend_color_mix_byte(projPixel->pixel.ch_pt,  projPixel->origColor.ch_pt,
+							                     projPixel->newColor.ch);
+						}
 					}
 					else {
-						float mask = ((float)projPixel->mask) * (1.0f / 65535.0f);
-						projPixel->newColor.ch[3] = mask * 255;
+						if (is_floatbuf) {
+							float newColor_f[4];
+							newColor_f[3] = ((float)projPixel->mask) * (1.0f / 65535.0f);
+							copy_v3_v3(newColor_f, ps->paint_color_linear);
 
-						rgb_float_to_uchar(projPixel->newColor.ch, ps->paint_color);
-						blend_color_mix_byte(projPixel->pixel.ch_pt,  projPixel->origColor.ch_pt,
-						                     projPixel->newColor.ch);
+							blend_color_mix_float(projPixel->pixel.f_pt,  projPixel->origColor.f_pt,
+							                      newColor_f);
+						}
+						else {
+							float mask = ((float)projPixel->mask) * (1.0f / 65535.0f);
+							projPixel->newColor.ch[3] = mask * 255;
+
+							rgb_float_to_uchar(projPixel->newColor.ch, ps->paint_color);
+							blend_color_mix_byte(projPixel->pixel.ch_pt,  projPixel->origColor.ch_pt,
+							                     projPixel->newColor.ch);
+						}
 					}
 
 					last_partial_redraw_cell = last_projIma->partRedrawRect + projPixel->bb_cell_index;




More information about the Bf-blender-cvs mailing list