DRW: Support edit-metaball clipping

This commit is contained in:
Campbell Barton 2019-02-07 00:07:30 +11:00
parent 3e6ebdd2a6
commit e8292466bc
Notes: blender-bot 2023-02-14 03:59:42 +01:00
Referenced by issue #60779, 3D Viewport clipping support
5 changed files with 35 additions and 10 deletions

View File

@ -696,13 +696,18 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp
return grp;
}
DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass, eGPUShaderConfig shader_cfg)
{
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
COMMON_Shaders *sh_data = &g_shaders[shader_cfg];
if (sh_data->mball_handles == NULL) {
sh_data->mball_handles = DRW_shader_create(
datatoc_object_mball_handles_vert_glsl, NULL,
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
bool is_clip = (shader_cfg == GPU_SHADER_CFG_CLIPPED);
const char *world_clip_lib_or_empty = is_clip ? datatoc_gpu_shader_cfg_world_clip_lib_glsl : "";
const char *world_clip_def_or_empty = is_clip ? "#define USE_WORLD_CLIP_PLANES\n" : "";
sh_data->mball_handles = GPU_shader_create_from_arrays({
.vert = (const char *[]){world_clip_lib_or_empty, datatoc_object_mball_handles_vert_glsl, NULL},
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
.defs = (const char *[]){world_clip_def_or_empty, NULL},
});
}
DRW_shgroup_instance_format(g_formats.instance_mball_handles, {
@ -716,7 +721,9 @@ DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
DRW_cache_screenspace_circle_get(),
g_formats.instance_mball_handles);
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
if (shader_cfg == GPU_SHADER_CFG_CLIPPED) {
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
}
return grp;
}

View File

@ -140,7 +140,7 @@ struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GP
struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig shader_cfg);
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, eGPUShaderConfig shader_cfg);
struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);

View File

@ -90,12 +90,23 @@ typedef struct EDIT_METABALL_PrivateData {
/* *********** FUNCTIONS *********** */
static void EDIT_METABALL_engine_init(void *UNUSED(vedata))
{
const DRWContextState *draw_ctx = DRW_context_state_get();
const bool is_clip = (draw_ctx->rv3d->rflag & RV3D_CLIPPING) != 0;
if (is_clip) {
DRW_state_clip_planes_set_from_rv3d(draw_ctx->rv3d);
}
}
/* Here init all passes and shading groups
* Assume that all Passes are NULL */
static void EDIT_METABALL_cache_init(void *vedata)
{
EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
const DRWContextState *draw_ctx = DRW_context_state_get();
if (!stl->g_data) {
/* Alloc transient pointers */
@ -110,7 +121,7 @@ static void EDIT_METABALL_cache_init(void *vedata)
psl->pass = DRW_pass_create("My Pass", state);
/* Create a shadingGroup using a function in draw_common.c or custom one */
stl->g_data->group = shgroup_instance_mball_handles(psl->pass);
stl->g_data->group = shgroup_instance_mball_handles(psl->pass, draw_ctx->shader_cfg);
}
}
@ -192,6 +203,8 @@ static void EDIT_METABALL_draw_scene(void *vedata)
/* If you changed framebuffer, double check you rebind
* the default one with its textures attached before finishing */
DRW_state_clip_planes_reset();
}
/* Cleanup when destroying the engine.
@ -208,7 +221,7 @@ DrawEngineType draw_engine_edit_metaball_type = {
NULL, NULL,
N_("EditMetaballMode"),
&EDIT_METABALL_data_size,
NULL,
&EDIT_METABALL_engine_init,
&EDIT_METABALL_engine_free,
&EDIT_METABALL_cache_init,
&EDIT_METABALL_cache_populate,

View File

@ -1298,7 +1298,7 @@ static void OBJECT_cache_init(void *vedata)
DRW_shgroup_state_disable(sgl->points_dupli_select, DRW_STATE_BLEND);
/* Metaballs Handles */
sgl->mball_handle = shgroup_instance_mball_handles(sgl->non_meshes);
sgl->mball_handle = shgroup_instance_mball_handles(sgl->non_meshes, draw_ctx->shader_cfg);
/* Lamps */
/* TODO

View File

@ -5,6 +5,7 @@
uniform mat4 ViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform vec3 screen_vecs[2];
/* ---- Instantiated Attrs ---- */
@ -31,4 +32,8 @@ void main()
gl_Position = ViewProjectionMatrix * world_pos;
finalColor = vec4(color, 1.0);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * world_pos).xyz);
#endif
}