[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55258] trunk/blender: Support for textures in vertex painting.

Antony Riakiotakis kalast at gmail.com
Thu Mar 14 04:42:20 CET 2013


Revision: 55258
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55258
Author:   psy-fi
Date:     2013-03-14 03:42:17 +0000 (Thu, 14 Mar 2013)
Log Message:
-----------
Support for textures in vertex painting.

Developer notes: this commit does painting in sRGB space. Since colours
are stored im byte per component formats, expect this to have the usual
dark fringing issues. Speed wise vertex paint could use some
optimization, for instance we could store the screen space vertex
positions on initialization like we do for texture painting, but this is
for another time. Also noticed that vertex painting suffers from the
subsurf + mirror issue too :/

Apart from that it's quite exciting how easy it is to add support for
texturing now that proper abstractions for texture sampling have been
done :)

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-03-14 02:45:23 UTC (rev 55257)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-03-14 03:42:17 UTC (rev 55258)
@@ -751,7 +751,7 @@
     def poll(cls, context):
         settings = cls.paint_settings(context)
         return (settings and settings.brush and
-                (context.sculpt_object or context.image_paint_object))
+                (context.sculpt_object or context.image_paint_object or context.vertex_paint_object))
 
     def draw(self, context):
         layout = self.layout

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2013-03-14 02:45:23 UTC (rev 55257)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2013-03-14 03:42:17 UTC (rev 55258)
@@ -43,6 +43,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_math_color.h"
 #include "BLI_memarena.h"
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
@@ -854,8 +855,8 @@
 }
 
 /* whats _dl mean? */
-static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float co[3],
-                                 const float mval[2], const float brush_size_pressure)
+static float calc_vp_strength_col_dl(VPaint *vp, ViewContext *vc, const float co[3],
+                                 const float mval[2], const float brush_size_pressure, float rgba[4])
 {
 	float vertco[2];
 
@@ -871,19 +872,26 @@
 		if (dist_squared <= brush_size_pressure * brush_size_pressure) {
 			Brush *brush = paint_brush(&vp->paint);
 			const float dist = sqrtf(dist_squared);
+			if (brush->mtex.tex) {
+				if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D)
+					BKE_brush_sample_tex_3D(vc->scene, brush, co, rgba, 0, NULL);
+				else
+					BKE_brush_sample_tex_3D(vc->scene, brush, vertco, rgba, 0, NULL);
+			}
 			return BKE_brush_curve_strength_clamp(brush, dist, brush_size_pressure);
 		}
 	}
 
+	zero_v4(rgba);
 	return 0.0f;
 }
 
 static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc,
                               float vpimat[3][3], const DMCoNo *v_co_no,
                               const float mval[2],
-                              const float brush_size_pressure, const float brush_alpha_pressure)
+                              const float brush_size_pressure, const float brush_alpha_pressure, float rgba[4])
 {
-	float strength = calc_vp_strength_dl(vp, vc, v_co_no->co, mval, brush_size_pressure);
+	float strength = calc_vp_strength_col_dl(vp, vc, v_co_no->co, mval, brush_size_pressure, rgba);
 
 	if (strength > 0.0f) {
 		float alpha = brush_alpha_pressure * strength;
@@ -2307,7 +2315,7 @@
 #define WP_BLUR_ACCUM(v_idx_var)  \
 	{ \
 		const unsigned int vidx = v_idx_var; \
-		const float fac = calc_vp_strength_dl(wp, vc, wpd->vertexcosnos[vidx].co, mval, brush_size_pressure); \
+		const float fac = calc_vp_strength_col_dl(wp, vc, wpd->vertexcosnos[vidx].co, mval, brush_size_pressure, NULL); \
 		if (fac > 0.0f) { \
 			MDeformWeight *dw = dw_func(&me->dvert[vidx], wpi.vgroup_active); \
 			paintweight += dw ? (dw->weight * fac) : 0.0f; \
@@ -2378,7 +2386,7 @@
 		unsigned int vidx = v_idx_var; \
 		if (me->dvert[vidx].flag) { \
 			alpha = calc_vp_alpha_dl(wp, vc, wpd->wpimat, &wpd->vertexcosnos[vidx], \
-			                         mval, brush_size_pressure, brush_alpha_pressure); \
+			                         mval, brush_size_pressure, brush_alpha_pressure, NULL); \
 			if (alpha) { \
 				do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight); \
 			} \
@@ -2662,6 +2670,8 @@
 	/* mpoly -> mface mapping */
 	MemArena *polyfacemap_arena;
 	ListBase *polyfacemap;
+
+	bool is_texbrush;
 } VPaintData;
 
 static void vpaint_build_poly_facemap(struct VPaintData *vd, Mesh *me)
@@ -2698,6 +2708,7 @@
 	ToolSettings *ts = CTX_data_tool_settings(C);
 	struct PaintStroke *stroke = op->customdata;
 	VPaint *vp = ts->vpaint;
+	Brush *brush = paint_brush(&vp->paint);
 	struct VPaintData *vpd;
 	Object *ob = CTX_data_active_object(C);
 	Mesh *me;
@@ -2727,6 +2738,8 @@
 	vpd->indexar = get_indexarray(me);
 	vpd->paintcol = vpaint_get_current_col(vp);
 
+	vpd->is_texbrush = !(brush->vertexpaint_tool == PAINT_BLEND_BLUR) &&
+	                   brush->mtex.tex;
 
 	/* are we painting onto a modified mesh?,
 	 * if not we can skip face map trickyness */
@@ -2803,12 +2816,24 @@
 
 	ml = me->mloop + mpoly->loopstart;
 	for (i = 0; i < mpoly->totloop; i++, ml++) {
+		float rgba[4];
+		unsigned int paintcol;
 		alpha = calc_vp_alpha_dl(vp, vc, vpd->vpimat,
 		                         &vpd->vertexcosnos[ml->v], mval,
-		                         brush_size_pressure, brush_alpha_pressure);
+		                         brush_size_pressure, brush_alpha_pressure, rgba);
+
+		if (vpd->is_texbrush) {
+			float rgba_br[3];
+			rgb_uchar_to_float(rgba_br, (const unsigned char *)&vpd->paintcol);
+			mul_v3_v3(rgba_br, rgba);
+			rgb_float_to_uchar((unsigned char *)&paintcol, rgba_br);
+		}
+		else
+			paintcol = vpd->paintcol;
+
 		if (alpha > 0.0f) {
 			const int alpha_i = (int)(alpha * 255.0f);
-			lcol[i] = vpaint_blend(vp, lcol[i], lcolorig[i], vpd->paintcol, alpha_i, brush_alpha_pressure_i);
+			lcol[i] = vpaint_blend(vp, lcol[i], lcolorig[i], paintcol, alpha_i, brush_alpha_pressure_i);
 		}
 	}
 




More information about the Bf-blender-cvs mailing list