[Bf-blender-cvs] [2908657ebb2] temp-greasepencil-vfx: WIP: More changes

Antonio Vazquez noreply at git.blender.org
Tue Jun 26 13:16:51 CEST 2018


Commit: 2908657ebb2b0f0f007805957f986a8915f408dc
Author: Antonio Vazquez
Date:   Mon Jun 25 23:50:48 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB2908657ebb2b0f0f007805957f986a8915f408dc

WIP: More changes

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

M	source/blender/blenkernel/BKE_shader_fx.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/shader_fx.c
M	source/blender/editors/object/object_shader_fx.c
M	source/blender/shader_fx/FX_shader_types.h
M	source/blender/shader_fx/intern/FX_shader_blur.c
M	source/blender/shader_fx/intern/FX_shader_flip.c
M	source/blender/shader_fx/intern/FX_shader_light.c
M	source/blender/shader_fx/intern/FX_shader_pixel.c
M	source/blender/shader_fx/intern/FX_shader_swirl.c
M	source/blender/shader_fx/intern/FX_shader_util.c
M	source/blender/shader_fx/intern/FX_shader_util.h
M	source/blender/shader_fx/intern/FX_shader_wave.c

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

diff --git a/source/blender/blenkernel/BKE_shader_fx.h b/source/blender/blenkernel/BKE_shader_fx.h
index fe3f03e3081..ea43c64c8fe 100644
--- a/source/blender/blenkernel/BKE_shader_fx.h
+++ b/source/blender/blenkernel/BKE_shader_fx.h
@@ -33,7 +33,6 @@
 struct ID;
 struct Depsgraph;
 struct DerivedMesh;
-struct bContext; /* NOTE: bakeModifier() - called from UI - needs to create new datablocks, hence the need for this */
 struct Mesh;
 struct Object;
 struct Scene;
@@ -42,7 +41,6 @@ struct ListBase;
 struct bArmature;
 struct Main;
 struct ShaderFxData;
-struct BMEditMesh;
 struct DepsNodeHandle;
 struct bGPDlayer;
 struct bGPDframe;
@@ -104,11 +102,9 @@ typedef struct ShaderFxTypeInfo {
 	 */
 	void (*copyData)(const struct ShaderFxData *fx, struct ShaderFxData *target);
 
-	/* create pass */
-	/* set shading group */
 	/* apply effect */
-	void(*generateStrokes)(struct GpencilModifierData *md, struct Depsgraph *depsgraph,
-		struct Object *ob, struct bGPDlayer *gpl, struct bGPDframe *gpf);
+	void(*applyEffect)(struct ShaderFxData *md, struct Depsgraph *depsgraph,
+		struct Object *ob);
 
 	/********************* Optional functions *********************/
 
@@ -185,7 +181,7 @@ typedef struct ShaderFxTypeInfo {
 /* Initialize  global data (type info and some common global storages). */
 void BKE_shaderfx_init(void);
 
-const ShaderFxTypeInfo *BKE_shaderfx_Type_getInfo(ShaderFxType type);
+const ShaderFxTypeInfo *BKE_shaderfxType_getInfo(ShaderFxType type);
 struct ShaderFxData  *BKE_shaderfx_new(int type);
 void BKE_shaderfx_free_ex(struct ShaderFxData *fx, const int flag);
 void BKE_shaderfx_free(struct ShaderFxData *fx);
@@ -199,8 +195,7 @@ void BKE_shaderfx_copyData_ex(struct ShaderFxData *fx, struct ShaderFxData *targ
 void BKE_shaderfx_foreachIDLink(struct Object *ob, ShaderFxIDWalkFunc walk, void *userData);
 void BKE_shaderfx_foreachTexLink(struct Object *ob, ShaderFxTexWalkFunc walk, void *userData);
 
-void BKE_shaderfx_stroke_modifiers(
-	struct Depsgraph *depsgraph, struct Object *ob,
-	struct bGPDlayer *gpl, struct bGPDframe *gpf, struct bGPDstroke *gps, bool is_render);
+void BKE_shaderfx_apply(
+	struct Depsgraph *depsgraph, struct Object *ob, bool is_render);
 
 #endif /* __BKE_SHADER_FX_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index cc381a4ba0b..889a5a211a9 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -305,6 +305,7 @@ set(SRC
 	BKE_scene.h
 	BKE_screen.h
 	BKE_sequencer.h
+	BKE_shader_fx.h
 	BKE_shrinkwrap.h
 	BKE_smoke.h
 	BKE_softbody.h
diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c
index e71ec512ec1..1618c415fab 100644
--- a/source/blender/blenkernel/intern/shader_fx.c
+++ b/source/blender/blenkernel/intern/shader_fx.c
@@ -43,446 +43,87 @@
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 #include "DNA_gpencil_types.h"
-#include "DNA_gpencil_modifier_types.h"
+#include "DNA_shader_fx_types.h"
 
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
 #include "BKE_gpencil.h"
-#include "BKE_lattice.h"
-#include "BKE_gpencil_modifier.h"
+#include "BKE_shader_fx.h"
 #include "BKE_object.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
-#include "MOD_gpencil_modifiertypes.h"
+#include "FX_shader_types.h"
 
-static GpencilModifierTypeInfo *modifier_gpencil_types[NUM_GREASEPENCIL_MODIFIER_TYPES] = { NULL };
+static ShaderFxTypeInfo *shader_fx_types[NUM_SHADER_FX_TYPES] = { NULL };
 
 /* *************************************************** */
-/* Geometry Utilities */
+/* Methods - Evaluation Loops, etc. */
 
-/* calculate stroke normal using some points */
-void BKE_gpencil_stroke_normal(const bGPDstroke *gps, float r_normal[3])
+/* check if exist grease pencil effects */
+bool BKE_shaderfx_has_gpencil(Object *ob)
 {
-	if (gps->totpoints < 3) {
-		zero_v3(r_normal);
-		return;
-	}
-
-	bGPDspoint *points = gps->points;
-	int totpoints = gps->totpoints;
-
-	const bGPDspoint *pt0 = &points[0];
-	const bGPDspoint *pt1 = &points[1];
-	const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
-
-	float vec1[3];
-	float vec2[3];
-
-	/* initial vector (p0 -> p1) */
-	sub_v3_v3v3(vec1, &pt1->x, &pt0->x);
-
-	/* point vector at 3/4 */
-	sub_v3_v3v3(vec2, &pt3->x, &pt0->x);
-
-	/* vector orthogonal to polygon plane */
-	cross_v3_v3v3(r_normal, vec1, vec2);
-
-	/* Normalize vector */
-	normalize_v3(r_normal);
-}
-
-/* Get points of stroke always flat to view not affected by camera view or view position */
-static void gpencil_stroke_project_2d(const bGPDspoint *points, int totpoints, vec2f *points2d)
-{
-	const bGPDspoint *pt0 = &points[0];
-	const bGPDspoint *pt1 = &points[1];
-	const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
-
-	float locx[3];
-	float locy[3];
-	float loc3[3];
-	float normal[3];
-
-	/* local X axis (p0 -> p1) */
-	sub_v3_v3v3(locx, &pt1->x, &pt0->x);
-
-	/* point vector at 3/4 */
-	sub_v3_v3v3(loc3, &pt3->x, &pt0->x);
-
-	/* vector orthogonal to polygon plane */
-	cross_v3_v3v3(normal, locx, loc3);
-
-	/* local Y axis (cross to normal/x axis) */
-	cross_v3_v3v3(locy, normal, locx);
-
-	/* Normalize vectors */
-	normalize_v3(locx);
-	normalize_v3(locy);
-
-	/* Get all points in local space */
-	for (int i = 0; i < totpoints; i++) {
-		const bGPDspoint *pt = &points[i];
-		float loc[3];
-
-		/* Get local space using first point as origin */
-		sub_v3_v3v3(loc, &pt->x, &pt0->x);
-
-		vec2f *point = &points2d[i];
-		point->x = dot_v3v3(loc, locx);
-		point->y = dot_v3v3(loc, locy);
-	}
-
-}
-
-/* Stroke Simplify ------------------------------------- */
-
-/* Reduce a series of points to a simplified version, but
- * maintains the general shape of the series
- *
- * Ramer - Douglas - Peucker algorithm
- * by http ://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
- */
-static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
-{
-	vec2f *old_points2d = points2d;
-	int totpoints = gps->totpoints;
-	char *marked = NULL;
-	char work;
-
-	int start = 1;
-	int end = gps->totpoints - 2;
-
-	marked = MEM_callocN(totpoints, "GP marked array");
-	marked[start] = 1;
-	marked[end] = 1;
-
-	work = 1;
-	int totmarked = 0;
-	/* while still reducing */
-	while (work) {
-		int ls, le;
-		work = 0;
-
-		ls = start;
-		le = start + 1;
-
-		/* while not over interval */
-		while (ls < end) {
-			int max_i = 0;
-			float v1[2];
-			/* divided to get more control */
-			float max_dist = epsilon / 10.0f;
-
-			/* find the next marked point */
-			while (marked[le] == 0) {
-				le++;
-			}
-
-			/* perpendicular vector to ls-le */
-			v1[1] = old_points2d[le].x - old_points2d[ls].x;
-			v1[0] = old_points2d[ls].y - old_points2d[le].y;
-
-			for (int i = ls + 1; i < le; i++) {
-				float mul;
-				float dist;
-				float v2[2];
-
-				v2[0] = old_points2d[i].x - old_points2d[ls].x;
-				v2[1] = old_points2d[i].y - old_points2d[ls].y;
-
-				if (v2[0] == 0 && v2[1] == 0) {
-					continue;
-				}
-
-				mul = (float)(v1[0] * v2[0] + v1[1] * v2[1]) / (float)(v2[0] * v2[0] + v2[1] * v2[1]);
-
-				dist = mul * mul * (v2[0] * v2[0] + v2[1] * v2[1]);
-
-				if (dist > max_dist) {
-					max_dist = dist;
-					max_i = i;
-				}
-			}
-
-			if (max_i != 0) {
-				work = 1;
-				marked[max_i] = 1;
-				totmarked++;
-			}
-
-			ls = le;
-			le = ls + 1;
-		}
-	}
-
-	/* adding points marked */
-	bGPDspoint *old_points = MEM_dupallocN(gps->points);
-	MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
-
-	/* resize gps */
-	gps->flag |= GP_STROKE_RECALC_CACHES;
-	gps->tot_triangles = 0;
-
-	int j = 0;
-	for (int i = 0; i < totpoints; i++) {
-		bGPDspoint *pt_src = &old_points[i];
-		bGPDspoint *pt = &gps->points[j];
-
-		MDeformVert *dvert_src = &old_dvert[i];
-		MDeformVert *dvert = &gps->dvert[j];
-
-		if ((marked[i]) || (i == 0) || (i == totpoints - 1)) {
-			memcpy(pt, pt_src, sizeof(bGPDspoint));
-			memcpy(dvert, dvert_src, sizeof(MDeformVert));
-			j++;
-		}
-		else {
-			BKE_gpencil_free_point_weights(dvert_src);
-		}
-	}
-
-	gps->totpoints = j;
-
-	MEM_SAFE_FREE(old_points);
-	MEM_SAFE_FREE(old_dvert);
-	MEM_SAFE_FREE(marked);
-}
-
-/* Simplify stroke using Ramer-Douglas-Peucker algorithm */
-void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float factor)
-{
-	/* first create temp data and convert points to 2D */
-	vec2f *points2d = MEM_mallocN(sizeof(vec2f) * gps->totpoints, "GP Stroke temp 2d points");
-
-	gpencil_stroke_project_2d(gps->points, gps->totpoints, points2d);
-
-	gpencil_rdp_stroke(gps, points2d, factor);
-
-	MEM_SAFE_FREE(points2d);
-}
-
-/* Simplify alternate vertex of stroke except extrems */
-void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
-{
-	if (gps->totpoints < 5) {
-		return;
-	}
-
-	/* save points */
-	bGPDspoint *old_points = MEM_dupallocN(gps->points);
-	MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
-
-	/* resize gps */
-	int newtot = (gps->totpoints - 2) / 2;
-	if (((gps->totpoints - 2) % 2) > 0) {
-		newtot++;
-	}
-	newtot += 2;
-
-	gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
-	gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
-	gps->flag |= GP_STROKE_RECALC_CACHES;
-	gps->tot_triangles = 0;
-
-	int j = 0;
-	for (int i = 0; i < gps->totpoints; i++) {
-		bGPDspoint *pt_src = &old_points[i];
-		bGPDspoint *pt = &gps->points[j];
-
-		MDeformVert *dvert_src = &old_dvert[i];
-		MDeformVert *dvert = &gps->dvert[j];
-
-		if ((i == 0) || (i == gps->totpoints - 1) || ((i % 2) > 0.0)) {
-			memcpy(pt, pt_src, sizeof(bGPDspoint));
-			memcpy(dvert, dvert_src, sizeof(MDeformVert));
-			j++;
-		}
-		else {
-			BKE_gpencil_free_point_weights(dvert_src);
-		}
-	}
-
-	gps->totpoints = j;
-
-	MEM_SAFE_FREE(old_points);
-	MEM_SAFE_FREE(old_dvert);
-}
-
-/* *************************************************** */
-/* Modifier Utilities */
-
-/* Lattice Modifier ---------------------------------- */
-/* Usually, evaluation of the lattice modifier is self-contained.
- * However, since GP's modifiers operate on a per-stroke basis,
- * we need to these two extra functions that called before/after
- * each loop over all the geometry 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list