[Bf-blender-cvs] [863733f] soc-2013-paint: Stencil eye candy (but can be useful too):

Antony Riakiotakis noreply at git.blender.org
Sat Apr 26 02:17:10 CEST 2014


Commit: 863733f429fd4a6937977a167fcdf69da2e739bb
Author: Antony Riakiotakis
Date:   Sat Apr 26 03:17:00 2014 +0300
https://developer.blender.org/rB863733f429fd4a6937977a167fcdf69da2e739bb

Stencil eye candy (but can be useful too):

Allow setting the mask viewport color.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/space_view3d/drawmesh.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 3b2f1a3..5487af5 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1670,6 +1670,7 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel, Panel):
         row.menu("VIEW3D_MT_tools_projectpaint_stencil", text=stencil_text, translate=False)
         row.prop(ipaint, "invert_stencil", text="", icon='IMAGE_ALPHA')
         col.template_ID(ipaint, "stencil_image", new="image.new")
+        col.prop(ipaint, "stencil_color")
 
         col = layout.column()
         col.active = (settings.brush.image_tool == 'CLONE')
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index 4e885b7..8348b05 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -223,7 +223,8 @@ static struct TextureDrawState {
 	int color_profile;
 	bool use_backface_culling;
 	unsigned char obcol[4];
-} Gtexdraw = {NULL, NULL, false, false, 0, 0, 0, false, {0, 0, 0, 0}};
+	float stencil_col[4];
+} Gtexdraw = {NULL, NULL, false, false, 0, 0, 0, false, {0, 0, 0, 0}, {0.0f, 0.0f, 0.0f, 1.0f}};
 
 static bool set_draw_settings_cached(int clearcache, MTFace *texface, Material *ma, struct TextureDrawState gtexdraw)
 {
@@ -257,10 +258,14 @@ static bool set_draw_settings_cached(int clearcache, MTFace *texface, Material *
 			if (GPU_verify_image(Gtexdraw.stencil, NULL, 0, 1, 0, false)) {
 				glEnable(GL_TEXTURE_2D);
 				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
-				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
+				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
+				glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
+				glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_TEXTURE);
+				glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
 				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
+				glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, Gtexdraw.stencil_col);
 				if (!Gtexdraw.stencil_invert) {
-					glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);
+					glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR);
 				}
 			}
 			glActiveTexture(GL_TEXTURE0);
@@ -399,6 +404,7 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
 	Gtexdraw.ob = ob;
 	Gtexdraw.stencil = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL) ? imapaint->stencil : NULL;
 	Gtexdraw.stencil_invert = ((imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) != 0);
+	copy_v3_v3(Gtexdraw.stencil_col, imapaint->stencil_col);
 	Gtexdraw.is_tex = is_tex;
 
 	Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene);
@@ -417,10 +423,10 @@ static void draw_textured_end(void)
 	/* switch off textures */
 	GPU_set_tpage(NULL, 0, 0);
 
-	if(Gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) {
+	if((Gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) && (Gtexdraw.stencil != NULL)) {
 		glActiveTexture(GL_TEXTURE1);
 		GPU_set_tpage(NULL, 0, 0);
-		glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
+		glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 		glBindTexture(GL_TEXTURE_2D, 0);
 		glActiveTexture(GL_TEXTURE0);
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 960a73f..81419f4 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -805,6 +805,8 @@ typedef struct ImagePaintSettings {
 
 	void *paintcursor;			/* wm handle */
 	struct Image *stencil;      /* workaround until we support true layer masks */
+	float stencil_col[3];
+	float pad2;
 } ImagePaintSettings;
 
 /* ------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 304348e..161a61d 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -603,7 +603,13 @@ static void rna_def_image_paint(BlenderRNA *brna)
 	RNA_def_property_pointer_sdna(prop, NULL, "stencil");
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Stencil Image", "Image used as stencil");
-	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_stencil_update");
+
+	prop = RNA_def_property(srna, "stencil_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_float_sdna(prop, NULL, "stencil_col");
+	RNA_def_property_ui_text(prop, "Stencil Color", "Stencil color in the viewport");
+	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_stencil_update");
 
 	prop = RNA_def_property(srna, "use_clone_layer", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);




More information about the Bf-blender-cvs mailing list