[Bf-blender-cvs] [71cf50a] soc-2013-paint: * Add custom color for new layers.

Antony Riakiotakis noreply at git.blender.org
Sun Apr 27 22:02:44 CEST 2014


Commit: 71cf50ae24702a6eb21a4d5bad5ce9ec3dc4279f
Author: Antony Riakiotakis
Date:   Sun Apr 27 22:57:30 2014 +0300
https://developer.blender.org/rB71cf50ae24702a6eb21a4d5bad5ce9ec3dc4279f

* Add custom color for new layers.

This is not ideal because of the internal representation of byte images,
which is straight alpha. This means that on the display we will get an
opaque color if we try painting on a transparent image. To bypass this I
have enforced alpha to be 1 in that case. If we are to support this we
should upload byte images as premultiplied meaning we take a performance
hit...hmmmm...no.

* Add dependency update when painting on image editor. Should handle
update of layer icons nicely

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.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 41a50f9..70d5d87 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1122,7 +1122,8 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
                 row = col.row(align=True)
                 row.prop(settings, "new_slot_xresolution")
                 row.prop(settings, "new_slot_yresolution")
-
+                col.prop(settings, "new_layer_color")
+                
             if brush.image_tool == 'CLONE' and settings.use_clone_layer:
                 col.label("Clone Slot")
                 col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "paint_clone_slot", rows=2)
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 31c701e..ee960f0 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -45,6 +45,7 @@
 #include "BLI_bitmap.h"
 
 #include "BKE_context.h"
+#include "BKE_depsgraph.h"
 #include "BKE_brush.h"
 #include "BKE_main.h"
 #include "BKE_image.h"
@@ -1278,6 +1279,7 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final)
 
 		/* compositor listener deals with updating */
 		WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image);
+		DAG_id_tag_update(&s->image->id, 0);
 	}
 	else {
 		if (!s->sima || !s->sima->lock)
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 825ab3d..2563c1e 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4821,7 +4821,6 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 {
 	Object *ob = CTX_data_active_object(C);
 	Scene *scene = CTX_data_scene(C);
-	float color[4] = {0.0, 0.0, 0.0, 1.0};
 	int i;
 	ImagePaintSettings *imapaint = &CTX_data_tool_settings(C)->imapaint;
 	bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
@@ -4870,12 +4869,26 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
 				mtex->mapto = type;
 
 				if (mtex->tex) {
+					float color[4];
+					bool use_float = type == MAP_NORM;
+
+					copy_v4_v4(color, imapaint->new_layer_col);
+					if (use_float) {
+						mul_v3_fl(color, color[3]);
+					}
+					else {
+						/* crappy workaround because we only upload straight color to OpenGL and that makes
+						 * painting result on viewport too opaque */
+						color[3] = 1.0;
+					}
+
 					BLI_strncpy(imagename, &ma->id.name[2], FILE_MAX);
 					BLI_strncat_utf8(imagename, "_", FILE_MAX);
 					BLI_strncat_utf8(imagename, name, FILE_MAX);
 					/* take the second letter to avoid the ID identifier */
 
-					ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, 32, type == MAP_NORM, IMA_GENTYPE_BLANK, color);
+					ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, 32, use_float,
+					                                               IMA_GENTYPE_BLANK, color);
 
 					refresh_texpaint_image_cache(ma, false);
 					BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 81419f4..f64614d 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -805,6 +805,7 @@ typedef struct ImagePaintSettings {
 
 	void *paintcursor;			/* wm handle */
 	struct Image *stencil;      /* workaround until we support true layer masks */
+	float new_layer_col[4];
 	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 161a61d..20d1c2d 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -611,6 +611,12 @@ static void rna_def_image_paint(BlenderRNA *brna)
 	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, "new_layer_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_float_sdna(prop, NULL, "new_layer_col");
+	RNA_def_property_ui_text(prop, "New Layer Color", "Color/Alpha used for new");
+	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+
 	prop = RNA_def_property(srna, "use_clone_layer", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);
 	RNA_def_property_ui_text(prop, "Clone Map",




More information about the Bf-blender-cvs mailing list