[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37276] trunk/blender/source/blender: fix for float projection painting, now updating correctly.

Ryakiotakis Antonis kalast at gmail.com
Tue Jun 7 00:10:05 CEST 2011


Revision: 37276
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37276
Author:   psy-fi
Date:     2011-06-06 22:10:05 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
fix for float projection painting, now updating correctly. 

This fix also allows for partial update of the image, speeding up painting. 
The different code path implemented will be used to upload high resolution images to OpenGL when onion branch is merged.
Due to conversion of float textures to/from sRGB, corrections made to brush color sampling to take account of the image profile. This is not 100% correct yet as texture images used for projection painting strokes are not converted to/from sRGB yet(This has been decided due to loss of precision for 8-bit formats). It will have to do for now, though.

last-minute update, exr image loading is broken, will fix asap

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/BLI_utildefines.h
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/gpu/intern/gpu_draw.c
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/divers.c

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2011-06-06 22:10:05 UTC (rev 37276)
@@ -71,7 +71,7 @@
 /* sampling */
 void brush_sample_tex(struct Brush *brush, float *xy, float *rgba, const int thread);
 void brush_imbuf_new(struct Brush *brush, short flt, short texfalloff, int size,
-	struct ImBuf **imbuf);
+	struct ImBuf **imbuf, int use_color_correction);
 
 /* painting */
 struct BrushPainter;
@@ -82,7 +82,7 @@
 void brush_painter_require_imbuf(BrushPainter *painter, short flt,
 	short texonly, int size);
 int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos,
-	double time, float pressure, void *user);
+	double time, float pressure, void *user, int use_color_correction);
 void brush_painter_break_stroke(BrushPainter *painter);
 void brush_painter_free(BrushPainter *painter);
 

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2011-06-06 22:10:05 UTC (rev 37276)
@@ -521,7 +521,7 @@
 }
 
 
-void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf)
+void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
 {
 	ImBuf *ibuf;
 	float xy[2], dist, rgba[4], *dstf;
@@ -529,7 +529,8 @@
 	const int radius= brush_size(brush);
 	char *dst, crgb[3];
 	const float alpha= brush_alpha(brush);
-
+	float brush_rgb[3];
+    
 	imbflag= (flt)? IB_rectfloat: IB_rect;
 	xoff = -bufsize/2.0f + 0.5f;
 	yoff = -bufsize/2.0f + 0.5f;
@@ -541,6 +542,11 @@
 		ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag);
 
 	if (flt) {
+		copy_v3_v3(brush_rgb, brush->rgb);
+		if(use_color_correction){
+			srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
+		}
+
 		for (y=0; y < ibuf->y; y++) {
 			dstf = ibuf->rect_float + y*rowbytes;
 
@@ -551,7 +557,7 @@
 				if (texfall == 0) {
 					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
 
-					VECCOPY(dstf, brush->rgb);
+					VECCOPY(dstf, brush_rgb);
 					dstf[3]= alpha*brush_curve_strength_clamp(brush, dist, radius);
 				}
 				else if (texfall == 1) {
@@ -561,10 +567,7 @@
 					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
 
 					brush_sample_tex(brush, xy, rgba, 0);
-
-					dstf[0] = rgba[0]*brush->rgb[0];
-					dstf[1] = rgba[1]*brush->rgb[1];
-					dstf[2] = rgba[2]*brush->rgb[2];
+					mul_v3_v3v3(dstf, rgba, brush_rgb);
 					dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius);
 				}
 			}
@@ -862,7 +865,7 @@
 		brush_painter_do_partial(painter, NULL, x1, y2, x2, ibuf->y, 0, 0, pos);
 }
 
-static void brush_painter_refresh_cache(BrushPainter *painter, float *pos)
+static void brush_painter_refresh_cache(BrushPainter *painter, float *pos, int use_color_correction)
 {
 	Brush *brush= painter->brush;
 	BrushPainterCache *cache= &painter->cache;
@@ -889,11 +892,11 @@
 		size= (cache->size)? cache->size: diameter;
 
 		if (brush->flag & BRUSH_FIXED_TEX) {
-			brush_imbuf_new(brush, flt, 3, size, &cache->maskibuf);
+			brush_imbuf_new(brush, flt, 3, size, &cache->maskibuf, use_color_correction);
 			brush_painter_fixed_tex_partial_update(painter, pos);
 		}
 		else
-			brush_imbuf_new(brush, flt, 2, size, &cache->ibuf);
+			brush_imbuf_new(brush, flt, 2, size, &cache->ibuf, use_color_correction);
 
 		cache->lastsize= diameter;
 		cache->lastalpha= alpha;
@@ -952,7 +955,7 @@
 	}
 }
 
-int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, double time, float pressure, void *user)
+int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, double time, float pressure, void *user, int use_color_correction)
 {
 	Brush *brush= painter->brush;
 	int totpaintops= 0;
@@ -970,7 +973,7 @@
 
 		brush_apply_pressure(painter, brush, pressure);
 		if (painter->cache.enabled)
-			brush_painter_refresh_cache(painter, pos);
+			brush_painter_refresh_cache(painter, pos, use_color_correction);
 		totpaintops += func(user, painter->cache.ibuf, pos, pos);
 		
 		painter->lasttime= time;
@@ -1043,7 +1046,7 @@
 				brush_jitter_pos(brush, paintpos, finalpos);
 
 				if (painter->cache.enabled)
-					brush_painter_refresh_cache(painter, finalpos);
+					brush_painter_refresh_cache(painter, finalpos, use_color_correction);
 
 				totpaintops +=
 					func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos);
@@ -1057,7 +1060,7 @@
 			brush_jitter_pos(brush, pos, finalpos);
 
 			if (painter->cache.enabled)
-				brush_painter_refresh_cache(painter, finalpos);
+				brush_painter_refresh_cache(painter, finalpos, use_color_correction);
 
 			totpaintops += func(user, painter->cache.ibuf, pos, finalpos);
 
@@ -1085,7 +1088,7 @@
 				brush_jitter_pos(brush, pos, finalpos);
 
 				if (painter->cache.enabled)
-					brush_painter_refresh_cache(painter, finalpos);
+					brush_painter_refresh_cache(painter, finalpos, use_color_correction);
 
 				totpaintops +=
 					func(user, painter->cache.ibuf, painter->lastmousepos, finalpos);

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2011-06-06 22:10:05 UTC (rev 37276)
@@ -58,6 +58,8 @@
 
 /********************************* Arithmetic ********************************/
 
+MINLINE void add_v3_fl(float r[3], float f);
+MINLINE void add_v4_fl(float r[4], float f);
 MINLINE void add_v2_v2(float r[2], const float a[2]);
 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]);
 MINLINE void add_v3_v3(float r[3], const float a[3]);

Modified: trunk/blender/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_utildefines.h	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/blenlib/BLI_utildefines.h	2011-06-06 22:10:05 UTC (rev 37276)
@@ -103,7 +103,13 @@
 
 #define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : (char)((255.0f*(val))+0.5f))
 #define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
+#define F3TOCHAR3(v2,v1) (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2]))
+#define F3TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \
+						(v1)[3]=FTOCHAR((v2[3])); (v1)[3] = 255; }
+#define F4TOCHAR4(v2,v1) { (v1)[0]=FTOCHAR((v2[0])); (v1)[1]=FTOCHAR((v2[1])); (v1)[2]=FTOCHAR((v2[2])); \
+						(v1)[3]=FTOCHAR((v2[3])); (v1)[3]=FTOCHAR((v2[3])); }
 
+
 #define VECCOPY(v1,v2)          {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);}
 #define VECCOPY2D(v1,v2)          {*(v1)= *(v2); *(v1+1)= *(v2+1);}
 #define QUATCOPY(v1,v2)         {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);}

Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2011-06-06 22:10:05 UTC (rev 37276)
@@ -102,6 +102,21 @@
 
 /********************************* Arithmetic ********************************/
 
+MINLINE void add_v3_fl(float r[3], float f)
+{
+	r[0] += f;
+	r[1] += f;
+	r[2] += f;
+}
+
+MINLINE void add_v4_fl(float r[4], float f)
+{
+	r[0] += f;
+	r[1] += f;
+	r[2] += f;
+	r[3] += f;
+}
+
 MINLINE void add_v2_v2(float *r, const float *a)
 {
 	r[0] += a[0];

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2011-06-06 22:09:40 UTC (rev 37275)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2011-06-06 22:10:05 UTC (rev 37276)
@@ -3692,14 +3692,26 @@
 	}
 }
 
-static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask) {
+static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask, int use_color_correction) {
 	if (ps->is_texbrush) {
-		rgba[0] *= ps->brush->rgb[0];
-		rgba[1] *= ps->brush->rgb[1];
-		rgba[2] *= ps->brush->rgb[2];
+		/* rgba already holds a texture result here from higher level function */
+		float rgba_br[3];
+		if(use_color_correction){
+			srgb_to_linearrgb_v3_v3(rgba_br, ps->brush->rgb);
+			mul_v3_v3(rgba, rgba_br);
+		}
+		else{
+			mul_v3_v3(rgba, ps->brush->rgb);
+		}
 	}
 	else {
-		VECCOPY(rgba, ps->brush->rgb);
+		if(use_color_correction){
+			srgb_to_linearrgb_v3_v3(rgba, rgba);
+		}
+ 		else {
+			VECCOPY(rgba, ps->brush->rgb);
+		}
+		rgba[3] = 1.0;
 	}
 	
 	if (ps->is_airbrush==0 && mask < 1.0f) {
@@ -3736,6 +3748,7 @@
 	float falloff;
 	int bucket_index;
 	int is_floatbuf = 0;
+	int use_color_correction = 0;
 	const short tool =  ps->tool;
 	rctf bucket_bounds;
 	
@@ -3841,6 +3854,7 @@
 
 								last_projIma->touch = 1;
 								is_floatbuf = last_projIma->ibuf->rect_float ? 1 : 0;
+								use_color_correction = (last_projIma->ibuf->profile == IB_PROFILE_LINEAR_RGB) ? 1 : 0;
 							}
 
 							last_partial_redraw_cell = last_projIma->partRedrawRect + projPixel->bb_cell_index;
@@ -3871,7 +3885,7 @@
 								else				do_projectpaint_smear(ps, projPixel, alpha, mask, smearArena, &smearPixels, co);
 								break;
 							default:
-								if (is_floatbuf)	do_projectpaint_draw_f(ps, projPixel, rgba, alpha, mask);
+								if (is_floatbuf)	do_projectpaint_draw_f(ps, projPixel, rgba, alpha, mask, use_color_correction);
 								else				do_projectpaint_draw(ps, projPixel, rgba, alpha, mask);
 								break;
 							}
@@ -3987,7 +4001,7 @@
 	// we may want to use this later 
 	// brush_painter_require_imbuf(painter, ((ibuf->rect_float)? 1: 0), 0, 0);
 	
-	if (brush_painter_paint(painter, project_paint_op, pos, time, pressure, ps)) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list