[Bf-blender-cvs] [ae9226d] soc-2013-paint: Fix accumulated painting in 2d painting, and refactor float code to use correct blending too.

Antony Riakiotakis noreply at git.blender.org
Tue Apr 1 17:14:40 CEST 2014


Commit: ae9226d3694f92591a3e33be3b130512b245c461
Author: Antony Riakiotakis
Date:   Tue Apr 1 18:14:23 2014 +0300
https://developer.blender.org/rBae9226d3694f92591a3e33be3b130512b245c461

Fix accumulated painting in 2d painting, and refactor float code to use
correct blending too.

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

M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/intern/rectop.c
M	source/gameengine/VideoTexture/ImageBuff.cpp

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

diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 25ec043..0d22eb9 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -967,7 +967,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos)
 		IMB_rectblend(ibufb, ibufb, ibuf, NULL, NULL, NULL, 0, region[a].destx, region[a].desty,
 		              region[a].destx, region[a].desty,
 		              region[a].srcx, region[a].srcy,
-		              region[a].width, region[a].height, IMB_BLEND_COPY_RGB);
+		              region[a].width, region[a].height, IMB_BLEND_COPY_RGB, false);
 }
 
 static ImBuf *paint_2d_lift_clone(ImBuf *ibuf, ImBuf *ibufb, int *pos)
@@ -979,9 +979,9 @@ static ImBuf *paint_2d_lift_clone(ImBuf *ibuf, ImBuf *ibufb, int *pos)
 
 	IMB_rectclip(clonebuf, ibuf, &destx, &desty, &srcx, &srcy, &w, &h);
 	IMB_rectblend(clonebuf, clonebuf, ibufb, NULL, NULL, NULL, 0, destx, desty, destx, desty, destx, desty, w, h,
-	              IMB_BLEND_COPY_ALPHA);
+	              IMB_BLEND_COPY_ALPHA, false);
 	IMB_rectblend(clonebuf, clonebuf, ibuf, NULL, NULL, NULL, 0, destx, desty, destx, desty, srcx, srcy, w, h,
-	              IMB_BLEND_COPY_RGB);
+	              IMB_BLEND_COPY_RGB, false);
 
 	return clonebuf;
 }
@@ -1001,7 +1001,7 @@ static int paint_2d_op(void *state, ImBuf *ibufb, unsigned short *curveb, unsign
 	short blend = s->blend;
 	float *offset = s->brush->clone.offset;
 	float liftpos[2];
-	unsigned short mask_max = (unsigned short)(BKE_brush_alpha_get(s->scene, s->brush) * 65535.0f);
+	float mask_max = BKE_brush_alpha_get(s->scene, s->brush);
 	int bpos[2], blastpos[2], bliftpos[2];
 	int a, tot;
 
@@ -1071,7 +1071,7 @@ static int paint_2d_op(void *state, ImBuf *ibufb, unsigned short *curveb, unsign
 								  region[a].destx, region[a].desty,
 								  origx, origy,
 								  region[a].srcx, region[a].srcy,
-								  region[a].width, region[a].height, blend);
+								  region[a].width, region[a].height, blend, ((s->brush->flag & BRUSH_ACCUMULATE) != 0));
 				}
 			}
 
@@ -1083,7 +1083,7 @@ static int paint_2d_op(void *state, ImBuf *ibufb, unsigned short *curveb, unsign
 			              region[a].destx, region[a].desty,
 			              region[a].destx, region[a].desty,
 			              region[a].srcx, region[a].srcy,
-			              region[a].width, region[a].height, blend);
+			              region[a].width, region[a].height, blend, false);
 		}
 	}
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index c06862f..91d42fb 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4106,7 +4106,7 @@ static void *do_projectpaint_thread(void *ph_v)
 
 					if (falloff > 0.0f) {
 						float texrgb[3];
-						float mask = falloff;
+						float mask;
 
 						if (ps->do_masking) {
 							/* masking to keep brush contribution to a pixel limited. note we do not do
@@ -4116,7 +4116,7 @@ static void *do_projectpaint_thread(void *ph_v)
 							 * Instead we use a formula that adds up but approaches brush_alpha slowly
 							 * and never exceeds it, which gives nice smooth results. */
 							float mask_accum = *projPixel->mask_accum;
-							float max_mask = brush_alpha * mask * 65535.0f;
+							float max_mask = brush_alpha * falloff * 65535.0f;
 
 							if (ps->is_maskbrush) {
 								float texmask = BKE_brush_sample_masktex(ps->scene, ps->brush, projPixel->projCoSS, thread_index, pool);
@@ -4127,7 +4127,7 @@ static void *do_projectpaint_thread(void *ph_v)
 							if (brush->flag & BRUSH_ACCUMULATE)
 								mask = min_ff(mask_accum + max_mask, 65535.0f);
 							else
-								mask = mask_accum + (max_mask - mask_accum) * mask;
+								mask = mask_accum + (max_mask - mask_accum) * falloff;
 
 							mask_short = (unsigned short)mask;
 
@@ -4141,7 +4141,7 @@ static void *do_projectpaint_thread(void *ph_v)
 							}
 						}
 						else {
-							mask *= brush_alpha;
+							mask = brush_alpha * falloff;
 							if (ps->is_maskbrush) {
 								float texmask = BKE_brush_sample_masktex(ps->scene, ps->brush, projPixel->projCoSS, thread_index, pool);
 								CLAMP(texmask, 0.0f, 1.0f);
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 39bdec8..a683841 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -195,9 +195,9 @@ void IMB_rectclip(struct ImBuf *dbuf, struct ImBuf *sbuf, int *destx,
 void IMB_rectcpy(struct ImBuf *drect, struct ImBuf *srect, int destx,
 	int desty, int srcx, int srcy, int width, int height);
 void IMB_rectblend(struct ImBuf *dbuf, struct ImBuf *obuf, struct ImBuf *sbuf,
-	unsigned short *dmask, unsigned short *curvemask, unsigned short *mmask, unsigned short mask_max,
+	unsigned short *dmask, unsigned short *curvemask, unsigned short *mmask, float mask_max,
 	int destx,  int desty, int origx, int origy, int srcx, int srcy,
-	int width, int height, IMB_BlendMode mode);
+	int width, int height, IMB_BlendMode mode, bool accumulate);
 
 /**
  *
diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c
index 8bbaaeb..2ab4369 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -291,7 +291,7 @@ static void imb_rectclip3(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, int *destx,
 void IMB_rectcpy(ImBuf *dbuf, ImBuf *sbuf, int destx, 
                  int desty, int srcx, int srcy, int width, int height)
 {
-	IMB_rectblend(dbuf, dbuf, sbuf, NULL, NULL, NULL, 0, destx, desty, destx, desty, srcx, srcy, width, height, IMB_BLEND_COPY);
+	IMB_rectblend(dbuf, dbuf, sbuf, NULL, NULL, NULL, 0, destx, desty, destx, desty, srcx, srcy, width, height, IMB_BLEND_COPY, false);
 }
 
 typedef void (*IMB_blend_func)(unsigned char *dst, const unsigned char *src1, const unsigned char *src2);
@@ -299,9 +299,9 @@ typedef void (*IMB_blend_func_float)(float *dst, const float *src1, const float
 
 
 void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask, unsigned short *curvemask,
-				   unsigned short *texmask, unsigned short mask_max,
+				   unsigned short *texmask, float mask_max,
                    int destx,  int desty, int origx, int origy, int srcx, int srcy, int width, int height,
-                   IMB_BlendMode mode)
+                   IMB_BlendMode mode, bool accumulate)
 {
 	unsigned int *drect = NULL, *orect, *srect = NULL, *dr, *or, *sr;
 	float *drectf = NULL, *orectf, *srectf = NULL, *drf, *orf, *srf;
@@ -542,10 +542,18 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask,
 						dmr = dmaskrect;
 						for (x = width; x > 0; x--, dr++, or++, sr++, dmr++, cmr++) {
 							unsigned char *src = (unsigned char *)sr;
-							float mask_lim = (texmaskrect) ? ((float)mask_max * (*tmr++) / 65535.0f) : mask_max;
+							float mask_lim = mask_max * (*cmr);
 
-							if (src[3] && *cmr) {
-								unsigned short mask = *dmr + (((mask_lim - *dmr) * (*cmr)) / 65535.0f);
+							if (texmaskrect)
+								mask_lim *= ((*tmr++) / 65535.0f);
+
+							if (src[3] && mask_lim) {
+								float mask;
+
+								if (accumulate)
+									mask = min_ff(*dmr + mask_lim, 65535.0);
+								else
+									mask = *dmr + (((mask_lim - *dmr) * (*cmr)) / 65535.0f);
 
 								if (mask > *dmr) {
 									unsigned char mask_src[4];
@@ -563,13 +571,16 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask,
 						}
 						dmaskrect += origskip;
 					}
-					/* no destination alpha buffer, do regular blend with masktexture if present */
+					/* no destination mask buffer, do regular blend with masktexture if present */
 					else {
 						for (x = width; x > 0; x--, dr++, or++, sr++, cmr++) {
 							unsigned char *src = (unsigned char *)sr;
-							unsigned short mask = (((texmaskrect) ? ((float)mask_max * (*tmr++) / 65535.0f) : (float)mask_max) * (*cmr)) / 65535.0f;
+							unsigned short mask = (float)mask_max * ((float)(*cmr));
+
+							if (texmaskrect)
+								mask *= ((float)(*tmr++) / 65535.0f);
 
-							if (src[3] && *cmr && mask) {
+							if (src[3] && mask) {
 								unsigned char mask_src[4];
 
 								mask_src[0] = src[0];
@@ -604,19 +615,49 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned short *dmask,
 				orf = orectf;
 				srf = srectf;
 
-				if (dmaskrect && cmaskrect) {
+				if (cmaskrect) {
 					/* mask accumulation for painting */
-					dmr = dmaskrect;
 					cmr = cmaskrect;
 					tmr = texmaskrect;
 
-					for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, dmr++, cmr++) {
-						unsigned short mask_lim = (texmaskrect)? *tmr++ : mask_max;
+					/* destination mask present, do max alpha masking */
+					if (dmaskrect) {
+						dmr = dmaskrect;
+						for (x = width; x > 0; x--, drf +=4 , orf += 4, srf += 4, dmr++, cmr++) {
+							float mask_lim = mask_max * (*cmr);
+
+							if (texmaskrect)
+								mask_lim *= ((*tmr++) / 65535.0f);
+
+							if (srf[3] && mask_lim) {
+								float mask;
+
+								if (accumulate)
+									mask = min_ff(*dmr + mask_lim, 65535.0);
+								else
+									mask = *dmr + (((mask_lim - *dmr) * (*cmr)) / 65535.0f);
+
+								if (mask > *dmr) {
+									float mask_srf[4];
+
+									*dmr = mask;
+									mul_v4_v4fl(mask_srf, srf, mask * (1.0f / 65535.0f));
+
+									func_float(drf, orf, mask_srf);
+								}
+							}
+						}
+						dmaskrect += origskip;
+					}
+					/* no destination mask buffer, do regular blend with masktexture if present */
+					else {
+						for (x = width; x > 0; x--, drf += 4, orf += 4, srf += 4, cmr++) {
+							float mask = (float)mask_max * ((float)(*cmr));
 
-						if (srf[3] != 0 && *cmr) {
-							unsigned short mask = *dmr + (((mask_lim - *dmr) * (*cmr)) / 65535);
+							if (texmaskrect)
+								mask *= ((float)(*tmr++) / 65535.0f);
 
-							if (mask > *dmr) {
+							if (srf[3] && mask) {
 								float mask_srf[4];
 
 								*dmr = mask;
@@ -627,7 +668,6 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, unsigned shor

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list