[Bf-blender-cvs] [7df3b33d93d] greasepencil-object: Fix problem of stroke thickness when zoom

Antonio Vazquez noreply at git.blender.org
Wed Jun 14 20:52:37 CEST 2017


Commit: 7df3b33d93dd7453d241f85b0d444c32d8fb5606
Author: Antonio Vazquez
Date:   Wed Jun 14 20:52:19 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB7df3b33d93dd7453d241f85b0d444c32d8fb5606

Fix problem of stroke thickness when zoom

The stroke thickness was not working fine in Camera view.

The credits for this fix go to Clemnt Foucault and Luca Rood, thanks for the help!

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
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 29a6d73a330..12d1c61035e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -44,10 +44,6 @@
 #include "draw_cache_impl.h"
 #include "gpencil_engine.h"
 
-#define PIX_PERSPECTIVE 1
-#define PIX_ORTHOGRAPHIC 2
-#define PIX_CAMERAVIEW 3
-
 /* allocate cache to store GP objects */
 tGPencilObjectCache *gpencil_object_cache_allocate(tGPencilObjectCache *cache, int *gp_cache_size, int *gp_cache_used)
 {
@@ -316,19 +312,13 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass
 	DRW_shgroup_uniform_float(grp, "pixsize", &rv3d->pixsize, 1);
 	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
 
-	if (rv3d->is_persp) {
-		stl->storage->is_persp = PIX_PERSPECTIVE;
-		if (rv3d->persp == RV3D_CAMOB) {
-			stl->storage->is_persp = PIX_CAMERAVIEW;
-		}
-	}
-	else {
-		stl->storage->is_persp = PIX_ORTHOGRAPHIC;
-	}
 	/* If disable zoom for strokes, disable scale */
 	if ((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS)) {
 		stl->storage->is_persp = 0;
 	}
+	else {
+		stl->storage->is_persp = 1;
+	}
 
 	DRW_shgroup_uniform_int(grp, "is_persp", &stl->storage->is_persp, 1);
 
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 1caed680c2c..5173321c132 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
@@ -1,8 +1,9 @@
 uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ProjectionMatrix;
 
 uniform float pixsize;   /* rv3d->pixsize */
 uniform float pixelsize; /* U.pixelsize */
-uniform int is_persp;    /* rv3d->is_persp (1-Persp, 2->Orto, 3->Cameraview), 0: No scale */
+uniform int is_persp;    /* 0: Keep Stroke size */
 
 in vec3 pos;
 in vec4 color;
@@ -12,18 +13,7 @@ out vec4 finalColor;
 out float finalThickness;
 
 #define TRUE 1
-#define PIX_PERSPECTIVE 1
-#define PIX_ORTHOGRAPHIC 2
-#define PIX_CAMERAVIEW 3
 
-/* port of c code function */
-float mul_project_m4_v3_zfac(mat4 mat, vec3 co)
-{
-	return (mat[0][3] * co[0]) +
-	       (mat[1][3] * co[1]) +
-	       (mat[2][3] * co[2]) + mat[3][3];
-}
-	
 float defaultpixsize = pixsize * pixelsize;
 
 void main(void)
@@ -31,16 +21,12 @@ void main(void)
 	gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 );
 	finalColor = color;
 
-	float pixsize = mul_project_m4_v3_zfac(ModelViewProjectionMatrix, pos) * defaultpixsize;
-	float scale_thickness = 1.0f;
-	
-	if ((is_persp == PIX_PERSPECTIVE) || (is_persp == PIX_CAMERAVIEW)) {
-		/* need a factor to mimmic old glLine size, 10.0f works fine */
-		scale_thickness = (defaultpixsize / pixsize) * 10.0f;
+	if (is_persp == TRUE) {
+		float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (-gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize);
+		finalThickness = max(abs(size) / 40.0 , 1.0);
 	}
-	if (is_persp == PIX_ORTHOGRAPHIC) {
-		scale_thickness = (1.0f / pixsize) / 100.0f;
+	else {
+		finalThickness = thickness;
 	}
-
-	finalThickness = thickness * max(scale_thickness, 0.01f);
+	
 } 
\ No newline at end of file




More information about the Bf-blender-cvs mailing list