[Bf-blender-cvs] [e2adbc9bca7] greasepencil-object: WIP: New paper function

Antonio Vazquez noreply at git.blender.org
Thu Nov 23 19:55:08 CET 2017


Commit: e2adbc9bca7fc95cf8f9f9c86284725880da8c8a
Author: Antonio Vazquez
Date:   Thu Nov 23 19:54:56 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe2adbc9bca7fc95cf8f9f9c86284725880da8c8a

WIP: New paper function

This function allows to cover full viewport with a predefined color. This allows to hide the geometry in complex scenes and make the drawing area cleaner.

This function was requested by artist after working in Hero open movie using complex scenes with a lot of geometry "behind" of the grease pencil drawings.

===================================================================

M	release/scripts/startup/bl_ui/properties_scene.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
A	source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index c83fc9c4a10..f76da8062fd 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -115,6 +115,21 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel):
         split.row()
         split.prop(unit, "use_separate")
 
+class SCENE_PT_gp_paper(SceneButtonsPanel, Panel):
+    bl_label = "Grease Pencil Paper"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        ts = context.tool_settings
+        row = layout.row(align=True)
+        row.prop(ts, "use_gpencil_paper", text="Use Paper")
+
+        row = layout.row(align=True)
+        row.prop(ts, "gp_paper_color", text="Color")
+        row = layout.row(align=True)
+        row.prop(ts, "gp_paper_opacity", text="Opacity")
 
 class SceneKeyingSetsPanel:
 
@@ -501,6 +516,7 @@ classes = (
     SCENE_PT_rigid_body_field_weights,
     SCENE_PT_simplify,
     SCENE_PT_gp_simplify,
+    SCENE_PT_gp_paper,
     SCENE_PT_custom_props,
 )
 
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 1760b41fab9..514bbac3623 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -157,6 +157,7 @@ class VIEW3D_HT_header(Header):
 
             view = context.space_data
             row = layout.row(align=True)
+            row.prop(context.tool_settings, "use_gpencil_paper", text="", icon='GHOST')
             row.prop(view, "show_only_render", text="", icon='IMAGE_COL')
             row.prop(view, "lock_camera", text="", icon='CAMERA_DATA')
 
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 28cba42a877..6b442b6b306 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -244,6 +244,7 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_wave_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_pixel_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_swirl_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_painting_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_paper_frag.glsl SRC)
 
 list(APPEND INC
 )
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 0e76b00e69e..52a4c976119 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -55,6 +55,7 @@ extern char datatoc_gpencil_wave_frag_glsl[];
 extern char datatoc_gpencil_pixel_frag_glsl[];
 extern char datatoc_gpencil_swirl_frag_glsl[];
 extern char datatoc_gpencil_painting_frag_glsl[];
+extern char datatoc_gpencil_paper_frag_glsl[];
 
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
@@ -171,6 +172,7 @@ static void GPENCIL_engine_free(void)
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_swirl_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_painting_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_front_depth_sh);
+	DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh);
 
 	DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
 }
@@ -245,6 +247,9 @@ static void GPENCIL_cache_init(void *vedata)
 	if (!e_data.gpencil_front_depth_sh) {
 		e_data.gpencil_front_depth_sh = DRW_shader_create_fullscreen(datatoc_gpencil_front_depth_mix_frag_glsl, NULL);
 	}
+	if (!e_data.gpencil_paper_sh) {
+		e_data.gpencil_paper_sh = DRW_shader_create_fullscreen(datatoc_gpencil_paper_frag_glsl, NULL);
+	}
 
 	{
 		/* Stroke pass */
@@ -377,6 +382,13 @@ static void GPENCIL_cache_init(void *vedata)
 		stl->g_data->tot_sh++;
 		DRW_shgroup_call_add(mix_front_shgrp, frontquad, NULL);
 		DRW_shgroup_uniform_buffer(mix_front_shgrp, "strokeColor", &e_data.temp_fbcolor_color_tx);
+
+		/* pass for drawing paper */
+		struct Gwn_Batch *paperquad = DRW_cache_fullscreen_quad_get();
+		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, paperquad, NULL);
+		DRW_shgroup_uniform_vec4(paper_shgrp, "color", ts->gpencil_paper_color, 1);
 	}
 }
 
@@ -596,6 +608,7 @@ static void GPENCIL_draw_scene(void *vedata)
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
 	DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
 	int init_grp, end_grp;
 	tGPencilObjectCache *cache;
 	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
@@ -603,8 +616,16 @@ static void GPENCIL_draw_scene(void *vedata)
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	Scene *scene = draw_ctx->scene;
 	ToolSettings *ts = scene->toolsettings;
+	Object *obact = draw_ctx->obact;
 	bool playing = (bool)stl->storage->playing;
 
+	/* paper pass to display a confortable area to draw over complex scenes with geometry */
+	if ((obact) && (obact->type == OB_GPENCIL)) {
+		if ((ts->gpencil_flags & GP_TOOL_FLAG_ENABLE_PAPER) && (stl->g_data->gp_cache_used > 0)) {
+			DRW_draw_pass(psl->paper_pass);
+		}
+	}
+
 	/* if we have a painting session, we use fast viewport drawing method */
 	if (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING) {
 		DRW_framebuffer_bind(dfbl->default_fb);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ea5acc6b00a..2320506ab2f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -180,6 +180,7 @@ typedef struct GPENCIL_PassList {
 	struct DRWPass *vfx_pixel_pass;
 	struct DRWPass *vfx_swirl_pass;
 	struct DRWPass *painting_pass;
+	struct DRWPass *paper_pass;
 } GPENCIL_PassList;
 
 typedef struct GPENCIL_FramebufferList {
@@ -248,6 +249,7 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_vfx_swirl_sh;
 	struct GPUShader *gpencil_painting_sh;
 	struct GPUShader *gpencil_front_depth_sh;
+	struct GPUShader *gpencil_paper_sh;
 	/* temp depth texture */
 	struct GPUTexture *temp_fbcolor_depth_tx;
 	struct GPUTexture *temp_fbcolor_color_tx;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl
new file mode 100644
index 00000000000..ae5cd00b810
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl
@@ -0,0 +1,8 @@
+uniform vec4 color;
+
+out vec4 FragColor;
+
+void main()
+{
+	FragColor = color;
+}
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index fbc7e2ca895..777ee5b144c 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1474,6 +1474,7 @@ typedef struct ToolSettings {
 
 	short gpencil_simplify; /* simplify flags for grease pencil */
 	char pad6[6];
+	float gpencil_paper_color[4];
 
 	/* Grease Pencil Sculpt */
 	struct GP_BrushEdit_Settings gp_sculpt;
@@ -2193,6 +2194,8 @@ typedef enum eGPencil_Flags {
 	GP_TOOL_FLAG_RETAIN_LAST            = (1 << 1),
 	/* Add the strokes below all strokes in the layer */
 	GP_TOOL_FLAG_PAINT_ONBACK = (1 << 2),
+	/* Activate paper to cover all viewport (this is done to facilitate drawing over geometry) */
+	GP_TOOL_FLAG_ENABLE_PAPER = (1 << 3),
 } eGPencil_Flags;
 
 /* toolsettings->gpencil_simplify */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 1e42592257f..0d7d5048c29 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2661,6 +2661,27 @@ static void rna_def_tool_settings(BlenderRNA  *brna)
 		"When draw new strokes, the new stroke is drawn below of all strokes in the layer");
 	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
 
+	prop = RNA_def_property(srna, "use_gpencil_paper", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "gpencil_flags", GP_TOOL_FLAG_ENABLE_PAPER);
+	RNA_def_property_ui_text(prop, "Use Paper",
+		"Cover all viewport with a full color layer to improve visibility while drawing over complex scenes");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+	
+	/* Paper Color */
+	prop = RNA_def_property(srna, "gp_paper_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_float_sdna(prop, NULL, "gpencil_paper_color");
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Paper Color", "Color for paper");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
+	/* Paper opacity factor */
+	prop = RNA_def_property(srna, "gp_paper_opacity", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "gpencil_paper_color[3]");
+	RNA_def_property_range(prop, 0.0, 1.0f);
+	RNA_def_property_ui_text(prop, "Opacity", "Paper opacity");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
 	prop = RNA_def_property(srna, "gpencil_sculpt", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "gp_sculpt");
 	RNA_def_property_struct_type(prop, "GPencilSculptSettings");



More information about the Bf-blender-cvs mailing list