3D View: draw clipping region
Only for workbench solid/wire modes.
This commit is contained in:
parent
44e9fe024b
commit
48eed058b1
Notes:
blender-bot
2023-02-14 10:35:28 +01:00
Referenced by issue #60779, 3D Viewport clipping support
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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),
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -804,6 +804,9 @@ static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = {
|
|||
[GPU_SHADER_3D_UNIFORM_COLOR] =
|
||||
{ datatoc_gpu_shader_3D_vert_glsl,
|
||||
datatoc_gpu_shader_uniform_color_frag_glsl },
|
||||
[GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND] =
|
||||
{ datatoc_gpu_shader_3D_vert_glsl,
|
||||
datatoc_gpu_shader_uniform_color_frag_glsl },
|
||||
[GPU_SHADER_3D_FLAT_COLOR] =
|
||||
{ datatoc_gpu_shader_3D_flat_color_vert_glsl,
|
||||
datatoc_gpu_shader_flat_color_frag_glsl },
|
||||
|
@ -1030,7 +1033,8 @@ static const char *gpu_shader_get_builtin_shader_defines(
|
|||
|
||||
case GPU_SHADER_2D_UV_FACES_STRETCH_ANGLE:
|
||||
return "#define STRETCH_ANGLE\n";
|
||||
|
||||
case GPU_SHADER_3D_UNIFORM_COLOR_BACKGROUND:
|
||||
return "#define USE_BACKGROUND\n";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -18,4 +18,8 @@ void main()
|
|||
#else
|
||||
fragColor = color;
|
||||
#endif
|
||||
|
||||
#if defined(USE_BACKGROUND)
|
||||
gl_FragDepth = 1.0;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue