[Bf-blender-cvs] [3e468e5556d] greasepencil-object: WIP: Improved use of UV along the path and speedup
Antonio Vazquez
noreply at git.blender.org
Tue Feb 20 17:02:10 CET 2018
Commit: 3e468e5556d6d245c4dfec52c0cc37693818baff
Author: Antonio Vazquez
Date: Mon Feb 19 17:54:00 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB3e468e5556d6d245c4dfec52c0cc37693818baff
WIP: Improved use of UV along the path and speedup
Now the texture is calculated using the pixelsize along the stroke.
Added a precalculation of fill and Uvs caches in order to avoid recalculation on frame change. This makes first play a little more slow (few miliseconds), but the next time the frame is used, all cache data is precalculated and the overall FPS is better when use fill strokes.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/gpencil_geom.c
M source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
M source/blender/makesdna/DNA_gpencil_types.h
===================================================================
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 25a24ea416b..228d4ddaff0 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -714,6 +714,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
*/
const DRWContextState *draw_ctx = DRW_context_state_get();
const bContext *C = draw_ctx->evil_C;
+ RegionView3D *rv3d = draw_ctx->rv3d;
EvaluationContext eval_ctx = {0};
if (C) {
@@ -752,6 +753,13 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
if (stl->storage->shgroup_id >= GPENCIL_MAX_SHGROUPS) {
continue;
}
+
+ /* be sure recalc all chache in source stroke to avoid recalculation when frame change
+ * and improve fps */
+ if (src_gps) {
+ DRW_gpencil_recalc_geometry_caches(src_gps, rv3d);
+ }
+
/* if the fill has any value, it's considered a fill and is not drawn if simplify fill is enabled */
if ((GP_SIMPLIFY_FILL(ts, playing)) && (ts->gpencil_simplify & GP_TOOL_FLAG_SIMPLIFY_REMOVE_LINE)) {
if ((gps->palcolor->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH) ||
@@ -812,11 +820,6 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
}
/* stroke */
if (strokegrp) {
- /* be sure UVs are ready */
- if (gps->flag & GP_STROKE_RECALC_CACHES) {
- ED_gpencil_calc_stroke_uv(gps, GPENCIL_STROKE_UV);
- gps->flag &= ~GP_STROKE_RECALC_CACHES;
- }
gpencil_add_stroke_shgroup(cache, strokegrp, ob, gpd, gpl, derived_gpf, gps, opacity, tintcolor, false, custonion);
}
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ff1cd627f7f..ea5bf27109e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -31,6 +31,7 @@
struct tGPspoint;
struct ModifierData;
struct GPENCIL_StorageList;
+struct RegionView3D;
/* TODO: these could be system parameter in userprefs screen */
#define GPENCIL_MAX_GP_OBJ 256
@@ -338,6 +339,8 @@ struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float
struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(struct bGPdata *gpd);
struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
+void DRW_gpencil_recalc_geometry_caches(struct bGPDstroke *gps, struct RegionView3D *rv3d);
+
struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height);
bool gpencil_can_draw_stroke(const struct bGPDstroke *gps, const bool onion);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 630cb1ad8f3..f307ad9dcea 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -602,16 +602,40 @@ static void gpencil_set_fill_point(
GWN_vertbuf_attr_set(vbo, text_id, idx, uv);
}
+/* recalc the internal geometry caches for fill and uvs */
+void DRW_gpencil_recalc_geometry_caches(bGPDstroke *gps, RegionView3D *rv3d) {
+ if (gps->flag & GP_STROKE_RECALC_CACHES) {
+ /* Calculate triangles cache for filling area (must be done only after changes) */
+ if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
+ if ((gps->totpoints > 2) &&
+ ((gps->palcolor->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gps->palcolor->fill_style > 0)))
+ {
+ gp_triangulate_stroke_fill(gps);
+ }
+ }
+
+ /* calc uv data along the stroke */
+ ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
+
+ /* clear flag */
+ gps->flag &= ~GP_STROKE_RECALC_CACHES;
+ }
+}
+
/* create batch geometry data for stroke shader */
Gwn_Batch *DRW_gpencil_get_fill_geom(bGPDstroke *gps, const float color[4])
{
BLI_assert(gps->totpoints >= 3);
-
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ RegionView3D *rv3d = draw_ctx->rv3d;
+
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
gp_triangulate_stroke_fill(gps);
- ED_gpencil_calc_stroke_uv(gps, GPENCIL_STROKE_UV);
+ ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
}
+
BLI_assert(gps->tot_triangles >= 1);
static Gwn_VertFormat format = { 0 };
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index 80bdf8682ad..fad10bebff1 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -16,10 +16,10 @@ out vec4 fragColor;
void main()
{
- vec2 center = vec2(uvfac, 1.0);
vec4 tColor = vec4(mColor);
/* if alpha < 0, then encap */
if (mColor.a < 0) {
+ vec2 center = vec2(uvfac, 1.0);
tColor.a = tColor.a * -1.0;
float dist = length(mTexCoord - center);
if (dist > 0.50) {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 4e2b74357ba..9faf89dd2a0 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -773,7 +773,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
bGPDbrush *brush = p->brush;
ToolSettings *ts = p->scene->toolsettings;
Object *obact = (Object *)p->ownerPtr.data;
-
+ RegionView3D *rv3d = p->ar->regiondata;
+
int i, totelem;
/* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
int depth_margin = (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 4 : 0;
@@ -1016,15 +1017,15 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
MEM_freeN(depth_arr);
}
- /* calculate UVs along the stroke */
- ED_gpencil_calc_stroke_uv(gps, GPENCIL_STROKE_UV);
-
/* Save palette color */
gps->palette = p->palette;
gps->palcolor = p->palettecolor;
if (p->palettecolor)
BLI_strncpy(gps->colorname, p->palettecolor->info, sizeof(gps->colorname));
+ /* calculate UVs along the stroke */
+ ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
+
/* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke is added on listbase head
* because the drawing order is inverse and the head stroke is the first to draw. This is very useful for artist
* when drawing the background
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 2b72ecf5399..488e8e986ea 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1527,13 +1527,15 @@ void ED_gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
}
/* texture coordinate utilities */
-void ED_gpencil_calc_stroke_uv(bGPDstroke *gps, float factor)
+void ED_gpencil_calc_stroke_uv(bGPDstroke *gps, float pixsize)
{
if (gps == NULL) {
return;
}
+
bGPDspoint *pt = NULL;
bGPDspoint *ptb = NULL;
+ PaletteColor *palcolor = gps->palcolor;
int i;
float totlen = 0;
@@ -1543,18 +1545,22 @@ void ED_gpencil_calc_stroke_uv(bGPDstroke *gps, float factor)
/* first point */
if (i == 0) {
pt->uv_fac = 0.0f;
- pt->uv_rot = 0.0f;
continue;
}
ptb = &gps->points[i - 1];
- totlen += len_v3v3(&pt->x, &ptb->x);
-
+ totlen += len_v3v3(&pt->x, &ptb->x) / pixsize;
pt->uv_fac = totlen;
- pt->uv_rot = 0.0f;
}
-
/* normalize the distance using a factor */
+ float factor;
+ /* if image, use texture width */
+ if ((palcolor) && (palcolor->sima)) {
+ factor = palcolor->sima->gen_x;
+ }
+ else {
+ factor = totlen;
+ }
for (i = 0; i < gps->totpoints; i++) {
pt = &gps->points[i];
pt->uv_fac /= factor;
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 8c64b42480a..2de5b3fb56b 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -212,7 +212,6 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
/* texture coordinate utilities */
-#define GPENCIL_STROKE_UV 1.0f /* TODO: Replace by brush parameter */
-void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps, float factor);
+void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps, float pixsize);
#endif /* __ED_GPENCIL_H__ */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 4e962ee9985..aea11c612ff 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -68,7 +68,7 @@ typedef struct bGPDspoint {
int flag; /* additional options (NOTE: can shrink this field down later if needed) */
float uv_fac; /* factor of uv along the stroke */
- float uv_rot; /* uv rotation for dor mode */
+ float uv_rot; /* uv rotation for dot mode */
int totweight; /* number of vertexgroups used */
bGPDweight *weights; /* vertex weight data */
More information about the Bf-blender-cvs
mailing list