[Bf-blender-cvs] [5d8ef4ecbaf] greasepencil-object: Check zdepth to avoid strokes in back of camera

Antonio Vazquez noreply at git.blender.org
Fri May 5 20:13:52 CEST 2017


Commit: 5d8ef4ecbaf452cf40fd60b8543f141c43a718a1
Author: Antonio Vazquez
Date:   Fri May 5 16:29:33 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5d8ef4ecbaf452cf40fd60b8543f141c43a718a1

Check zdepth to avoid strokes in back of camera

Do not draw if the stroke ison  back of the point of view.

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

M	source/blender/draw/engines/gpencil/gpencil_draw.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw.c b/source/blender/draw/engines/gpencil/gpencil_draw.c
index 39ef388b387..c03e64dc044 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw.c
@@ -371,7 +371,7 @@ Batch *gpencil_get_buffer_fill_geom(const tGPspoint *points, int totpoints, floa
 
 
 /* Helper for doing all the checks on whether a stroke can be drawn */
-bool gpencil_can_draw_stroke(const bGPDstroke *gps)
+bool gpencil_can_draw_stroke(RegionView3D *rv3d, const bGPDframe *gpf, const bGPDstroke *gps)
 {
 	/* skip stroke if it doesn't have any valid data */
 	if ((gps->points == NULL) || (gps->totpoints < 1))
@@ -385,6 +385,24 @@ bool gpencil_can_draw_stroke(const bGPDstroke *gps)
 		return false;
 	}
 
+	/* Check if stroke is in view plane, not on camera back. Only check first point of 
+	   the stroke because check all points is too work and it works fine in most situations
+	*/
+	float viewfpt[3];
+	copy_v3_v3(viewfpt, &gps->points[0].x);
+	mul_m4_v3(gpf->matrix, viewfpt);
+	float zdepth = 0.0;
+
+	if (rv3d->is_persp) {
+		zdepth = ED_view3d_calc_zfac(rv3d, viewfpt, NULL);
+	}
+	else {
+		zdepth = -dot_v3v3(rv3d->viewinv[2], viewfpt);
+	}
+	if (zdepth < 0.0) {
+		return false;
+	}
+
 	/* stroke can be drawn */
 	return true;
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 4562c6b27df..2c81623906b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -31,6 +31,7 @@
 #include "ED_gpencil.h"
 
 #include "DNA_gpencil_types.h"
+#include "DNA_view3d_types.h"
 
  /* If builtin shaders are needed */
 #include "GPU_shader.h"
@@ -307,6 +308,9 @@ static void gpencil_draw_strokes(void *vedata, ToolSettings *ts, Object *ob,
 {
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	RegionView3D *rv3d = draw_ctx->rv3d;
+
 	DRWShadingGroup *fillgrp;
 	DRWShadingGroup *strokegrp;
 	bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
@@ -334,7 +338,7 @@ static void gpencil_draw_strokes(void *vedata, ToolSettings *ts, Object *ob,
 
 	for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 		/* check if stroke can be drawn */
-		if (gpencil_can_draw_stroke(gps) == false) {
+		if (gpencil_can_draw_stroke(rv3d, gpf, gps) == false) {
 			continue;
 		}
 		/* try to find shader group or create a new one */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index a9f3ce88a3a..dad94f024c1 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -36,6 +36,6 @@ struct Batch *gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float matrix[4
 struct Batch *gpencil_get_buffer_fill_geom(const struct tGPspoint *points, int totpoints, float ink[4]);
 struct Batch *gpencil_get_buffer_point_geom(struct bGPdata *gpd, short thickness);
 
-bool gpencil_can_draw_stroke(const struct bGPDstroke *gps);
+bool gpencil_can_draw_stroke(struct RegionView3D *rv3d, const struct bGPDframe *gpf, const struct bGPDstroke *gps);
 
 #endif /* __GPENCIL_ENGINE_H__ */
\ No newline at end of file




More information about the Bf-blender-cvs mailing list