GPv3: Canvas overlay
This implements the "Canvas" overlay for GPv3. Some things of note: - The color and subdivision are hard coded for now - The scale and offset have been removed for now Pull Request: https://projects.blender.org/blender/blender/pulls/126248
This commit is contained in:
committed by
Falk David
parent
db6113048d
commit
92155db27a
@@ -229,6 +229,7 @@ static void OVERLAY_cache_init(void *vedata)
|
||||
OVERLAY_mode_transfer_cache_init(data);
|
||||
OVERLAY_extra_cache_init(data);
|
||||
OVERLAY_facing_cache_init(data);
|
||||
OVERLAY_grease_pencil_cache_init(data);
|
||||
OVERLAY_gpencil_legacy_cache_init(data);
|
||||
OVERLAY_grid_cache_init(data);
|
||||
OVERLAY_image_cache_init(data);
|
||||
@@ -697,6 +698,7 @@ static void OVERLAY_draw_scene(void *vedata)
|
||||
OVERLAY_particle_draw(data);
|
||||
OVERLAY_metaball_draw(data);
|
||||
OVERLAY_gpencil_legacy_draw(data);
|
||||
OVERLAY_grease_pencil_draw(data);
|
||||
OVERLAY_extra_draw(data);
|
||||
if (pd->overlay.flag & V3D_OVERLAY_VIEWER_ATTRIBUTE) {
|
||||
OVERLAY_viewer_attribute_draw(data);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
|
||||
#include "DNA_grease_pencil_types.h"
|
||||
|
||||
#include "overlay_private.hh"
|
||||
|
||||
void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata)
|
||||
@@ -70,6 +72,93 @@ void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata)
|
||||
}
|
||||
}
|
||||
|
||||
void OVERLAY_grease_pencil_cache_init(OVERLAY_Data *vedata)
|
||||
{
|
||||
using namespace blender;
|
||||
OVERLAY_PassList *psl = vedata->psl;
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
const bke::AttrDomain selection_domain = ED_grease_pencil_selection_domain_get(ts);
|
||||
const View3D *v3d = draw_ctx->v3d;
|
||||
|
||||
GPUShader *sh;
|
||||
DRWShadingGroup *grp;
|
||||
|
||||
/* Default: Display nothing. */
|
||||
psl->grease_pencil_canvas_ps = nullptr;
|
||||
|
||||
Object *ob = draw_ctx->obact;
|
||||
const bool show_overlays = (v3d->flag2 & V3D_HIDE_OVERLAYS) == 0;
|
||||
const bool show_grid = (v3d->gp_flag & V3D_GP_SHOW_GRID) != 0 &&
|
||||
((ts->gpencil_v3d_align &
|
||||
(GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)) == 0);
|
||||
const bool grid_xray = (v3d->gp_flag & V3D_GP_SHOW_GRID_XRAY);
|
||||
|
||||
if (show_grid && show_overlays) {
|
||||
const float3 base_color = float3(0.5f);
|
||||
const float4 col_grid = float4(base_color, v3d->overlay.gpencil_grid_opacity);
|
||||
|
||||
float4x4 mat = ob->object_to_world();
|
||||
|
||||
const GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
|
||||
const blender::bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer();
|
||||
|
||||
if (ts->gp_sculpt.lock_axis != GP_LOCKAXIS_CURSOR) {
|
||||
mat = layer.to_world_space(*ob);
|
||||
}
|
||||
const View3DCursor *cursor = &scene->cursor;
|
||||
|
||||
/* Set the grid in the selected axis */
|
||||
switch (ts->gp_sculpt.lock_axis) {
|
||||
case GP_LOCKAXIS_X:
|
||||
std::swap(mat[0], mat[2]);
|
||||
break;
|
||||
case GP_LOCKAXIS_Y:
|
||||
std::swap(mat[1], mat[2]);
|
||||
break;
|
||||
case GP_LOCKAXIS_Z:
|
||||
/* Default. */
|
||||
break;
|
||||
case GP_LOCKAXIS_CURSOR: {
|
||||
mat = float4x4(cursor->matrix<float3x3>());
|
||||
break;
|
||||
}
|
||||
case GP_LOCKAXIS_VIEW:
|
||||
/* view aligned */
|
||||
DRW_view_viewmat_get(nullptr, mat.ptr(), true);
|
||||
break;
|
||||
}
|
||||
|
||||
mat *= 2.0f;
|
||||
|
||||
if (ts->gpencil_v3d_align & GP_PROJECT_CURSOR) {
|
||||
mat.location() = cursor->location;
|
||||
}
|
||||
else {
|
||||
mat.location() = layer.to_world_space(*ob).location();
|
||||
}
|
||||
|
||||
const int gridlines = 4;
|
||||
const int line_count = gridlines * 4 + 2;
|
||||
|
||||
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA;
|
||||
state |= (grid_xray) ? DRW_STATE_DEPTH_ALWAYS : DRW_STATE_DEPTH_LESS_EQUAL;
|
||||
|
||||
DRW_PASS_CREATE(psl->grease_pencil_canvas_ps, state);
|
||||
|
||||
sh = OVERLAY_shader_gpencil_canvas();
|
||||
grp = DRW_shgroup_create(sh, psl->grease_pencil_canvas_ps);
|
||||
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
|
||||
DRW_shgroup_uniform_vec4_copy(grp, "color", col_grid);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "xAxis", mat[0]);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "yAxis", mat[1]);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "origin", mat[3]);
|
||||
DRW_shgroup_uniform_int_copy(grp, "halfLineCount", line_count / 2);
|
||||
DRW_shgroup_call_procedural_lines(grp, nullptr, line_count);
|
||||
}
|
||||
}
|
||||
|
||||
void OVERLAY_edit_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob)
|
||||
{
|
||||
using namespace blender::draw;
|
||||
@@ -140,6 +229,15 @@ void OVERLAY_weight_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *o
|
||||
}
|
||||
}
|
||||
|
||||
void OVERLAY_grease_pencil_draw(OVERLAY_Data *vedata)
|
||||
{
|
||||
OVERLAY_PassList *psl = vedata->psl;
|
||||
|
||||
if (psl->grease_pencil_canvas_ps) {
|
||||
DRW_draw_pass(psl->grease_pencil_canvas_ps);
|
||||
}
|
||||
}
|
||||
|
||||
void OVERLAY_edit_grease_pencil_draw(OVERLAY_Data *vedata)
|
||||
{
|
||||
OVERLAY_PassList *psl = vedata->psl;
|
||||
|
||||
@@ -102,6 +102,7 @@ struct OVERLAY_PassList {
|
||||
DRWPass *extra_centers_ps;
|
||||
DRWPass *extra_grid_ps;
|
||||
DRWPass *gpencil_canvas_ps;
|
||||
DRWPass *grease_pencil_canvas_ps;
|
||||
DRWPass *facing_ps[2];
|
||||
DRWPass *fade_ps[2];
|
||||
DRWPass *mode_transfer_ps[2];
|
||||
@@ -562,10 +563,12 @@ void OVERLAY_gpencil_legacy_cache_populate(OVERLAY_Data *vedata, Object *ob);
|
||||
void OVERLAY_gpencil_legacy_draw(OVERLAY_Data *vedata);
|
||||
void OVERLAY_edit_gpencil_legacy_draw(OVERLAY_Data *vedata);
|
||||
|
||||
void OVERLAY_grease_pencil_cache_init(OVERLAY_Data *vedata);
|
||||
void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata);
|
||||
void OVERLAY_edit_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob);
|
||||
void OVERLAY_sculpt_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob);
|
||||
void OVERLAY_weight_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob);
|
||||
void OVERLAY_grease_pencil_draw(OVERLAY_Data *vedata);
|
||||
void OVERLAY_edit_grease_pencil_draw(OVERLAY_Data *vedata);
|
||||
|
||||
void OVERLAY_edit_lattice_cache_init(OVERLAY_Data *vedata);
|
||||
|
||||
Reference in New Issue
Block a user