[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48139] branches/soc-2012-bratwurst: Texture paint mask textures

Antony Riakiotakis kalast at gmail.com
Wed Jun 20 22:07:28 CEST 2012


Revision: 48139
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48139
Author:   psy-fi
Date:     2012-06-20 20:07:28 +0000 (Wed, 20 Jun 2012)
Log Message:
-----------
Texture paint mask textures
============================
* rename alpha_mtex property to mask_mtex
* More forgotten initialization stuff
* do_versions code to initialize the mask properly
* Mask works now :).

I need to expose more properties for mask textures so that they can be
modified independently. Also I need to see how to modify the properties
panel to accomodate the new brush texture type

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    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/blenkernel/intern/texture.c
    branches/soc-2012-bratwurst/source/blender/blenloader/intern/readfile.c
    branches/soc-2012-bratwurst/source/blender/blenloader/intern/versioning_250.c
    branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c
    branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_image.py	2012-06-20 20:07:28 UTC (rev 48139)
@@ -710,7 +710,7 @@
         col = layout.column()
         col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
         col.label(text='Mask Texture')
-        col.template_ID_preview(brush, "alpha_texture", new="texture.new", rows=3, cols=8)
+        col.template_ID_preview(brush, "mask_texture", new="texture.new", rows=3, cols=8)
         col.prop(brush, "use_fixed_texture")
 
 

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-06-20 20:07:28 UTC (rev 48139)
@@ -730,14 +730,14 @@
         settings = self.paint_settings(context)
         brush = settings.brush
         tex_slot = brush.texture_slot
-        tex_slot_alpha = brush.alpha_texture_slot
+        tex_slot_alpha = brush.mask_texture_slot
 
         col = layout.column()
 
         col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
         if context.image_paint_object:
             col.label(text='Mask Texture')
-            col.template_ID_preview(brush, "alpha_texture", new="texture.new", rows=3, cols=8)
+            col.template_ID_preview(brush, "mask_texture", new="texture.new", rows=3, cols=8)
         if brush.use_paint_image:
             col.prop(brush, "use_fixed_texture")
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h	2012-06-20 20:07:28 UTC (rev 48139)
@@ -68,6 +68,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);
+float BKE_brush_sample_masktex(const struct Scene *scene, struct Brush *brush, const float xy[2], 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, float angle, int use_color_correction);
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -106,6 +106,7 @@
 	brush->random_factor_cache = 1.0;
 	/* BRUSH TEXTURE SETTINGS */
 	default_mtex(&brush->mtex);
+	default_mtex(&brush->mask_mtex);
 
 	brush->texture_sample_bias = 0; /* value to added to texture samples */
 	brush->texture_overlay_alpha = 33;
@@ -151,8 +152,8 @@
 	if (brush->mtex.tex)
 		id_us_plus((ID *)brush->mtex.tex);
 
-	if (brush->alphamtex.tex)
-		id_us_plus((ID *)brush->alphamtex.tex);
+	if (brush->mask_mtex.tex)
+		id_us_plus((ID *)brush->mask_mtex.tex);
 
 	if (brush->icon_imbuf)
 		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
@@ -176,8 +177,8 @@
 	if (brush->mtex.tex)
 		brush->mtex.tex->id.us--;
 
-	if (brush->alphamtex.tex)
-		brush->alphamtex.tex->id.us--;
+	if (brush->mask_mtex.tex)
+		brush->mask_mtex.tex->id.us--;
 
 	if (brush->icon_imbuf)
 		IMB_freeImBuf(brush->icon_imbuf);
@@ -190,7 +191,7 @@
 static void extern_local_brush(Brush *brush)
 {
 	id_lib_extern((ID *)brush->mtex.tex);
-	id_lib_extern((ID *)brush->alphamtex.tex);
+	id_lib_extern((ID *)brush->mask_mtex.tex);
 	id_lib_extern((ID *)brush->clone.image);
 }
 
@@ -519,11 +520,6 @@
 		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]);
@@ -554,6 +550,45 @@
 	}
 }
 
+/* Brush Mask Sampling */
+float BKE_brush_sample_masktex(const Scene *scene, Brush *brush, const float xy[2], const int thread, float angle)
+{
+	MTex *mtex = &brush->mask_mtex;
+
+	if (mtex && mtex->tex) {
+		float co_angle, length;
+		float co[3], tin, rgb[3], ta;
+		int hasrgb;
+		const int radius = BKE_brush_size_randomized_get(scene, brush);
+
+		co[0] = xy[0] / radius;
+		co[1] = xy[1] / 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;
+
+			co_angle -= angle;
+			co[0] = cos(co_angle)*length;
+			co[1] = sin(co_angle)*length;
+		}
+
+		hasrgb = externtex(mtex, co, &tin, rgb, rgb+1, rgb+2, &ta, thread);
+
+		if (hasrgb) {
+			return rgb_to_grayscale(rgb);
+		}
+		else {
+			return tin;
+		}
+	}
+	else {
+		return 1.0f;
+	}
+}
+
 /* TODO, use define for 'texfall' arg */
 void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, float angle, int use_color_correction)
 {

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/texture.c	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/texture.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -804,6 +804,10 @@
 			if (br->id.lib) is_lib = TRUE;
 			else is_local = TRUE;
 		}
+		if (br->mask_mtex.tex == tex) {
+			if (br->id.lib) is_lib = TRUE;
+			else is_local = TRUE;
+		}
 		br = br->id.next;
 	}
 	pa = bmain->particle.first;
@@ -877,6 +881,13 @@
 					tex->id.us--;
 				}
 			}
+			if (br->mask_mtex.tex == tex) {
+				if (br->id.lib == NULL) {
+					br->mask_mtex.tex = tex_new;
+					tex_new->id.us++;
+					tex->id.us--;
+				}
+			}
 			br = br->id.next;
 		}
 		pa = bmain->particle.first;

Modified: branches/soc-2012-bratwurst/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenloader/intern/readfile.c	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenloader/intern/readfile.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -142,6 +142,7 @@
 #include "BKE_tracking.h"
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_sound.h"
+#include "BKE_texture.h"
 
 #include "IMB_imbuf.h"  // for proxy / timecode versioning stuff
 
@@ -1671,7 +1672,7 @@
 			brush->id.flag -= LIB_NEEDLINK;
 			
 			brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
-			brush->alphamtex.tex = newlibadr_us(fd, brush->id.lib, brush->alphamtex.tex);
+			brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex);
 			brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image);
 		}
 	}
@@ -7790,6 +7791,12 @@
 				ma->strand_widthfade = 0.0f;
 	}
 
+	if (main->versionfile < 264) {
+		Brush *brush;
+		for (brush = main->brush.first; brush; brush = brush->id.next) {
+			default_mtex(&brush->mask_mtex);
+		}
+	}
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 

Modified: branches/soc-2012-bratwurst/source/blender/blenloader/intern/versioning_250.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenloader/intern/versioning_250.c	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenloader/intern/versioning_250.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -1602,6 +1602,7 @@
 		/* brush texture changes */
 		for (brush = main->brush.first; brush; brush = brush->id.next) {
 			default_mtex(&brush->mtex);
+			default_mtex(&brush->mask_mtex);
 		}
 
 		for (ma = main->mat.first; ma; ma = ma->id.next) {

Modified: branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c	2012-06-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -2675,7 +2675,7 @@
 			if (brush->id.properties) IDP_WriteProperty(brush->id.properties, wd);
 			
 			writestruct(wd, DATA, "MTex", 1, &brush->mtex);
-			writestruct(wd, DATA, "MTex", 1, &brush->alphamtex);
+			writestruct(wd, DATA, "MTex", 1, &brush->mask_mtex);
 			
 			if (brush->curve)
 				write_curvemapping(wd, brush->curve);

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-20 20:05:21 UTC (rev 48138)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c	2012-06-20 20:07:28 UTC (rev 48139)
@@ -317,6 +317,7 @@
 	short is_ortho;
 	short is_airbrush;              /* only to avoid using (ps.brush->flag & BRUSH_AIRBRUSH) */
 	short is_texbrush;              /* only to avoid running  */
+	short is_maskbrush;             /* avoid getting mask value */
 #ifndef PROJ_DEBUG_NOSEAMBLEED
 	float seam_bleed_px;
 #endif
@@ -3915,18 +3916,22 @@
 
 				/*if (dist < radius) {*/ /* correct but uses a sqrtf */
 				if (dist_nosqrt <= radius_squared) {
+					float samplecos[2];
 					dist = sqrtf(dist_nosqrt);
 
 					falloff = BKE_brush_curve_strength_clamp(ps->brush, dist, radius);
 
+					/* will eventuallly be separated when mask textures get their own attributes */
+					if (ps->is_texbrush || ps->is_maskbrush) {
+						if(ps->brush->flag & (BRUSH_RAKE | BRUSH_RANDOM_ROTATION)) {
+							sub_v2_v2v2(samplecos, projPixel->projCoSS, pos);
+						} else {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list