[Bf-blender-cvs] [cbad88435ce] greasepencil-object: WIP: Basic stroke volumetric support

Antonio Vazquez noreply at git.blender.org
Sun Jul 2 18:10:21 CEST 2017


Commit: cbad88435cec39b5180c903055b2429d705e6571
Author: Antonio Vazquez
Date:   Sun Jul 2 18:10:08 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBcbad88435cec39b5180c903055b2429d705e6571

WIP: Basic stroke volumetric support

This need more work to expand volumetric features. Commit these changes to put in place all the pieces of the system.

We keep as is today while we decide the final design.

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

M	source/blender/draw/CMakeLists.txt
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/gpencil_geom.c
A	source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 0dac8dfba6d..f5658bc1b83 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -202,6 +202,8 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_vert.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_geom.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_stroke_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_point_vert.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_point_frag.glsl SRC)
 
 list(APPEND INC
 )
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 8797c71f3d6..4b11fcf14ed 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -357,6 +357,43 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, GPENC
 	return grp;
 }
 
+/* create shading group for volumetrics */
+static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
+	bGPdata *gpd, int id)
+{
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+
+	/* e_data.gpencil_stroke_sh */
+	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
+
+	DRW_shgroup_uniform_float(grp, "pixsize", DRW_viewport_pixelsize_get(), 1);
+	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
+
+	/* object scale and depth */
+	if ((ob) && (id > -1)) {
+		stl->shgroups[id].obj_scale = (ob->size[0] + ob->size[1] + ob->size[2]) / 3.0f;
+		DRW_shgroup_uniform_float(grp, "objscale", &stl->shgroups[id].obj_scale, 1);
+		stl->shgroups[id].keep_size = (int)((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS));
+		DRW_shgroup_uniform_int(grp, "keep_size", &stl->shgroups[id].keep_size, 1);
+	}
+	else {
+		stl->storage->obj_scale = 1.0f;
+		stl->storage->keep_size = 0;
+		DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->obj_scale, 1);
+		DRW_shgroup_uniform_int(grp, "keep_size", &stl->storage->keep_size, 1);
+	}
+
+	if (gpd) {
+		DRW_shgroup_uniform_int(grp, "xraymode", (const int *)&gpd->xray_mode, 1);
+	}
+	else {
+		/* for drawing always on front */
+		DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
+	}
+
+	return grp;
+}
+
 /* create shading group for edit points using volumetric */
 DRWShadingGroup *DRW_gpencil_shgroup_edit_volumetric_create(DRWPass *pass, GPUShader *shader)
 {
@@ -432,20 +469,16 @@ static void gpencil_add_stroke_shgroup(GPENCIL_StorageList *stl, GpencilBatchCac
 	}
 	short sthickness = gps->thickness + gpl->thickness;
 	if (sthickness > 0) {
-		if (gps->totpoints > 1) {
-			if (cache->is_dirty) {
-				gpencil_batch_cache_check_free_slots(gpd);
+		if (cache->is_dirty) {
+			gpencil_batch_cache_check_free_slots(gpd);
+			if ((gps->totpoints > 1) && (gps->palcolor->stroke_style != STROKE_STYLE_VOLUMETRIC)) {
 				cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_stroke_geom(gpf, gps, sthickness, ink);
 			}
-			DRW_shgroup_call_add(strokegrp, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
-		}
-		else if (gps->totpoints == 1) {
-			if (cache->is_dirty) {
-				gpencil_batch_cache_check_free_slots(gpd);
-				cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_point_geom(gps->points, sthickness, ink);
+			else {
+				cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_point_geom(gps, sthickness, ink);
 			}
-			DRW_shgroup_call_add(stl->g_data->shgrps_point_volumetric, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
 		}
+		DRW_shgroup_call_add(strokegrp, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
 	}
 }
 
@@ -500,7 +533,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 		}
 #if 0   /* if we use the reallocate the shading group is doing weird thing, so disable while find a solution 
 		   and allocate the max size on cache_init */
-		/* realloc memory */
+		   /* realloc memory */
 		GPENCIL_shgroup *p = NULL;
 		int size = stl->storage->shgroup_id + 1;
 		p = MEM_recallocN(stl->shgroups, sizeof(struct GPENCIL_shgroup) * size);
@@ -508,18 +541,28 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 			stl->shgroups = p;
 		}
 #endif
-		if (gps->totpoints > 1) {
-			int id = stl->storage->shgroup_id;
-			stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id);
+		int id = stl->storage->shgroup_id;
+		if ((gps->totpoints > 1) && (gps->palcolor->stroke_style != STROKE_STYLE_VOLUMETRIC)) {
+			if (gps->totpoints > 2) {
+				stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id);
+			}
+			else { 
+				stl->shgroups[id].shgrps_fill = NULL;
+			}
 			stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd, gps->palcolor, id);
-			++stl->storage->shgroup_id;
-
-			fillgrp = stl->shgroups[id].shgrps_fill;
-			strokegrp = stl->shgroups[id].shgrps_stroke;
 		}
-		/* fill */
-		gpencil_add_fill_shgroup(cache, fillgrp, gpd, gpl, gpf, gps, tintcolor, onion, custonion);
+		else {
+			stl->shgroups[id].shgrps_fill = NULL;
+			stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_point_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_point_sh, ob, gpd, id);
+		}
+		++stl->storage->shgroup_id;
 
+		fillgrp = stl->shgroups[id].shgrps_fill;
+		strokegrp = stl->shgroups[id].shgrps_stroke;
+		/* fill */
+		if (fillgrp) {
+			gpencil_add_fill_shgroup(cache, fillgrp, gpd, gpl, gpf, gps, tintcolor, onion, custonion);
+		}
 		/* stroke */
 		gpencil_add_stroke_shgroup(stl, cache, strokegrp, gpd, gpl, gpf, gps, opacity, tintcolor, onion, custonion);
 
@@ -549,11 +592,8 @@ void DRW_gpencil_populate_buffer_strokes(void *vedata, ToolSettings *ts, bGPdata
 			* i.e. tGPspoints NOT bGPDspoints
 			*/
 			short lthick = brush->thickness;
-			if (gpd->sbuffer_size == 1) {
-				stl->g_data->batch_buffer_stroke = DRW_gpencil_get_buffer_point_geom(gpd, lthick);
-				DRW_shgroup_call_add(stl->g_data->shgrps_point_volumetric, stl->g_data->batch_buffer_stroke, stl->storage->unit_matrix);
-			}
-			else {
+			/* if only one point, don't need to draw buffer because the user has no time to see it */
+			if (gpd->sbuffer_size > 1) {
 				/* use unit matrix because the buffer is in screen space and does not need conversion */
 				stl->g_data->batch_buffer_stroke = DRW_gpencil_get_buffer_stroke_geom(gpd, stl->storage->unit_matrix, lthick);
 				DRW_shgroup_call_add(stl->g_data->shgrps_drawing_stroke, stl->g_data->batch_buffer_stroke, stl->storage->unit_matrix);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 8a9a7ab89b5..6c4cc0b0e14 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -42,6 +42,8 @@ extern char datatoc_gpencil_stroke_vert_glsl[];
 extern char datatoc_gpencil_stroke_geom_glsl[];
 extern char datatoc_gpencil_stroke_frag_glsl[];
 extern char datatoc_gpencil_zdepth_mix_frag_glsl[];
+extern char datatoc_gpencil_point_vert_glsl[];
+extern char datatoc_gpencil_point_frag_glsl[];
 
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
@@ -79,6 +81,12 @@ static void GPENCIL_engine_init(void *vedata)
 			datatoc_gpencil_stroke_frag_glsl,
 			NULL);
 	}
+	if (!e_data.gpencil_point_sh) {
+		e_data.gpencil_point_sh = DRW_shader_create(datatoc_gpencil_point_vert_glsl,
+			NULL,
+			datatoc_gpencil_point_frag_glsl,
+			NULL);
+	}
 
 	/* used for edit points or strokes with one point only */
 	if (!e_data.gpencil_volumetric_sh) {
@@ -98,7 +106,7 @@ static void GPENCIL_engine_init(void *vedata)
 
 	/* blank texture used if no texture defined for fill shader */
 	if (!e_data.gpencil_blank_texture) {
-		e_data.gpencil_blank_texture = DRW_gpencil_create_blank_texture(64, 64);
+		e_data.gpencil_blank_texture = DRW_gpencil_create_blank_texture(16, 16);
 	}
 
 }
@@ -108,6 +116,7 @@ static void GPENCIL_engine_free(void)
 	/* only free custom shaders, builtin shaders are freed in blender close */
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh);
+	DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh);
 	DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
 }
@@ -150,7 +159,6 @@ static void GPENCIL_cache_init(void *vedata)
 		/* Stroke pass */
 		psl->stroke_pass = DRW_pass_create("Gpencil Stroke Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND);
 		stl->storage->shgroup_id = 0;
-		stl->g_data->shgrps_point_volumetric = DRW_gpencil_shgroup_point_volumetric_create(psl->stroke_pass, e_data.gpencil_volumetric_sh);
 
 		/* edit pass */
 		psl->edit_pass = DRW_pass_create("Gpencil Edit Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
@@ -160,9 +168,8 @@ static void GPENCIL_cache_init(void *vedata)
 		const DRWContextState *draw_ctx = DRW_context_state_get();
 		Palette *palette = BKE_palette_get_active_from_context(draw_ctx->evil_C);
 		PaletteColor *palcolor = BKE_palette_color_get_active(palette);
-		if (palcolor) {
-			stl->storage->stroke_style = palcolor->stroke_style;
-		}
+		stl->storage->stroke_style = STROKE_STYLE_SOLID;
+
 
 		psl->drawing_pass = DRW_pass_create("Gpencil Drawing Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
 		stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, palcolor, -1);
@@ -286,21 +293,20 @@ static void GPENCIL_draw_scene(void *vedata)
 			Object *ob = stl->g_data->gp_object_cache[i].ob;
 			init_grp = stl->g_data->gp_object_cache[i].init_grp;
 			end_grp = stl->g_data->gp_object_cache[i].end_grp;
-			if ((end_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list