Object Mode: Use same empty (arrow) drawing as the bone axes display

This commit is contained in:
Clément Foucault 2018-08-17 12:16:50 +02:00
parent 7d720cc655
commit 435f308eed
7 changed files with 57 additions and 99 deletions

View File

@ -286,6 +286,7 @@ data_to_c_simple(modes/shaders/overlay_face_orientation_vert.glsl SRC)
data_to_c_simple(modes/shaders/overlay_face_wireframe_vert.glsl SRC)
data_to_c_simple(modes/shaders/overlay_face_wireframe_geom.glsl SRC)
data_to_c_simple(modes/shaders/overlay_face_wireframe_frag.glsl SRC)
data_to_c_simple(modes/shaders/object_empty_axes_vert.glsl SRC)
data_to_c_simple(modes/shaders/object_empty_image_frag.glsl SRC)
data_to_c_simple(modes/shaders/object_empty_image_vert.glsl SRC)
data_to_c_simple(modes/shaders/object_outline_resolve_frag.glsl SRC)

View File

@ -985,77 +985,6 @@ GPUBatch *DRW_cache_empty_capsule_cap_get(void)
#undef NSEGMENTS
}
GPUBatch *DRW_cache_arrows_get(void)
{
if (!SHC.drw_arrows) {
GPUVertBuf *vbo = fill_arrows_vbo(1.0f);
SHC.drw_arrows = GPU_batch_create_ex(GPU_PRIM_LINES, vbo, NULL, GPU_BATCH_OWNS_VBO);
}
return SHC.drw_arrows;
}
GPUBatch *DRW_cache_axis_names_get(void)
{
if (!SHC.drw_axis_names) {
const float size = 0.1f;
float v1[3], v2[3];
/* Position Only 3D format */
static GPUVertFormat format = { 0 };
static struct { uint pos; } attr_id;
if (format.attr_len == 0) {
/* Using 3rd component as axis indicator */
attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
}
/* Line */
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
GPU_vertbuf_data_alloc(vbo, 14);
/* X */
copy_v3_fl3(v1, -size, size, 0.0f);
copy_v3_fl3(v2, size, -size, 0.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
copy_v3_fl3(v1, size, size, 0.0f);
copy_v3_fl3(v2, -size, -size, 0.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 2, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 3, v2);
/* Y */
copy_v3_fl3(v1, -size + 0.25f * size, size, 1.0f);
copy_v3_fl3(v2, 0.0f, 0.0f, 1.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 4, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 5, v2);
copy_v3_fl3(v1, size - 0.25f * size, size, 1.0f);
copy_v3_fl3(v2, -size + 0.25f * size, -size, 1.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 6, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 7, v2);
/* Z */
copy_v3_fl3(v1, -size, size, 2.0f);
copy_v3_fl3(v2, size, size, 2.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 8, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 9, v2);
copy_v3_fl3(v1, size, size, 2.0f);
copy_v3_fl3(v2, -size, -size, 2.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 10, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 11, v2);
copy_v3_fl3(v1, -size, -size, 2.0f);
copy_v3_fl3(v2, size, -size, 2.0f);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 12, v1);
GPU_vertbuf_attr_set(vbo, attr_id.pos, 13, v2);
SHC.drw_axis_names = GPU_batch_create_ex(GPU_PRIM_LINES, vbo, NULL, GPU_BATCH_OWNS_VBO);
}
return SHC.drw_axis_names;
}
GPUBatch *DRW_cache_image_plane_get(void)
{
if (!SHC.drw_image_plane) {

View File

@ -70,8 +70,6 @@ struct GPUBatch *DRW_cache_empty_cylinder_get(void);
struct GPUBatch *DRW_cache_empty_cone_get(void);
struct GPUBatch *DRW_cache_empty_capsule_cap_get(void);
struct GPUBatch *DRW_cache_empty_capsule_body_get(void);
struct GPUBatch *DRW_cache_arrows_get(void);
struct GPUBatch *DRW_cache_axis_names_get(void);
struct GPUBatch *DRW_cache_image_plane_get(void);
struct GPUBatch *DRW_cache_image_plane_wire_get(void);

View File

@ -186,6 +186,7 @@ extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
extern char datatoc_object_mball_handles_vert_glsl[];
extern char datatoc_object_empty_axes_vert_glsl[];
static struct {
struct GPUShader *shape_outline;
@ -203,6 +204,7 @@ static struct {
struct GPUShader *volume_velocity_needle_sh;
struct GPUShader *volume_velocity_sh;
struct GPUShader *empty_axes_sh;
struct GPUShader *mball_handles;
} g_shaders = {NULL};
@ -368,22 +370,6 @@ DRWShadingGroup *shgroup_instance_screen_aligned(DRWPass *pass, struct GPUBatch
return grp;
}
DRWShadingGroup *shgroup_instance_axis_names(DRWPass *pass, struct GPUBatch *geom)
{
GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS);
DRW_shgroup_instance_format(g_formats.instance_screen_aligned, {
{"color", DRW_ATTRIB_FLOAT, 3},
{"size", DRW_ATTRIB_FLOAT, 1},
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
});
DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screen_aligned);
DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
return grp;
}
DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct GPUBatch *geom)
{
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE);
@ -414,6 +400,26 @@ DRWShadingGroup *shgroup_instance(DRWPass *pass, struct GPUBatch *geom)
return grp;
}
DRWShadingGroup *shgroup_instance_empty_axes(DRWPass *pass, struct GPUBatch *geom)
{
if (g_shaders.empty_axes_sh == NULL) {
g_shaders.empty_axes_sh = DRW_shader_create(
datatoc_object_empty_axes_vert_glsl, NULL,
datatoc_gpu_shader_flat_color_frag_glsl, NULL);
}
DRW_shgroup_instance_format(g_formats.instance_sized, {
{"color", DRW_ATTRIB_FLOAT, 3},
{"size", DRW_ATTRIB_FLOAT, 1},
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
});
DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.empty_axes_sh, pass, geom, g_formats.instance_sized);
DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
return grp;
}
DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct GPUBatch *geom, int *baseid)
{
GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE);

View File

@ -116,7 +116,7 @@ struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struc
struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_axis_names(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_empty_axes(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_image_plane(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPUBatch *geom);
struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom);

View File

@ -162,8 +162,7 @@ typedef struct OBJECT_ShadingGroupList {
DRWShadingGroup *cone;
DRWShadingGroup *single_arrow;
DRWShadingGroup *single_arrow_line;
DRWShadingGroup *arrows;
DRWShadingGroup *axis_names;
DRWShadingGroup *empty_axes;
/* GPUTexture -> EmptyImageShadingGroupData */
GHash *image_plane_map;
@ -1136,11 +1135,8 @@ static void OBJECT_cache_init(void *vedata)
geom = DRW_cache_single_line_get();
sgl->single_arrow_line = shgroup_instance(sgl->non_meshes, geom);
geom = DRW_cache_arrows_get();
sgl->arrows = shgroup_instance(sgl->non_meshes, geom);
geom = DRW_cache_axis_names_get();
sgl->axis_names = shgroup_instance_axis_names(sgl->non_meshes, geom);
geom = DRW_cache_bone_arrows_get();
sgl->empty_axes = shgroup_instance_empty_axes(sgl->non_meshes, geom);
/* initialize on first use */
sgl->image_plane_map = NULL;
@ -1798,8 +1794,7 @@ static void DRW_shgroup_empty_ex(
DRW_shgroup_call_dynamic_add(sgl->cone, color, draw_size, mat);
break;
case OB_ARROWS:
DRW_shgroup_call_dynamic_add(sgl->arrows, color, draw_size, mat);
DRW_shgroup_call_dynamic_add(sgl->axis_names, color, draw_size, mat);
DRW_shgroup_call_dynamic_add(sgl->empty_axes, color, draw_size, mat);
break;
case OB_EMPTY_IMAGE:
BLI_assert(!"Should never happen, use DRW_shgroup_empty instead.");

View File

@ -0,0 +1,29 @@
uniform mat4 ViewProjectionMatrix;
uniform vec3 screenVecs[3];
/* ---- Instanciated Attribs ---- */
in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
in vec2 screenPos;
/* ---- Per instance Attribs ---- */
in vec3 color;
in float size;
in mat4 InstanceModelMatrix;
flat out vec4 finalColor;
void main()
{
float draw_size = 4.0 * size;
vec3 chosen_axis = InstanceModelMatrix[int(axis)].xyz;
vec3 loc = InstanceModelMatrix[3].xyz;
vec3 wpos = loc + chosen_axis * fract(axis) * draw_size;
vec3 spos = screenVecs[0].xyz * screenPos.x + screenVecs[1].xyz * screenPos.y;
/* Scale uniformly by axis length */
spos *= length(chosen_axis) * draw_size;
gl_Position = ViewProjectionMatrix * vec4(wpos + spos, 1.0);
finalColor = vec4(color, 1.0);
}