[Bf-blender-cvs] [693dfda0355] greasepencil-object: WIP: adjust the shift factor with distance
Antonio Vazquez
noreply at git.blender.org
Sun Jun 18 21:07:44 CEST 2017
Commit: 693dfda035583df22c7ae86baa1fae740e8b5494
Author: Antonio Vazquez
Date: Sun Jun 18 19:46:08 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB693dfda035583df22c7ae86baa1fae740e8b5494
WIP: adjust the shift factor with distance
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
M source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.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 788952454af..d4b14d23434 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -159,7 +159,8 @@ static GpencilBatchCache *gpencil_batch_cache_get(bGPdata *gpd, int cfra)
}
/* create shading group for filling */
-static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, bGPdata *gpd, PaletteColor *palcolor, int id)
+static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
+ bGPdata *gpd, PaletteColor *palcolor, int id, float zdepth)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -214,6 +215,21 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_Data *vedata, DR
}
}
+ /* object scale and depth */
+ if ((ob) && (id > -1)) {
+ stl->shgroups[id].obj_scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
+ stl->shgroups[id].obj_zdepth = zdepth;
+ DRW_shgroup_uniform_float(grp, "objscale", &stl->shgroups[id].obj_scale, 1);
+ DRW_shgroup_uniform_float(grp, "obj_zdepth", &stl->shgroups[id].obj_zdepth, 1);
+ }
+ else {
+ stl->storage->objscale = 1.0f;
+ stl->storage->zdepth = 0.0f;
+ DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->objscale, 1);
+ DRW_shgroup_uniform_float(grp, "obj_zdepth", &stl->storage->zdepth, 1);
+ }
+
+
return grp;
}
@@ -227,7 +243,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(DRWPass *pass, GPUS
}
/* create shading group for strokes */
-DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob, bGPdata *gpd, int id)
+DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
+ bGPdata *gpd, int id, float zdepth)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const float *viewport_size = DRW_viewport_size_get();
@@ -239,14 +256,19 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass
DRW_shgroup_uniform_float(grp, "pixsize", DRW_viewport_pixelsize_get(), 1);
DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
- /* object scale */
- stl->storage->objscale = 1.0f;
- float scale;
- if (ob) {
- scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
- stl->storage->objscale = scale;
+ /* object scale and depth */
+ if ((ob) && (id > -1)) {
+ stl->shgroups[id].obj_scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
+ stl->shgroups[id].obj_zdepth = zdepth;
+ DRW_shgroup_uniform_float(grp, "objscale", &stl->shgroups[id].obj_scale, 1);
+ DRW_shgroup_uniform_float(grp, "obj_zdepth", &stl->shgroups[id].obj_zdepth, 1);
+ }
+ else {
+ stl->storage->objscale = 1.0f;
+ stl->storage->zdepth = 0.0f;
+ DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->objscale, 1);
+ DRW_shgroup_uniform_float(grp, "obj_zdepth", &stl->storage->zdepth, 1);
}
- DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->objscale, 1);
/* If disable zoom for strokes, disable scale */
if ((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS)) {
@@ -388,7 +410,7 @@ static void gpencil_add_editpoints_shgroup(GPENCIL_StorageList *stl, GpencilBatc
/* main function to draw strokes */
static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_data, void *vedata, ToolSettings *ts, Object *ob,
bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf,
- const float opacity, const float tintcolor[4], const bool onion, const bool custonion)
+ const float opacity, const float tintcolor[4], const bool onion, const bool custonion, float zdepth)
{
GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -423,10 +445,10 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
if (gps->totpoints > 1) {
int id = stl->storage->pal_id;
stl->shgroups[id].sort = stl->g_data->main_sort;
- stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, e_data->gpencil_fill_sh, gpd, gps->palcolor, id);
- stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd, id);
+ stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id, zdepth);
+ stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd, id, zdepth);
++stl->storage->pal_id;
- stl->g_data->main_sort += 6;
+ stl->g_data->main_sort += 15;
fillgrp = stl->shgroups[id].shgrps_fill;
strokegrp = stl->shgroups[id].shgrps_stroke;
@@ -486,7 +508,8 @@ static void gpencil_draw_buffer_strokes(GpencilBatchCache *cache, void *vedata,
}
/* draw onion-skinning for a layer */
-static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_data, void *vedata, ToolSettings *ts, Object *ob, bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf)
+static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_data, void *vedata,
+ ToolSettings *ts, Object *ob, bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, float zdepth)
{
const float default_color[3] = { UNPACK3(U.gpencil_new_layer_col) };
const float alpha = 1.0f;
@@ -508,7 +531,7 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
/* alpha decreases with distance from curframe index */
float fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1));
color[3] = alpha * fac * 0.66f;
- gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gf, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_PREVCOL);
+ gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gf, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_PREVCOL, zdepth);
}
else
break;
@@ -518,7 +541,7 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
/* draw the strokes for the ghost frames (at half of the alpha set by user) */
if (gpf->prev) {
color[3] = (alpha / 7);
- gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf->prev, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_PREVCOL);
+ gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf->prev, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_PREVCOL, zdepth);
}
}
else {
@@ -541,7 +564,7 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
/* alpha decreases with distance from curframe index */
float fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1));
color[3] = alpha * fac * 0.66f;
- gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gf, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_NEXTCOL);
+ gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gf, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_NEXTCOL, zdepth);
}
else
break;
@@ -551,7 +574,7 @@ static void gpencil_draw_onionskins(GpencilBatchCache *cache, GPENCIL_e_data *e_
/* draw the strokes for the ghost frames (at half of the alpha set by user) */
if (gpf->next) {
color[3] = (alpha / 4);
- gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf->next, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_NEXTCOL);
+ gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf->next, 1.0f, color, true, gpl->flag & GP_LAYER_GHOST_NEXTCOL, zdepth);
}
}
else {
@@ -566,7 +589,20 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data, void *vedata, Scene
printf("DRW_gpencil_populate_datablock for %s\n", gpd->id.name);
}
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
- stl->g_data->main_sort = 0;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ /* get object zdepth */
+ float zdepth = 0.0;
+ if (ob) {
+ if (rv3d->is_persp) {
+ zdepth = ED_view3d_calc_zfac(rv3d, ob->loc, NULL);
+ }
+ else {
+ zdepth = -dot_v3v3(rv3d->viewinv[2], ob->loc);
+ }
+ }
+
+ stl->g_data->main_sort = -300;
GpencilBatchCache *cache = gpencil_batch_cache_get(gpd, CFRA);
cache->cache_idx = 0;
@@ -582,13 +618,13 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data, void *vedata, Scene
/* draw onion skins */
if ((gpl->flag & GP_LAYER_ONIONSKIN) || (gpl->flag & GP_LAYER_GHOST_ALWAYS))
{
- gpencil_draw_onionskins(cache, e_data, vedata, ts, ob, gpd, gpl, gpf);
+ gpencil_draw_onionskins(cache, e_data, vedata, ts, ob, gpd, gpl, gpf, zdepth);
}
/* draw normal strokes */
- gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf, gpl->opacity, gpl->tintcolor, false, false);
+ gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, gpf, gpl->opacity, gpl->tintcolor, false, false, zdepth);
/* separate layers */
- stl->g_data->main_sort += 20;
+ stl->g_data->main_sort += 40;
}
/* draw current painting strokes */
gpencil_draw_buffer_strokes(cache, vedata, ts, gpd);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 9b7f3fd2cf8..79ea17c7c21 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -125,7 +125,7 @@ static void GPENCIL_cache_init(void *vedata)
/* drawing buffer pass */
psl->drawing_pass = DRW_pass_create("Gpencil Drawing Pass", state);
- stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, -1);
+ stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, -1, 0.0);
stl->g_data->shgrps_drawing_fill = DRW_gpencil_shgroup_drawing_fill_create(psl->drawing_pass, e_data.gpencil_drawing_fill_sh);
}
}
diff --git a/source/blender/draw/engine
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list