[Bf-blender-cvs] [6a51a610743] greasepencil-refactor: GPencil: Refactor: Remove image size from uv computation
Clément Foucault
noreply at git.blender.org
Tue Dec 31 19:31:15 CET 2019
Commit: 6a51a610743cef40286750357204c679d8990136
Author: Clément Foucault
Date: Mon Dec 30 20:49:08 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB6a51a610743cef40286750357204c679d8990136
GPencil: Refactor: Remove image size from uv computation
Now UVs for line strokes is computed using only the pixel factor.
We can reintroduce the image size behavior easilly if needed but in a much
cleaner way.
===================================================================
M source/blender/blenkernel/intern/gpencil.c
M source/blender/draw/engines/gpencil/gpencil_draw_data.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_primitive.c
===================================================================
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 8152433acfd..b8b59823235 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2789,57 +2789,16 @@ void BKE_gpencil_triangulate_stroke_fill(bGPdata *gpd, bGPDstroke *gps)
/* texture coordinate utilities */
void BKE_gpencil_calc_stroke_uv(Object *ob, bGPDstroke *gps)
{
- if (gps == NULL) {
+ if (gps == NULL || gps->totpoints == 0) {
return;
}
- MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
- float pixsize;
- if (gp_style) {
- pixsize = gp_style->texture_pixsize / 1000000.0f;
- }
- else {
- /* use this value by default */
- pixsize = 0.0001f;
- }
- pixsize = MAX2(pixsize, 0.0000001f);
- bGPDspoint *pt = NULL;
- bGPDspoint *ptb = NULL;
- int i;
+ bGPDspoint *pt = gps->points;
float totlen = 0.0f;
-
- /* first read all points and calc distance */
- for (i = 0; i < gps->totpoints; i++) {
- pt = &gps->points[i];
- /* first point */
- if (i == 0) {
- pt->uv_fac = 0.0f;
- continue;
- }
-
- ptb = &gps->points[i - 1];
- totlen += len_v3v3(&pt->x, &ptb->x) / pixsize;
- pt->uv_fac = totlen;
- }
-
- /* normalize the distance using a factor */
- float factor;
-
- /* if image, use texture width */
- if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) &&
- (gp_style->sima)) {
- factor = gp_style->sima->gen_x;
- }
- else if (totlen == 0) {
- return;
- }
- else {
- factor = totlen;
- }
-
- for (i = 0; i < gps->totpoints; i++) {
- pt = &gps->points[i];
- pt->uv_fac /= factor;
+ pt[0].uv_fac = totlen;
+ for (int i = 1; i < gps->totpoints; i++) {
+ totlen += len_v3v3(&pt[i - 1].x, &pt[i].x);
+ pt[i].uv_fac = totlen;
}
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 04a3a6795dc..156a5f10cfa 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -151,13 +151,13 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
/* Stroke Style */
if ((gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
- /* TODO finish. */
bool premul;
pool->tex_stroke[mat_id] = gpencil_image_texture_get(gp_style->sima, &premul);
mat_data->flag |= pool->tex_stroke[mat_id] ? GP_STROKE_TEXTURE_USE : 0;
mat_data->flag |= premul ? GP_STROKE_TEXTURE_PREMUL : 0;
copy_v4_v4(mat_data->stroke_color, gp_style->stroke_rgba);
mat_data->stroke_texture_mix = 1.0f - gp_style->mix_stroke_factor;
+ mat_data->stroke_u_scale = 500.0f / gp_style->texture_pixsize;
}
else /* if (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_SOLID) */ {
pool->tex_stroke[mat_id] = NULL;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 20a70aa2783..020d6e5de66 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -67,7 +67,7 @@ typedef struct gpMaterial {
float fill_mix_color[4];
float fill_uv_transform[3][2], _pad0[2];
float stroke_texture_mix;
- float stroke_uv_factor;
+ float stroke_u_scale;
float fill_texture_mix;
int flag;
} gpMaterial;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index 9bc861ea614..4cf332b8a1d 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -245,6 +245,7 @@ void stroke_vertex()
gl_Position.xy += screen_ofs * sizeViewportInv.xy * thickness;
finalUvs.x = (use_curr) ? uv1.z : uv2.z;
+ finalUvs.x *= materials[m].stroke_u_scale;
}
vec4 vert_col = (use_curr) ? col1 : col2;
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 86f2231058b..5bb5ecac5a4 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -689,7 +689,6 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
tGPspoint *pt;
Object *obact = (Object *)p->ownerPtr.data;
RegionView3D *rv3d = p->ar->regiondata;
- MaterialGPencilStyle *gp_style = p->material->gp_style;
/* check painting mode */
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -801,7 +800,6 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
/* point uv (only 3d view) */
if ((p->sa->spacetype == SPACE_VIEW3D) && (gpd->runtime.sbuffer_used > 0)) {
- float pixsize = gp_style->texture_pixsize / 1000000.0f;
tGPspoint *ptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
bGPDspoint spt, spt2;
@@ -815,11 +813,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
/* reproject previous */
ED_gpencil_tpoint_to_point(p->ar, origin, ptb, &spt2);
ED_gp_project_point_to_plane(p->scene, obact, rv3d, origin, p->lock_axis - 1, &spt2);
- p->totpixlen += len_v3v3(&spt.x, &spt2.x) / pixsize;
+ p->totpixlen += len_v3v3(&spt.x, &spt2.x);
pt->uv_fac = p->totpixlen;
- if ((gp_style) && (gp_style->sima)) {
- pt->uv_fac /= gp_style->sima->gen_x;
- }
}
else {
p->totpixlen = 0.0f;
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 66ac9ecccb3..b45faf8120f 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -998,8 +998,6 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* point uv */
if (gpd->runtime.sbuffer_used > 0) {
- MaterialGPencilStyle *gp_style = tgpi->mat->gp_style;
- const float pixsize = gp_style->texture_pixsize / 1000000.0f;
tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
bGPDspoint spt, spt2;
@@ -1015,11 +1013,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
ED_gpencil_tpoint_to_point(tgpi->ar, origin, tptb, &spt2);
ED_gp_project_point_to_plane(
tgpi->scene, tgpi->ob, tgpi->rv3d, origin, tgpi->lock_axis - 1, &spt2);
- tgpi->totpixlen += len_v3v3(&spt.x, &spt2.x) / pixsize;
+ tgpi->totpixlen += len_v3v3(&spt.x, &spt2.x);
tpt->uv_fac = tgpi->totpixlen;
- if ((gp_style) && (gp_style->sima)) {
- tpt->uv_fac /= gp_style->sima->gen_x;
- }
}
else {
tgpi->totpixlen = 0.0f;
More information about the Bf-blender-cvs
mailing list