[Bf-blender-cvs] [e920e1335dc] greasepencil-object: Full refactor of Grease Pencil grid
Antonioya
noreply at git.blender.org
Sat Jul 28 12:02:39 CEST 2018
Commit: e920e1335dca54a836e0a408df4e0abc69a93c03
Author: Antonioya
Date: Sat Jul 28 12:02:29 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe920e1335dca54a836e0a408df4e0abc69a93c03
Full refactor of Grease Pencil grid
After testing the old grid locked to view, the artist found that old system was not usable and they requested a grid locked to grease pencil object.
Also fixed some problems with fade object
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/blenloader/intern/versioning_280.c
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_paper_frag.glsl
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesdna/DNA_view3d_types.h
M source/blender/makesrna/intern/rna_space.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index c33290e7bd6..67260e42ec3 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4735,7 +4735,8 @@ class VIEW3D_PT_overlay_gpencil_options(Panel):
layout.prop(overlay, "use_gpencil_grid", text="Show Plane Grid")
if overlay.use_gpencil_grid:
- layout.prop(overlay, "gpencil_grid_size", text="")
+ layout.prop(overlay, "gpencil_grid_scale")
+ layout.prop(overlay, "gpencil_grid_lines")
layout.prop(overlay, "use_gpencil_onion_skin", text="Onion Skin")
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index d6b54bd7013..5a323d3c969 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -989,9 +989,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
- v3d->gpencil_grid_size[0] = GP_DEFAULT_GRID_SIZE;
- v3d->gpencil_grid_size[1] = GP_DEFAULT_GRID_SIZE;
- ARRAY_SET_ITEMS(v3d->gpencil_paper_color, 1.0f, 1.0f, 1.0f, 0.7f);
+ v3d->gpencil_grid_scale = 1.0f; // Scale
+ v3d->gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of lines
+ v3d->gpencil_paper_opacity = 0.5f;
}
}
}
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 ba174ed9f50..cdb73c151a5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -599,3 +599,85 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
return GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
}
+
+static void set_grid_point(GPUVertBuf *vbo, int idx, uchar col_grid[3],
+ uint pos_id, uint color_id,
+ float x, float y, float z)
+{
+ GPU_vertbuf_attr_set(vbo, color_id, idx, col_grid);
+
+ float pos[3] = { x, y, z };
+ GPU_vertbuf_attr_set(vbo, pos_id, idx, pos);
+}
+
+/* Draw grid lines */
+GPUBatch *DRW_gpencil_get_grid(void)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ View3D *v3d = draw_ctx->v3d;
+
+ uchar col_grid[3];
+ UI_GetThemeColor3ubv(TH_GRID, col_grid);
+
+ /* verify we have soemthing to draw */
+ if (v3d->gpencil_grid_lines < 4) {
+ v3d->gpencil_grid_lines = GP_DEFAULT_GRID_LINES;
+ }
+
+ if (v3d->gpencil_grid_scale == 0.0f) {
+ v3d->gpencil_grid_scale = 1.0f;
+ }
+
+ const char *grid_unit = NULL;
+ const int gridlines = v3d->gpencil_grid_lines;
+ const float grid_scale = v3d->gpencil_grid_scale * ED_scene_grid_scale(scene, &grid_unit);
+ const float grid = gridlines * grid_scale;
+
+ const uint vertex_len = 2 * (gridlines * 4 + 2);
+
+ static GPUVertFormat format = { 0 };
+ static uint pos_id, color_id;
+ if (format.attr_len == 0) {
+ pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ color_id = GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ }
+
+ GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+ GPU_vertbuf_data_alloc(vbo, vertex_len);
+
+ int idx = 0;
+ for (int a = 1; a <= gridlines; a++) {
+ const float line = a * grid_scale;
+
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, 0.0f, -line);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, 0.0f, -line);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, 0.0f, +line);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, 0.0f, +line);
+ idx++;
+
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line, 0.0f, -grid);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, -line, 0.0f, +grid);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line, 0.0f, -grid);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, +line, 0.0f, +grid);
+ idx++;
+ }
+ /* center lines */
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, -grid, 0.0f, 0.0f);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, +grid, 0.0f, 0.0f);
+ idx++;
+
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, 0.0f, -grid);
+ idx++;
+ set_grid_point(vbo, idx, col_grid, pos_id, color_id, 0.0f, 0.0f, +grid);
+ idx++;
+
+ return GPU_batch_create_ex(GPU_PRIM_LINES, vbo, NULL, GPU_BATCH_OWNS_VBO);
+}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 3b13886b14a..ed1332d2712 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -428,31 +428,14 @@ void GPENCIL_cache_init(void *vedata)
psl->paper_pass = DRW_pass_create("GPencil Paper Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
DRWShadingGroup *paper_shgrp = DRW_shgroup_create(e_data.gpencil_paper_sh, psl->paper_pass);
DRW_shgroup_call_add(paper_shgrp, quad, NULL);
- DRW_shgroup_uniform_vec4(paper_shgrp, "color", v3d->gpencil_paper_color, 1);
-
- UI_GetThemeColor3fv(TH_GRID, stl->storage->gridcolor);
- DRW_shgroup_uniform_vec3(paper_shgrp, "gridcolor", &stl->storage->gridcolor[0], 1);
-
- stl->storage->gridsize[0] = (float)v3d->gpencil_grid_size[0];
- stl->storage->gridsize[1] = (float)v3d->gpencil_grid_size[1];
- DRW_shgroup_uniform_vec2(paper_shgrp, "size", &stl->storage->gridsize[0], 1);
-
- /* paper can be only grid */
- if (v3d->flag3 & V3D_GP_SHOW_PAPER) {
- stl->storage->usepaper = 1;
- }
- else {
- stl->storage->usepaper = 0;
- }
- DRW_shgroup_uniform_int(paper_shgrp, "usepaper", &stl->storage->usepaper, 1);
+ DRW_shgroup_uniform_vec3(paper_shgrp, "color", v3d->shading.background_color, 1);
+ DRW_shgroup_uniform_float(paper_shgrp, "opacity", &v3d->gpencil_paper_opacity, 1);
+ }
- if (v3d->flag3 & V3D_GP_SHOW_GRID) {
- stl->storage->uselines = 1;
- }
- else {
- stl->storage->uselines = 0;
- }
- DRW_shgroup_uniform_int(paper_shgrp, "uselines", &stl->storage->uselines, 1);
+ /* grid pass */
+ if (v3d) {
+ psl->grid_pass = DRW_pass_create("GPencil Grid Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
+ stl->g_data->shgrps_grid = DRW_shgroup_create(e_data.gpencil_line_sh, psl->grid_pass);
}
/* create effects passes */
@@ -471,6 +454,8 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
const DRWContextState *draw_ctx = DRW_context_state_get();
Scene *scene = draw_ctx->scene;
ToolSettings *ts = scene->toolsettings;
+ View3D *v3d = draw_ctx->v3d;
+ const bool playing = (bool)stl->storage->playing;
/* object datablock (this is not draw now) */
if (ob->type == OB_GPENCIL && ob->data) {
@@ -495,6 +480,18 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
}
/* draw current painting strokes */
DRW_gpencil_populate_buffer_strokes(&e_data, vedata, ts, ob);
+
+ /* grid */
+ if ((v3d) && (!playing) &&
+ ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+ (v3d->flag3 & V3D_GP_SHOW_GRID) &&
+ (ob->type == OB_GPENCIL) && (ob == draw_ctx->obact))
+ {
+ stl->g_data->batch_grid = DRW_gpencil_get_grid();
+ DRW_shgroup_call_add(stl->g_data->shgrps_grid,
+ stl->g_data->batch_grid,
+ ob->obmat);
+ }
}
}
@@ -616,7 +613,7 @@ void GPENCIL_draw_scene(void *ved)
/* paper pass to display a confortable area to draw over complex scenes with geometry */
if ((!is_render) && (obact) && (obact->type == OB_GPENCIL)) {
if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
- ((v3d->flag3 & V3D_GP_SHOW_PAPER) || (v3d->flag3 & V3D_GP_SHOW_GRID)) &&
+ (v3d->flag3 & V3D_GP_SHOW_PAPER) &&
(stl->g_data->gp_cache_used > 0))
{
DRW_draw_pass(psl->paper_pass);
@@ -637,6 +634,15 @@ void GPENCIL_draw_scene(void *ved)
/* free memory */
gpencil_free_obj_list(stl);
+ /* grid pass */
+ if ((!is_render) && (obact) && (obact->type == OB_GPENCIL)) {
+ if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+ (v3d->flag3 & V3D_GP_SHOW_GRID))
+ {
+ DRW_draw_pass(psl->grid_pass);
+ }
+ }
+
return;
}
@@ -715,6 +721,14 @@ void GPENCIL_draw_scene(void *ved)
DRW_draw_pass(psl->edit_pass);
}
}
+ /* grid pass */
+ if ((!is_render) && (obact) && (obact->type == OB_GPENCIL)) {
+ if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+ (v3d->flag3 & V3D_GP_SHOW_GRID))
+ {
+ DRW_draw_pass(psl->grid_pass);
+ }
+ }
}
/* free memory */
gpencil_free_obj_list(stl);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0ea831b9384..59630b5f304 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -107,10 +107,6 @@ typedef struct GPENCIL_Storage {
int playing;
bool is_render;
bool is_mat_preview;
- int usepaper;
- int uselines;
- float gridsize[2];
- float gridcolor[3];
const float *pixsize;
float render_pixsize;
int tonemapping;
@@ -144,6 +140,7 @@ typedef struct GPENCIL_PassList {
struct DRWPass *mix_pass_noblend;
struct DRWPass *background_pass;
struct DRWPass *paper_pass;
+ struct DRWPass *grid_pass;
/* effects */
struct DRWPass *fx_shader_pass;
@@ -180,6 +177,7 @@ typedef struct GPENCIL_Data {
/* render textures */
struct GPUTexture *render_depth_tx;
struct GPUTexture *render_color_tx;
+
} GPENCIL_Data;
/* *********** STATIC *********** */
@@ -188,11 +186,15 @@ typedef struct g_data {
struct DRWShadingGroup *shgrps_edit_line;
struct DRWShadingGroup *shgrps_drawing_stroke;
struct DRWShadingGroup *shgrps_drawing_fill;
+ struct DRWShadingGroup *shgrps_grid;
/* for buffer only one batch is nedeed because the drawing is only of one stroke */
GPUBatch *batch_buffer_stroke;
GPUBatch *batch_buffer_fill;
+ /* grid geometry *
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list