[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47617] branches/soc-2012-bratwurst/source /blender: Texture rake brushes for texture paint mode

Antony Riakiotakis kalast at gmail.com
Fri Jun 8 18:26:56 CEST 2012


Revision: 47617
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47617
Author:   psy-fi
Date:     2012-06-08 16:26:46 +0000 (Fri, 08 Jun 2012)
Log Message:
-----------
Texture rake brushes for texture paint mode
===========================================
* Reading into the code, i am starting to get the hang of what is going
on :)
* I disabled the texture rake for projection paint because it didn't
work too well (will check why next). I suspect a sampling offset issue.
So I started implementing rake brushes for regular non-projective
texturing and uv/image viewwer. This commit makes this work :). I will
probably have to move the rotation part from the BKE_brush_sample_tex
function and modify the coordinates directly. This will ensure that for
projective or even fixed mode texturing this will work as expected (?)

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-08 16:17:57 UTC (rev 47616)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-08 16:26:46 UTC (rev 47617)
@@ -69,7 +69,7 @@
 /* sampling */
 void BKE_brush_sample_tex(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], const int thread, float angle);
 void BKE_brush_imbuf_new(const struct Scene *scene, struct Brush *brush, short flt, short texfalloff, int size,
-                         struct ImBuf **imbuf, int use_color_correction);
+                         struct ImBuf **imbuf, float angle, int use_color_correction);
 
 /* painting */
 struct BrushPainter;

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-08 16:17:57 UTC (rev 47616)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-08 16:26:46 UTC (rev 47617)
@@ -496,18 +496,25 @@
 		int hasrgb;
 		const int radius = BKE_brush_size_get(scene, brush);
 
+		co[0] = xy[0] / radius;
+		co[1] = xy[1] / radius;
+		co[2] = 0.0f;
+
+		/*
 		co[0] = ((xy[0] - radius/2) / radius);
 		co[1] = ((xy[1] - radius/2) / radius);
 		co[2] = 0.0f;
+		*/
+		if(fabs(angle) > 0.0001) {
+			length = normalize_v2(co);
+			co_angle = acos(co[0]);
+			co_angle = (co[1] > 0)? co_angle : - co_angle;
 
-		length = normalize_v2(co);
-		co_angle = acos(co[0]);
-		co_angle = (co[1] > 0)? co_angle : - co_angle;
+			co_angle -= angle;
+			co[0] = cos(co_angle)*length;
+			co[1] = sin(co_angle)*length;
+		}
 
-		co_angle -= angle;
-		co[0] = cos(co_angle)*length + 0.5;
-		co[1] = sin(co_angle)*length + 0.5;
-
 		hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread);
 
 		if (hasrgb) {
@@ -529,7 +536,7 @@
 }
 
 /* TODO, use define for 'texfall' arg */
-void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
+void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, float angle, int use_color_correction)
 {
 	ImBuf *ibuf;
 	float xy[2], rgba[4], *dstf;
@@ -567,10 +574,10 @@
 					dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
 				else if (texfall == 1) {
-					BKE_brush_sample_tex(scene, brush, xy, dstf, 0, 0);
+					BKE_brush_sample_tex(scene, brush, xy, dstf, 0, angle);
 				}
 				else {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
 					mul_v3_v3v3(dstf, rgba, brush_rgb);
 					dstf[3] = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 				}
@@ -597,11 +604,11 @@
 					dst[3] = FTOCHAR(alpha_f);
 				}
 				else if (texfall == 1) {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
 					rgba_float_to_uchar(dst, rgba);
 				}
 				else if (texfall == 2) {
-					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, 0);
+					BKE_brush_sample_tex(scene, brush, xy, rgba, 0, angle);
 					mul_v3_v3(rgba, brush->rgb);
 					alpha_f = rgba[3] *alpha *BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
@@ -773,6 +780,7 @@
 	int lastsize;
 	float lastalpha;
 	float lastjitter;
+	float lastrotation;
 
 	ImBuf *ibuf;
 	ImBuf *texibuf;
@@ -793,6 +801,7 @@
 	double lasttime;        /* time of last update */
 
 	float lastpressure;
+	float rotation;
 
 	short firsttouch;       /* first paint op */
 
@@ -1016,10 +1025,12 @@
 	short flt;
 	const int diameter = 2 * BKE_brush_size_get(scene, brush);
 	const float alpha = BKE_brush_alpha_get(scene, brush);
+	const float rotation = painter->rotation;
 
 	if (diameter != cache->lastsize ||
 	    alpha != cache->lastalpha ||
-	    brush->jitter != cache->lastjitter)
+	    brush->jitter != cache->lastjitter ||
+	    rotation != cache->lastrotation)
 	{
 		if (cache->ibuf) {
 			IMB_freeImBuf(cache->ibuf);
@@ -1034,15 +1045,16 @@
 		size = (cache->size) ? cache->size : diameter;
 
 		if (brush->flag & BRUSH_FIXED_TEX) {
-			BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction);
+			BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, rotation, use_color_correction);
 			brush_painter_fixed_tex_partial_update(painter, pos);
 		}
 		else
-			BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction);
+			BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, rotation, use_color_correction);
 
 		cache->lastsize = diameter;
 		cache->lastalpha = alpha;
 		cache->lastjitter = brush->jitter;
+		cache->lastrotation = rotation;
 	}
 	else if ((brush->flag & BRUSH_FIXED_TEX) && mtex && mtex->tex) {
 		int dx = (int)painter->lastpaintpos[0] - (int)pos[0];
@@ -1124,6 +1136,7 @@
 		painter->firsttouch = 0;
 		painter->lastpaintpos[0] = pos[0];
 		painter->lastpaintpos[1] = pos[1];
+		painter->rotation = 0;
 	}
 #if 0
 	else if (painter->brush->flag & BRUSH_AIRBRUSH) {
@@ -1175,6 +1188,14 @@
 		len = normalize_v2(dmousepos);
 		painter->accumdistance += len;
 
+		if(brush->flag & BRUSH_RAKE) {
+			if(len > 0.001) {
+				float angle;
+				angle = acos(dmousepos[0]);
+				painter->rotation = (dmousepos[1] > 0)? angle : -angle;
+			}
+		}
+
 		if (brush->flag & BRUSH_SPACE) {
 			/* do paint op over unpainted distance */
 			while ((len > 0.0f) && (painter->accumdistance >= spacing)) {

Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-08 16:17:57 UTC (rev 47616)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-08 16:26:46 UTC (rev 47617)
@@ -141,12 +141,6 @@
 
 static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint);
 
-
-typedef struct BrushRotationState {
-		float last_orientation[2]; /* orientation in screen space*/
-		float last_angle; /* last angle, stores angle to */
-} BrushRotationState;
-
 typedef struct ImagePaintState {
 	SpaceImage *sima;
 	View2D *v2d;
@@ -267,7 +261,6 @@
 
 	Brush *brush;
 	short tool, blend;
-	BrushRotationState rotation_state;
 	Object *ob;
 	/* end similarities with ImagePaintState */
 	
@@ -3410,13 +3403,6 @@
 		ps->cloneOffset[0] = mouse[0] - ((float)(ps->winx / 2.0f) + (ps->winx / 2.0f) * projCo[0] / projCo[3]);
 		ps->cloneOffset[1] = mouse[1] - ((float)(ps->winy / 2.0f) + (ps->winy / 2.0f) * projCo[1] / projCo[3]);
 	}
-
-	/* reset rake state */
-	if(ps->brush && ps->brush->flag & BRUSH_RAKE) {
-		ps->rotation_state.last_angle = 0.0;
-		ps->rotation_state.last_orientation[0] = 1.0;
-		ps->rotation_state.last_orientation[0] = 0.0;
-	}
 }	
 
 static void project_paint_end(ProjPaintState *ps)
@@ -3936,7 +3922,7 @@
 					if (falloff > 0.0f) {
 						if (ps->is_texbrush) {
 							/* note, for clone and smear, we only use the alpha, could be a special function */
-							BKE_brush_sample_tex(ps->scene, ps->brush, projPixel->projCoSS, rgba, thread_index, ps->rotation_state.last_angle);
+							BKE_brush_sample_tex(ps->scene, ps->brush, projPixel->projCoSS, rgba, thread_index, 0);
 							alpha = rgba[3];
 						}
 						else {
@@ -4056,21 +4042,6 @@
 		return 0;
 	}
 
-	if(ps->brush->flag & BRUSH_RAKE) {
-		float mdiff[2];
-
-		sub_v2_v2v2(mdiff, pos, lastpos);
-
-		if(len_v2(mdiff) > 0.001) {
-			float angle;
-			normalize_v2(mdiff);
-			angle = acos(mdiff[0]);
-			ps->rotation_state.last_orientation[0] = mdiff[0];
-			ps->rotation_state.last_orientation[0] = mdiff[1];
-			ps->rotation_state.last_angle = (mdiff[1] > 0)? angle : -angle;
-		}
-	}
-
 	if (ps->thread_tot > 1)
 		BLI_init_threads(&threads, do_projectpaint_thread, ps->thread_tot);
 	




More information about the Bf-blender-cvs mailing list