[Bf-blender-cvs] [f988869434c] greasepencil-refactor: GPencil: Add support for Object In Front option
Antonio Vazquez
noreply at git.blender.org
Tue Jan 21 18:06:32 CET 2020
Commit: f988869434c39d430aefe2b416c3a6bc12d5e1d4
Author: Antonio Vazquez
Date: Tue Jan 21 18:02:58 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBf988869434c39d430aefe2b416c3a6bc12d5e1d4
GPencil: Add support for Object In Front option
Still need a small change in RNA to tag datablock when property is changed.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_cache_utils.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_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 974ef244340..be8e50cbb0f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -99,7 +99,13 @@ GPENCIL_tObject *gpencil_object_cache_add(GPENCIL_PrivateData *pd, Object *ob)
rescale_m4(tgp_ob->plane_mat, (float[3]){radius, radius, radius});
copy_v3_v3(tgp_ob->plane_mat[3], center);
- BLI_LINKS_APPEND(&pd->tobjects, tgp_ob);
+ /* Add to corresponding list if is in front. */
+ if (ob->dtx & OB_DRAWXRAY) {
+ BLI_LINKS_APPEND(&pd->tobjects_infront, tgp_ob);
+ }
+ else {
+ BLI_LINKS_APPEND(&pd->tobjects, tgp_ob);
+ }
return tgp_ob;
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 545f1a2cfae..b463c4c8ddc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -92,6 +92,8 @@ void GPENCIL_engine_init(void *ved)
stl->pd->last_material_pool = NULL;
stl->pd->tobjects.first = NULL;
stl->pd->tobjects.last = NULL;
+ stl->pd->tobjects_infront.first = NULL;
+ stl->pd->tobjects_infront.last = NULL;
stl->pd->sbuffer_tobjects.first = NULL;
stl->pd->sbuffer_tobjects.last = NULL;
stl->pd->dummy_tx = txl->dummy_texture;
@@ -454,6 +456,7 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
(iter->ob->dtx & OB_USE_GPENCIL_LIGHTS);
iter->ubo_lights = (use_lights) ? iter->pd->global_light_pool->ubo :
iter->pd->shadeless_light_pool->ubo;
+ const bool is_in_front = (iter->ob->dtx & OB_DRAWXRAY);
bool overide_vertcol = (iter->pd->v3d_color_type != -1);
bool is_vert_col_mode = (iter->pd->v3d_color_type == V3D_SHADING_VERTEX_COLOR) ||
@@ -461,13 +464,16 @@ static void gp_layer_cache_populate(bGPDlayer *gpl,
float vert_col_opacity = (overide_vertcol) ? (is_vert_col_mode ? 1.0f : 0.0f) :
gpl->vertex_paint_opacity;
+ /* Check if object is defined in front. */
+ GPUTexture *depth_tex = (is_in_front) ? iter->pd->dummy_tx : iter->pd->scene_depth_tx;
+
struct GPUShader *sh = GPENCIL_shader_geometry_get();
iter->grp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
DRW_shgroup_uniform_block_persistent(iter->grp, "gpLightBlock", iter->ubo_lights);
DRW_shgroup_uniform_block(iter->grp, "gpMaterialBlock", iter->ubo_mat);
DRW_shgroup_uniform_texture(iter->grp, "gpFillTexture", iter->tex_fill);
DRW_shgroup_uniform_texture(iter->grp, "gpStrokeTexture", iter->tex_stroke);
- DRW_shgroup_uniform_texture(iter->grp, "gpSceneDepthTexture", iter->pd->scene_depth_tx);
+ DRW_shgroup_uniform_texture(iter->grp, "gpSceneDepthTexture", depth_tex);
DRW_shgroup_uniform_int_copy(iter->grp, "gpMaterialOffset", iter->mat_ofs);
DRW_shgroup_uniform_bool_copy(iter->grp, "strokeOrder3d", is_stroke_order_3d);
DRW_shgroup_uniform_vec3_copy(iter->grp, "gpNormal", iter->tgp_ob->plane_normal);
@@ -696,7 +702,34 @@ void GPENCIL_cache_finish(void *ved)
}
/* Sort object by distance to the camera. */
- pd->tobjects.first = gpencil_tobject_sort_fn_r(pd->tobjects.first, gpencil_tobject_dist_sort);
+ if (pd->tobjects.first) {
+ pd->tobjects.first = gpencil_tobject_sort_fn_r(pd->tobjects.first, gpencil_tobject_dist_sort);
+ /* Relink last pointer. */
+ while ((pd->tobjects.last->next != NULL)) {
+ pd->tobjects.last = pd->tobjects.last->next;
+ }
+ }
+ if (pd->tobjects_infront.first) {
+ pd->tobjects_infront.first = gpencil_tobject_sort_fn_r(pd->tobjects_infront.first,
+ gpencil_tobject_dist_sort);
+ /* Relink last pointer. */
+ while ((pd->tobjects_infront.last->next != NULL)) {
+ pd->tobjects_infront.last = pd->tobjects_infront.last->next;
+ }
+ }
+
+ /* Join both lists, adding infront. */
+ if (pd->tobjects_infront.first != NULL) {
+ if (pd->tobjects.last != NULL) {
+ pd->tobjects.last->next = pd->tobjects_infront.first;
+ pd->tobjects.last = pd->tobjects_infront.last;
+ }
+ else {
+ /* Only in front objects. */
+ pd->tobjects.first = pd->tobjects_infront.first;
+ pd->tobjects.last = pd->tobjects_infront.last;
+ }
+ }
/* Create framebuffers only if needed. */
if (pd->tobjects.first) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index dfb5ba92353..cfee730cd18 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -251,7 +251,7 @@ typedef struct GPENCIL_PrivateData {
/* Linked list of tObjects. */
struct {
GPENCIL_tObject *first, *last;
- } tobjects;
+ } tobjects, tobjects_infront;
/* Temp Textures (shared with other engines). */
GPUTexture *depth_tx;
GPUTexture *color_tx;
More information about the Bf-blender-cvs
mailing list