[Bf-blender-cvs] [65081e17f71] greasepencil-object: Add new Fade and Opacity to Onion

Antonio Vazquez noreply at git.blender.org
Mon Sep 11 16:17:10 CEST 2017


Commit: 65081e17f71a29f75986b978a5e00d00ffc5575a
Author: Antonio Vazquez
Date:   Mon Sep 11 12:43:49 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB65081e17f71a29f75986b978a5e00d00ffc5575a

Add new Fade and Opacity to Onion

New parameters to define the opacity and a parameter to enable/disable fade effect.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index d6e3b1eaf12..6c823e87e26 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -1261,6 +1261,13 @@ class GreasePencilOnionPanel:
         sub = split.column(align=True)
         sub.prop(gpl, "ghost_after_range", text="After")
 
+        split = layout.split(percentage=0.5)
+        split.active = gpl.use_onion_skinning
+        sub = split.column(align=True)
+        sub.prop(gpl, "use_onion_fade", text="Fade")
+
+        sub = split.column(align=True)
+        sub.prop(gpl, "onion_factor", text="Opacity", slider=True)
 
 
 class GreasePencilParentLayerPanel:
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 45722e4864e..fac61828c37 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -461,10 +461,9 @@ bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setacti
 	gpl->opacity = 1.0f;
 
 	/* onion-skinning settings */
-	if (gpd->flag & GP_DATA_SHOW_ONIONSKINS)
-		gpl->flag |= GP_LAYER_ONIONSKIN;
-	
 	gpl->flag |= (GP_LAYER_GHOST_PREVCOL | GP_LAYER_GHOST_NEXTCOL);
+	gpl->flag |= GP_LAYER_ONION_FADE;
+	gpl->onion_factor = 0.5f;
 	
 	ARRAY_SET_ITEMS(gpl->gcolor_prev, 0.145098f, 0.419608f, 0.137255f); /* green */
 	ARRAY_SET_ITEMS(gpl->gcolor_next, 0.125490f, 0.082353f, 0.529412f); /* blue */
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index f6d0287a423..bf1c526919e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -886,10 +886,18 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
 			color[3] = alpha * fac * 0.66f;
 		}
 		else {
+			++idx;
+			fac = alpha - ((1.1f - (1.0f / (float)idx)) * 0.66f);
+			color[3] = fac;
+		}
+		/* if fade is disabled, opacity is equal in all frames */
+		if ((gpl->flag & GP_LAYER_ONION_FADE) == 0) {
 			color[3] = 0.66f;
 		}
-		CLAMP_MIN(color[3], 0.66f);
-		/* draw */
+		/* add override opacity factor */
+		color[3] += gpl->onion_factor - 0.5f;
+
+		CLAMP(color[3], 0.3f, 1.0f);
 		cache->is_dirty = true;
 		gpencil_draw_onion_strokes(cache, e_data, vedata, ob, gpd, gpl, gf, color, gpl->flag & GP_LAYER_GHOST_PREVCOL);
 	}
@@ -934,9 +942,18 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
 			color[3] = alpha * fac * 0.66f;
 		}
 		else {
+			++idx;
+			fac = alpha - ((1.1f - (1.0f / (float)idx)) * 0.66f);
+			color[3] = fac;
+		}
+		/* if fade is disabled, opacity is equal in all frames */
+		if ((gpl->flag & GP_LAYER_ONION_FADE) == 0) {
 			color[3] = 0.66f;
 		}
-		CLAMP_MIN(color[3], 0.66f);
+		/* add override opacity factor */
+		color[3] += gpl->onion_factor - 0.5f;
+
+		CLAMP(color[3], 0.3f, 1.0f);
 		cache->is_dirty = true;
 		gpencil_draw_onion_strokes(cache, e_data, vedata, ob, gpd, gpl, gf, color, gpl->flag & GP_LAYER_GHOST_NEXTCOL);
 	}
@@ -1016,6 +1033,7 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data, void *vedata, Scene
 		bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, 0);
 		if (gpf == NULL)
 			continue;
+
 		/* create GHash if need */
 		if (gpl->derived_data == NULL) {
 			gpl->derived_data = (GHash *)BLI_ghash_str_new(gpl->info);
@@ -1035,6 +1053,7 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data, void *vedata, Scene
 			derived_gpf = BKE_gpencil_frame_color_duplicate(gpf);
 			BLI_ghash_insert(gpl->derived_data, ob->id.name, derived_gpf);
 		}
+
 		/* draw onion skins */
 		if ((!no_onion) && (gpl->flag & GP_LAYER_ONIONSKIN) &&
 			((!playing) || (gpl->flag & GP_LAYER_GHOST_ALWAYS)))
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 84adfa7c9ed..8d9662f0bcf 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -269,7 +269,7 @@ typedef struct bGPDlayer {
 	float tintcolor[4];     /* Color used to tint layer, alpha value is used as factor */
 	float opacity;          /* Opacity of the layer */
 	int onion_mode;         /* onion mode */
-	char pad2[4];
+	float onion_factor;     /* onion alpha factor change */
 	struct GHash *derived_data;     /* runtime data created by modifiers */
 } bGPDlayer;
 
@@ -303,6 +303,8 @@ typedef enum eGPDlayer_Flag {
 	GP_LAYER_GHOST_ALWAYS	= (1 << 13),
 	/* draw new strokes using last stroke location (only in 3d view) */
 	GP_LAYER_USE_LOCATION = (1 << 14),
+	/* use fade color in onion skin */
+	GP_LAYER_ONION_FADE = (1 << 15),
 } eGPDlayer_Flag;
 
 /* xray modes */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index d92608ed2a1..efa4cd47d0e 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1118,7 +1118,6 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Use Stroke Location",
 		"When draw new strokes in 3D view, use last stroke origin, as new stroke origin");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
-
 	
 	/* Flags */
 	prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
@@ -1217,6 +1216,19 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Mode", "Mode to display frames");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
+	prop = RNA_def_property(srna, "use_onion_fade", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_ONION_FADE);
+	RNA_def_property_ui_text(prop, "Fade",
+		"Display onion keyframes with a fade in color transparency");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
+	prop = RNA_def_property(srna, "onion_factor", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "onion_factor");
+	RNA_def_property_float_default(prop, 0.5f);
+	RNA_def_property_range(prop, 0.0, 1.0f);
+	RNA_def_property_ui_text(prop, "Onion Opacity", "Change fade opacity of displayed onion frames");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
 	/* Layers API */
 	func = RNA_def_function(srna, "clear", "rna_GPencil_layer_clear");
 	RNA_def_function_ui_description(func, "Remove all the grease pencil layer data");



More information about the Bf-blender-cvs mailing list