[Bf-blender-cvs] [62677a73e1e] greasepencil-object: Add new factor to define pixel scale

Antonio Vazquez noreply at git.blender.org
Thu Aug 10 16:39:32 CEST 2017


Commit: 62677a73e1e4324ed0c6d6bedb683721232c3199
Author: Antonio Vazquez
Date:   Thu Aug 10 16:27:28 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB62677a73e1e4324ed0c6d6bedb683721232c3199

Add new factor to define pixel scale

This new parameter allows to define the factor to convert stroke thickness to pixel scale.

By default the factor was set to 40 that gets a good result.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
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_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index df0be90df09..159fcffa9d6 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -107,6 +107,7 @@ class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
         layout.prop(ob, "empty_draw_size", text="Size")
 
         gpd = context.gpencil_data
+
         row = layout.row()
         row.prop(gpd, "xray_mode", text="Draw Mode")
         row = layout.row()
@@ -120,6 +121,9 @@ class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
             row = layout.row()
             row.prop(gpl, "show_points")
 
+        row = layout.row()
+        row.prop(gpd, "pixfactor", text="Pixel Factor")
+
 
 classes = (
     DATA_PT_gpencil,
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 00188e6c570..95629cc9363 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -772,6 +772,7 @@ bGPdata *BKE_gpencil_data_addnew(const char name[])
 	gpd->flag |= GP_DATA_VIEWALIGN;
 	gpd->xray_mode = GP_XRAY_3DSPACE;
 	gpd->batch_cache_data = NULL;
+	gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
 	
 	return gpd;
 }
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 5e225d1fe24..fec307896a8 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -551,6 +551,13 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
 				}
 			}
 		}
+		/* init pixel size factor */
+		if (!DNA_struct_elem_find(fd->filesdna, "bGPDdata", "int", "pixfactor")) {
+			for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
+				gpd->pixfactor = 40;
+			}
+		}
+
 
 
 	}
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 8a598be0476..321ea46e6e9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -332,6 +332,11 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, GPENC
 	DRW_shgroup_uniform_float(grp, "pixsize", DRW_viewport_pixelsize_get(), 1);
 	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
 
+	/* avoid wrong values */
+	if ((gpd) && (gpd->pixfactor == 0)) {
+		gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
+	}
+
 	/* object scale and depth */
 	if ((ob) && (id > -1)) {
 		stl->shgroups[id].obj_scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
@@ -348,13 +353,21 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, GPENC
 			}
 		}
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
+		DRW_shgroup_uniform_int(grp, "pixfactor", &gpd->pixfactor, 1);
 	}
 	else {
 		stl->storage->obj_scale = 1.0f;
 		stl->storage->keep_size = 0;
+		stl->storage->pixfactor = GP_DEFAULT_PIX_FACTOR;
 		DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->obj_scale, 1);
 		DRW_shgroup_uniform_int(grp, "keep_size", &stl->storage->keep_size, 1);
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->storage->color_type, 1);
+		if (gpd) {
+			DRW_shgroup_uniform_int(grp, "pixfactor", &gpd->pixfactor, 1);
+		}
+		else {
+			DRW_shgroup_uniform_int(grp, "pixfactor", &stl->storage->pixfactor, 1);
+		}
 	}
 
 	if (gpd) {
@@ -410,6 +423,11 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data, GPENCI
 	DRW_shgroup_uniform_float(grp, "pixsize", DRW_viewport_pixelsize_get(), 1);
 	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
 
+	/* avoid wrong values */
+	if ((gpd) && (gpd->pixfactor == 0)) {
+		gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
+	}
+
 	/* object scale and depth */
 	if ((ob) && (id > -1)) {
 		stl->shgroups[id].obj_scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
@@ -426,14 +444,21 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data, GPENCI
 			}
 		}
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
-
+		DRW_shgroup_uniform_int(grp, "pixfactor", &gpd->pixfactor, 1);
 	}
 	else {
 		stl->storage->obj_scale = 1.0f;
 		stl->storage->keep_size = 0;
+		stl->storage->pixfactor = GP_DEFAULT_PIX_FACTOR;
 		DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->obj_scale, 1);
 		DRW_shgroup_uniform_int(grp, "keep_size", &stl->storage->keep_size, 1);
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->storage->color_type, 1);
+		if (gpd) {
+			DRW_shgroup_uniform_int(grp, "pixfactor", &gpd->pixfactor, 1);
+		}
+		else {
+			DRW_shgroup_uniform_int(grp, "pixfactor", &stl->storage->pixfactor, 1);
+		}
 	}
 
 	if (gpd) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 811730ea5e0..736f2fbb794 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -152,6 +152,8 @@ static void GPENCIL_cache_init(void *vedata)
 
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	Object *ob = NULL;
+	bGPdata *gpd = NULL;
 
 	if (!stl->g_data) {
 		/* Alloc transient pointers */
@@ -199,6 +201,10 @@ static void GPENCIL_cache_init(void *vedata)
 		stl->g_data->shgrps_edit_line = DRW_gpencil_shgroup_edit_volumetric_create(psl->edit_pass, e_data.gpencil_line_sh);
 		/* drawing buffer pass */
 		const DRWContextState *draw_ctx = DRW_context_state_get();
+		ob = draw_ctx->obact;
+		if (ob) {
+			gpd = ob->gpd;
+		}
 		Palette *palette = BKE_palette_get_active_from_context(draw_ctx->evil_C);
 		PaletteColor *palcolor = BKE_palette_color_get_active(palette);
 		if (palcolor) {
@@ -220,10 +226,10 @@ static void GPENCIL_cache_init(void *vedata)
 		stl->g_data->shgrps_drawing_fill = DRW_gpencil_shgroup_drawing_fill_create(psl->drawing_pass, e_data.gpencil_drawing_fill_sh);
 
 		if ((palcolor) && (palcolor->flag & PAC_COLOR_DOT) == 0) {
-			stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, palcolor, -1);
+			stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, gpd, palcolor, -1);
 		}
 		else {
-			stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_point_sh, NULL, NULL, palcolor, -1);
+			stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_point_sh, NULL, gpd, palcolor, -1);
 		}
 
 		/* we need a full screen pass to combine the result of zdepth */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 99de3296045..ea8e7db7e20 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -95,6 +95,7 @@ typedef struct GPENCIL_Storage {
 	int keep_size;
 	float obj_scale;
 	float blur1[2], blur2[2];
+	int pixfactor;
 } GPENCIL_Storage;
 
 typedef struct GPENCIL_StorageList {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
index ba11465e410..18d1f623f30 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
@@ -4,7 +4,9 @@ uniform mat4 ProjectionMatrix;
 
 uniform float pixsize;   /* rv3d->pixsize */
 uniform float pixelsize; /* U.pixelsize */
+uniform int pixfactor;
 uniform int keep_size;    
+
 uniform float objscale;
 
 in vec3 pos;
@@ -16,7 +18,7 @@ out float finalThickness;
 
 #define TRUE 1
 
-float defaultpixsize = pixsize * pixelsize * 40.0;
+float defaultpixsize = pixsize * pixelsize * pixfactor;
 
 void main()
 {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
index 205d5a02c7e..854d23911d7 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
@@ -3,7 +3,9 @@ uniform mat4 ProjectionMatrix;
 
 uniform float pixsize;   /* rv3d->pixsize */
 uniform float pixelsize; /* U.pixelsize */
+uniform int pixfactor;
 uniform int keep_size;    
+
 uniform float objscale;
 
 in vec3 pos;
@@ -15,7 +17,8 @@ out float finalThickness;
 
 #define TRUE 1
 
-float defaultpixsize = pixsize * pixelsize * 40.0;
+
+float defaultpixsize = pixsize * pixelsize * pixfactor;
 
 void main(void)
 {
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 909bd22014d..ae84ff20107 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -40,6 +40,7 @@ struct GHash;
 
 /* TODO: add size as userprefs parameter */
 #define GP_OBGPENCIL_DEFAULT_SIZE  0.2f 
+#define GP_DEFAULT_PIX_FACTOR 40
 
 /* information of vertex group weight */
 typedef struct bGPDweight {
@@ -332,6 +333,8 @@ typedef struct bGPdata {
 	short bfill_style;          /* buffer style for filling areas (used to select shader type) */
 
 	short xray_mode;            /* xray mode for strokes */
+	int pixfactor;              /* factor to define pixel size conversion */
+	char pad1[4];
 
 	/* saved palettes */
 	ListBase palettes DNA_DEPRECATED;
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index be894125b0a..aaee530a4ab 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1253,6 +1253,12 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Keep thickness", "Show stroke with same thickness when viewport zoom change");
 	RNA_def_property_update(prop, 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list