[Bf-blender-cvs] [48eed058b17] master: 3D View: draw clipping region

Campbell Barton noreply at git.blender.org
Wed Jan 23 13:37:01 CET 2019


Commit: 48eed058b170e3def90fbc420933638d3986ca2c
Author: Campbell Barton
Date:   Wed Jan 23 23:30:30 2019 +1100
Branches: master
https://developer.blender.org/rB48eed058b170e3def90fbc420933638d3986ca2c

3D View: draw clipping region

Only for workbench solid/wire modes.

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

M	release/datafiles/userdef/userdef_default_theme.c
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/draw/intern/draw_view.c
M	source/blender/draw/intern/draw_view.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl

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

diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c
index aa275d6a99e..39ba48eef0a 100644
--- a/release/datafiles/userdef/userdef_default_theme.c
+++ b/release/datafiles/userdef/userdef_default_theme.c
@@ -355,7 +355,7 @@ const bTheme U_theme_default = {
 		.outline_width = 1,
 		.facedot_size = 3,
 		.editmesh_active = RGBA(0xffffff80),
-		.clipping_border_3d = RGBA(0x313131ff),
+		.clipping_border_3d = RGBA(0x0f0f0fff),
 		.bundle_solid = RGBA(0xc8c8c8ff),
 		.camera_path = RGBA(0x000000ff),
 		.gp_vertex_size = 3,
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 0d17c4a5c5d..931dfd63088 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -28,6 +28,8 @@
 
 #include "UI_resources.h"
 
+#include "GPU_batch.h"
+
 
 void workbench_effect_info_init(WORKBENCH_EffectInfo *effect_info)
 {
@@ -118,6 +120,7 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
 		if (rv3d->rflag & RV3D_CLIPPING) {
 			wpd->world_clip_planes = rv3d->clip;
 			DRW_state_clip_planes_set_from_rv3d(rv3d);
+			UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, wpd->world_clip_planes_color);
 		}
 		else {
 			wpd->world_clip_planes = NULL;
@@ -212,4 +215,5 @@ void workbench_private_data_free(WORKBENCH_PrivateData *wpd)
 {
 	BLI_ghash_free(wpd->material_hash, NULL, MEM_freeN);
 	DRW_UBO_FREE_SAFE(wpd->world_ubo);
+	GPU_BATCH_DISCARD_SAFE(wpd->world_clip_planes_batch);
 }
diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c
index af6b83679ea..44bc35bfc41 100644
--- a/source/blender/draw/engines/workbench/workbench_deferred.c
+++ b/source/blender/draw/engines/workbench/workbench_deferred.c
@@ -640,6 +640,17 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
 			DRW_shgroup_uniform_texture_ref(grp, "objectId", &e_data.object_id_tx);
 		}
 		DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+
+		if (draw_ctx->rv3d &&
+		    (draw_ctx->rv3d->rflag & RV3D_CLIPPING) &&
+		    draw_ctx->rv3d->clipbb)
+		{
+			GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND);
+			grp = DRW_shgroup_create(shader, psl->background_pass);
+			wpd->world_clip_planes_batch = DRW_draw_background_clipping_batch_from_rv3d(draw_ctx->rv3d);
+			DRW_shgroup_call_add(grp, wpd->world_clip_planes_batch, NULL);
+			DRW_shgroup_uniform_vec4(grp, "color", &wpd->world_clip_planes_color[0], 1);
+		}
 	}
 
 	/* Deferred Mix Pass */
diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c
index 3ced267ce89..c8f3a9a7bff 100644
--- a/source/blender/draw/engines/workbench/workbench_forward.c
+++ b/source/blender/draw/engines/workbench/workbench_forward.c
@@ -364,6 +364,16 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata)
 		DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
 	}
 
+	if (draw_ctx->rv3d && (draw_ctx->rv3d->rflag & RV3D_CLIPPING) && draw_ctx->rv3d->clipbb) {
+		psl->background_pass = DRW_pass_create(
+		        "Background", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
+		GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND);
+		grp = DRW_shgroup_create(shader, psl->background_pass);
+		wpd->world_clip_planes_batch = DRW_draw_background_clipping_batch_from_rv3d(draw_ctx->rv3d);
+		DRW_shgroup_call_add(grp, wpd->world_clip_planes_batch, NULL);
+		DRW_shgroup_uniform_vec4(grp, "color", &wpd->world_clip_planes_color[0], 1);
+	}
+
 	{
 		workbench_aa_create_pass(vedata, &e_data.transparent_accum_tx);
 	}
@@ -642,6 +652,11 @@ void workbench_forward_draw_scene(WORKBENCH_Data *vedata)
 	DRW_draw_pass(psl->composite_pass);
 	DRW_draw_pass(psl->volume_pass);
 
+	/* Only when clipping is enabled. */
+	if (psl->background_pass) {
+		DRW_draw_pass(psl->background_pass);
+	}
+
 	/* Color correct and Anti aliasing */
 	workbench_aa_draw_pass(vedata, e_data.composite_buffer_tx);
 
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
index 0dc4078f888..bbcae7f81d4 100644
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -126,6 +126,7 @@ typedef struct WORKBENCH_PassList {
 	struct DRWPass *composite_pass;
 	struct DRWPass *composite_shadow_pass;
 	struct DRWPass *background_pass;
+	struct DRWPass *background_pass_clip;
 	struct DRWPass *ghost_resolve_pass;
 	struct DRWPass *effect_aa_pass;
 	struct DRWPass *volume_pass;
@@ -204,6 +205,8 @@ typedef struct WORKBENCH_PrivateData {
 	bool is_playback;
 
 	float (*world_clip_planes)[4];
+	struct GPUBatch *world_clip_planes_batch;
+	float world_clip_planes_color[4];
 
 	/* Volumes */
 	bool volumes_do;
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
index 2d5dbac5dd5..027eda05933 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -126,6 +126,41 @@ void DRW_draw_background(void)
 	}
 }
 
+GPUBatch *DRW_draw_background_clipping_batch_from_rv3d(const RegionView3D *rv3d)
+{
+	const BoundBox *bb = rv3d->clipbb;
+	const uint clipping_index[6][4] = {
+		{0, 1, 2, 3},
+		{0, 4, 5, 1},
+		{4, 7, 6, 5},
+		{7, 3, 2, 6},
+		{1, 5, 6, 2},
+		{7, 4, 0, 3}
+	};
+	GPUVertBuf *vbo;
+	GPUIndexBuf *el;
+	GPUIndexBufBuilder elb = {0};
+
+	/* Elements */
+	GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, ARRAY_SIZE(clipping_index) * 2, ARRAY_SIZE(bb->vec));
+	for (int i = 0; i < ARRAY_SIZE(clipping_index); i++) {
+		const uint *idx = clipping_index[i];
+		GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
+		GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[2], idx[3]);
+	}
+	el = GPU_indexbuf_build(&elb);
+
+	GPUVertFormat format = {0};
+	uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+
+	vbo = GPU_vertbuf_create_with_format(&format);
+	GPU_vertbuf_data_alloc(vbo, ARRAY_SIZE(bb->vec));
+	GPU_vertbuf_attr_fill(vbo, pos_id, bb->vec);
+
+	return GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, el, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
+}
+
+
 /* **************************** 3D Cursor ******************************** */
 
 static bool is_cursor_visible(const DRWContextState *draw_ctx, Scene *scene, ViewLayer *view_layer)
diff --git a/source/blender/draw/intern/draw_view.h b/source/blender/draw/intern/draw_view.h
index b6f37de080d..1fc79e00829 100644
--- a/source/blender/draw/intern/draw_view.h
+++ b/source/blender/draw/intern/draw_view.h
@@ -35,4 +35,6 @@ void DRW_draw_cursor(void);
 void DRW_draw_gizmo_3d(void);
 void DRW_draw_gizmo_2d(void);
 
+struct GPUBatch *DRW_draw_background_clipping_batch_from_rv3d(const struct RegionView3D *rv3d);
+
 #endif /* __DRAW_VIEW_H__ */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index f8130ee73fa..8a699d8c9fb 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -452,8 +452,6 @@ void ED_view3d_draw_setup_view(
         struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
         float viewmat[4][4], float winmat[4][4], const struct rcti *rect);
 
-void ED_view3d_draw_clipping(const struct RegionView3D *rv3d);
-
 enum {
 	V3D_OFSDRAW_NONE             = (0),
 
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 8d259986114..6c9d5f590c8 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1736,57 +1736,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
 /** \name Viewport Clipping
  * \{ */
 
-void ED_view3d_draw_clipping(const RegionView3D *rv3d)
-{
-	const BoundBox *bb = rv3d->clipbb;
-	if (bb == NULL) {
-		return;
-	}
-
-	const uint clipping_index[6][4] = {
-		{0, 1, 2, 3},
-		{0, 4, 5, 1},
-		{4, 7, 6, 5},
-		{7, 3, 2, 6},
-		{1, 5, 6, 2},
-		{7, 4, 0, 3}
-	};
-
-	GPUVertBuf *vbo;
-	GPUIndexBuf *el;
-	GPUIndexBufBuilder elb = {0};
-
-	/* Elements */
-	GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, ARRAY_SIZE(clipping_index) * 2, ARRAY_SIZE(bb->vec));
-	for (int i = 0; i < ARRAY_SIZE(clipping_index); i++) {
-		const uint *idx = clipping_index[i];
-		GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
-		GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[2], idx[3]);
-	}
-	el = GPU_indexbuf_build(&elb);
-
-	GPUVertFormat format = {0};
-	uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
-
-	vbo = GPU_vertbuf_create_with_format(&format);
-	GPU_vertbuf_data_alloc(vbo, ARRAY_SIZE(bb->vec));
-	GPU_vertbuf_attr_fill(vbo, pos_id, bb->vec);
-
-	GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, el, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
-	GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR);
-
-	float color[4];
-	UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, color);
-
-	GPU_batch_uniform_4fv(batch, "color", color);
-
-	/* Draw. */
-	glEnable(GL_BLEND);
-	GPU_batch_draw(batch);
-	GPU_batch_discard(batch);
-	glDisable(GL_BLEND);
-}
-
 static bool view3d_clipping_test(const float co[3], const float clip[6][4])
 {
 	if (plane_point_side_v3(clip[0], co) > 0.0f)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index d339d0a2f81..0004642ea5b 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -162,6 +162,8 @@ typedef enum eGPUBuiltinShader {
 	 * \param pos: in vec3
 	 */
 	GPU_SHADER_3D_UNIFORM_COLOR,
+	/* Sets Z-depth to 1.0 (draw onto background). */
+	GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND,
 	GPU_SHADER_3D_UNIFORM_COLOR_INSTANCE,
 	/**
 	 * Take a 3D position and color for each vertex without color interpolation.
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index c5a2c2ea6e5..5d5084c4eb9 100644
--- a/source/blender/gpu/intern/gpu_s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list