[Bf-blender-cvs] [767f4f45870] greasepencil-object: Fix error in Cameraview when zoom

Antonio Vazquez noreply at git.blender.org
Thu Jun 15 20:12:29 CEST 2017


Commit: 767f4f458705ad9b1d387c305506101d6bd1733b
Author: Antonio Vazquez
Date:   Thu Jun 15 20:12:14 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB767f4f458705ad9b1d387c305506101d6bd1733b

Fix error in Cameraview when zoom

The problem was related to object scale

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

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_stroke_vert.glsl

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

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 12d1c61035e..d7fb5afe2fa 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -297,21 +297,27 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(DRWPass *pass, GPUS
 }
 
 /* create shading group for strokes */
-DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, bGPdata *gpd)
+DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob, bGPdata *gpd)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
-
 	const float *viewport_size = DRW_viewport_size_get();
-	const DRWContextState *draw_ctx = DRW_context_state_get();
-	RegionView3D *rv3d = draw_ctx->rv3d;
 
 	/* e_data.gpencil_stroke_sh */
 	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
 	DRW_shgroup_uniform_vec2(grp, "Viewport", viewport_size, 1);
 
-	DRW_shgroup_uniform_float(grp, "pixsize", &rv3d->pixsize, 1);
+	DRW_shgroup_uniform_float(grp, "pixsize", DRW_viewport_pixelsize_get(), 1);
 	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
 
+	/* object scale */
+	stl->storage->objscale = 1.0f;
+	float scale;
+	if (ob) {
+		scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
+		stl->storage->objscale = scale;
+	}
+	DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->objscale, 1);
+
 	/* If disable zoom for strokes, disable scale */
 	if ((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS)) {
 		stl->storage->is_persp = 0;
@@ -480,7 +486,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 		if (gps->totpoints > 1) {
 			int id = stl->storage->pal_id;
 			stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, e_data->gpencil_fill_sh, gpd, gps->palcolor, id);
-			stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, gpd);
+			stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd);
 			++stl->storage->pal_id;
 			
 			fillgrp = stl->shgroups[id].shgrps_fill;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 883029d72da..ed71ac5fe00 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -129,7 +129,7 @@ static void GPENCIL_cache_init(void *vedata)
 
 		/* drawing buffer pass */
 		psl->drawing_pass = DRW_pass_create("Gpencil Drawing Pass", state);
-		stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL);
+		stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL);
 		stl->g_data->shgrps_drawing_fill = DRW_gpencil_shgroup_drawing_fill_create(psl->drawing_pass, e_data.gpencil_drawing_fill_sh);
 	}
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index a4a9de99cec..38a85771535 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -57,6 +57,7 @@ typedef struct GPENCIL_Storage {
 	float unit_matrix[4][4];
 	int is_persp;   /* rv3d->is_persp (1-yes) */
 	int xray;
+	float objscale;
 } GPENCIL_Storage;
 
 typedef struct GPENCIL_StorageList {
@@ -132,7 +133,7 @@ typedef struct GpencilBatchCache {
 	int cache_idx;   /* current slot index */
 } GpencilBatchCache;
 
-struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, bGPdata *gpd);
+struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, struct Object *ob, struct bGPdata *gpd);
 struct DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
 struct DRWShadingGroup *DRW_gpencil_shgroup_edit_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
 struct DRWShadingGroup *DRW_gpencil_shgroup_drawing_fill_create(struct DRWPass *pass, struct GPUShader *shader);
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 fce902d8646..56d68cf8b8e 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
@@ -4,6 +4,7 @@ uniform mat4 ProjectionMatrix;
 uniform float pixsize;   /* rv3d->pixsize */
 uniform float pixelsize; /* U.pixelsize */
 uniform int is_persp;    /* 0: Keep Stroke size */
+uniform float objscale;
 
 in vec3 pos;
 in vec4 color;
@@ -14,7 +15,7 @@ out float finalThickness;
 
 #define TRUE 1
 
-float defaultpixsize = pixsize * pixelsize;
+float defaultpixsize = pixsize * pixelsize * 40.0;
 
 void main(void)
 {
@@ -22,9 +23,8 @@ void main(void)
 	finalColor = color;
 
 	if (is_persp == TRUE) {
-		float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (-gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize);
-		float objscale = (ModelViewProjectionMatrix[0][0] + ModelViewProjectionMatrix[1][1] + ModelViewProjectionMatrix[2][2]) / 3.0;
-		finalThickness = max((abs(size) / 40.0) * objscale , 1.0);
+		float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize);
+		finalThickness = clamp(size * objscale, 1.0, thickness * 50.0);
 	}
 	else {
 		finalThickness = thickness;




More information about the Bf-blender-cvs mailing list