DRW: support clipping for envelope armature draw type
This commit is contained in:
parent
6aebb5a4d5
commit
c55fb58e8a
Notes:
blender-bot
2023-02-14 03:59:42 +01:00
Referenced by issue #60779, 3D Viewport clipping support
|
@ -207,11 +207,12 @@ static void drw_shgroup_bone_stick(
|
|||
/* Envelope */
|
||||
static void drw_shgroup_bone_envelope_distance(
|
||||
const float (*bone_mat)[4],
|
||||
const float *radius_head, const float *radius_tail, const float *distance)
|
||||
const float *radius_head, const float *radius_tail, const float *distance,
|
||||
const eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
if (g_data.passes.bone_envelope != NULL) {
|
||||
if (g_data.bone_envelope_distance == NULL) {
|
||||
g_data.bone_envelope_distance = shgroup_instance_bone_envelope_distance(g_data.passes.bone_envelope);
|
||||
g_data.bone_envelope_distance = shgroup_instance_bone_envelope_distance(g_data.passes.bone_envelope, sh_cfg);
|
||||
/* passes.bone_envelope should have the DRW_STATE_CULL_FRONT state enabled. */
|
||||
}
|
||||
float head_sphere[4] = {0.0f, 0.0f, 0.0f, 1.0f}, tail_sphere[4] = {0.0f, 1.0f, 0.0f, 1.0f};
|
||||
|
@ -244,12 +245,12 @@ static void drw_shgroup_bone_envelope(
|
|||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid, g_data.transparent, sh_cfg);
|
||||
}
|
||||
if (g_data.bone_envelope_wire == NULL) {
|
||||
g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire);
|
||||
g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire, sh_cfg);
|
||||
}
|
||||
if (g_data.bone_envelope_solid == NULL &&
|
||||
g_data.passes.bone_solid != NULL)
|
||||
{
|
||||
g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.passes.bone_solid, g_data.transparent);
|
||||
g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.passes.bone_solid, g_data.transparent, sh_cfg);
|
||||
/* We can have a lot of overdraw if we don't do this. Also envelope are not subject to
|
||||
* inverted matrix. */
|
||||
DRW_shgroup_state_enable(g_data.bone_envelope_solid, DRW_STATE_CULL_BACK);
|
||||
|
@ -1332,7 +1333,7 @@ static void draw_bone_envelope(
|
|||
(boneflag & BONE_NO_DEFORM) == 0 &&
|
||||
((boneflag & BONE_SELECTED) || (eBone && (boneflag & (BONE_ROOTSEL | BONE_TIPSEL)))))
|
||||
{
|
||||
drw_shgroup_bone_envelope_distance(BONE_VAR(eBone, pchan, disp_mat), rad_head, rad_tail, distance);
|
||||
drw_shgroup_bone_envelope_distance(BONE_VAR(eBone, pchan, disp_mat), rad_head, rad_tail, distance, sh_cfg);
|
||||
}
|
||||
|
||||
if (select_id != -1) {
|
||||
|
|
|
@ -625,13 +625,16 @@ DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
|
|||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
|
||||
if (sh_data->bone_envelope_outline == NULL) {
|
||||
sh_data->bone_envelope_outline = DRW_shader_create(
|
||||
datatoc_armature_envelope_outline_vert_glsl, NULL,
|
||||
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_envelope_outline = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_outline_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
||||
});
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_outline, {
|
||||
|
@ -646,17 +649,22 @@ DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
|
|||
pass, DRW_cache_bone_envelope_outline_get(),
|
||||
g_formats.instance_bone_envelope_outline);
|
||||
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
||||
|
||||
if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
|
||||
if (sh_data->bone_envelope_distance == NULL) {
|
||||
sh_data->bone_envelope_distance = DRW_shader_create(
|
||||
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_distance_frag_glsl, NULL);
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_envelope_distance = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_solid_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_armature_envelope_distance_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
||||
});
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
|
||||
|
@ -669,17 +677,22 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
|
|||
sh_data->bone_envelope_distance,
|
||||
pass, DRW_cache_bone_envelope_solid_get(),
|
||||
g_formats.instance_bone_envelope_distance);
|
||||
|
||||
if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp)
|
||||
DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
|
||||
if (sh_data->bone_envelope == NULL) {
|
||||
sh_data->bone_envelope = DRW_shader_create(
|
||||
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_envelope = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg_data->lib, datatoc_armature_envelope_solid_vert_glsl, NULL},
|
||||
.frag = (const char *[]){datatoc_armature_envelope_solid_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg_data->def, NULL},
|
||||
});
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
|
||||
|
@ -695,7 +708,9 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass, bool transp
|
|||
pass, DRW_cache_bone_envelope_solid_get(),
|
||||
g_formats.instance_bone_envelope);
|
||||
DRW_shgroup_uniform_float_copy(grp, "alpha", transp ? 0.6f : 1.0f);
|
||||
|
||||
if (sh_cfg == GPU_SHADER_CFG_CLIPPED) {
|
||||
DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d);
|
||||
}
|
||||
return grp;
|
||||
}
|
||||
|
||||
|
@ -789,7 +804,7 @@ DRWShadingGroup *shgroup_instance_bone_shape_solid(
|
|||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
|
||||
if (sh_data->bone_sphere == NULL) {
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_sphere = GPU_shader_create_from_arrays({
|
||||
|
@ -818,7 +833,7 @@ DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass, bool transp,
|
|||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass, eGPUShaderConfig sh_cfg)
|
||||
{
|
||||
COMMON_Shaders *sh_data = &g_shaders[GPU_SHADER_CFG_DEFAULT];
|
||||
COMMON_Shaders *sh_data = &g_shaders[sh_cfg];
|
||||
if (sh_data->bone_sphere_outline == NULL) {
|
||||
const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg];
|
||||
sh_data->bone_sphere_outline = GPU_shader_create_from_arrays({
|
||||
|
|
|
@ -143,9 +143,9 @@ struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, st
|
|||
struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass, eGPUShaderConfig sh_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);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass, bool transp, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct GPUBatch *geom, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct GPUBatch *geom, bool transp, eGPUShaderConfig sh_cfg);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass, eGPUShaderConfig sh_cfg);
|
||||
|
|
|
@ -3,6 +3,9 @@ uniform mat4 ViewMatrix;
|
|||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
uniform mat4 ModelMatrix;
|
||||
#endif
|
||||
|
||||
uniform vec2 viewportSize;
|
||||
uniform float lineThickness = 2.0;
|
||||
|
@ -130,7 +133,13 @@ void main()
|
|||
vec3 wpos1 = get_outline_point(pos1, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
|
||||
vec3 wpos2 = get_outline_point(pos2, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
|
||||
|
||||
vec4 V = ViewMatrix * vec4(wpos1, 1.0);
|
||||
|
||||
vec4 pos_4d = vec4(wpos1, 1.0);
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
|
||||
#endif
|
||||
|
||||
vec4 V = ViewMatrix * pos_4d;
|
||||
float pres_fac = (ProjectionMatrix[3][3] == 0.0) ? abs(V.z) : 1.0;
|
||||
|
||||
vec4 p0 = ViewProjectionMatrix * vec4(wpos0, 1.0);
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
uniform mat4 ModelMatrix;
|
||||
#endif
|
||||
|
||||
|
||||
/* ---- Instantiated Attrs ---- */
|
||||
in vec3 pos;
|
||||
|
@ -48,8 +52,12 @@ void main()
|
|||
|
||||
normalView = mat3(ViewMatrix) * nor;
|
||||
|
||||
gl_Position = ViewProjectionMatrix * vec4(sp, 1.0);
|
||||
|
||||
finalStateColor = stateColor;
|
||||
finalBoneColor = boneColor;
|
||||
|
||||
vec4 pos_4d = vec4(sp, 1.0);
|
||||
gl_Position = ViewProjectionMatrix * pos_4d;
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance((ModelMatrix * pos_4d).xyz);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue