From a8f7d41d3898a8d3ae8afb4f95ea9f4f44db2a69 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 8 Jul 2022 12:07:08 +0200 Subject: Draw: Curve outline drawing in object mode. This patch adds (selected/active) outline around a curve object in object mode. {F13270680} In the past the draw bounds option was enabled for any curve objects. With this patch it isn't needed and will be disabled. In the future the curve outline could also be enabled to improve GPU selection. Reviewed By: dfelinto, HooglyBoogly, fclem Maniphest Tasks: T95933 Differential Revision: https://developer.blender.org/D15308 --- .../overlay/shaders/infos/overlay_outline_info.hh | 10 +++ .../overlay_outline_prepass_curves_vert.glsl | 81 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl (limited to 'source/blender/draw/engines/overlay/shaders') diff --git a/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh b/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh index 6f6a9c1622d..288fb3b3cbd 100644 --- a/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh +++ b/source/blender/draw/engines/overlay/shaders/infos/overlay_outline_info.hh @@ -29,6 +29,16 @@ GPU_SHADER_CREATE_INFO(overlay_outline_prepass_mesh_clipped) GPU_SHADER_INTERFACE_INFO(overlay_outline_prepass_wire_iface, "vert").flat(Type::VEC3, "pos"); +GPU_SHADER_CREATE_INFO(overlay_outline_prepass_curves) + .do_static_compilation(true) + .vertex_source("overlay_outline_prepass_curves_vert.glsl") + .additional_info("draw_hair", "overlay_outline_prepass") + .additional_info("draw_object_infos"); + +GPU_SHADER_CREATE_INFO(overlay_outline_prepass_curves_clipped) + .do_static_compilation(true) + .additional_info("overlay_outline_prepass_curves", "drw_clipped"); + GPU_SHADER_CREATE_INFO(overlay_outline_prepass_wire) .do_static_compilation(true) .define("USE_GEOM") diff --git a/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl new file mode 100644 index 00000000000..f9ec475d21f --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/overlay_outline_prepass_curves_vert.glsl @@ -0,0 +1,81 @@ + +#pragma BLENDER_REQUIRE(common_view_clipping_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) +#pragma BLENDER_REQUIRE(common_hair_lib.glsl) + +uint outline_colorid_get(void) +{ + int flag = int(abs(ObjectInfo.w)); + bool is_active = (flag & DRW_BASE_ACTIVE) != 0; + + if (isTransform) { + return 0u; /* colorTransform */ + } + else if (is_active) { + return 3u; /* colorActive */ + } + else { + return 1u; /* colorSelect */ + } + + return 0u; +} + +/* Replace top 2 bits (of the 16bit output) by outlineId. + * This leaves 16K different IDs to create outlines between objects. + vec3 world_pos = point_object_to_world(pos); + * SHIFT = (32 - (16 - 2)) */ +#define SHIFT 18u + +void main() +{ + bool is_persp = (drw_view.winmat[3][3] == 0.0); + float time, thickness; + vec3 center_wpos, tan, binor; + + hair_get_center_pos_tan_binor_time(is_persp, + ModelMatrixInverse, + drw_view.viewinv[3].xyz, + drw_view.viewinv[2].xyz, + center_wpos, + tan, + binor, + time, + thickness); + vec3 world_pos; + if (hairThicknessRes > 1) { + /* Calculate the thickness, thicktime, worldpos taken into account the outline. */ + float outline_width = point_world_to_ndc(center_wpos).w * 1.25 * + drw_view.viewport_size_inverse.y * drw_view.wininv[1][1]; + thickness += outline_width; + float thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1); + thick_time = thickness * (thick_time * 2.0 - 1.0); + /* Take object scale into account. + * NOTE: This only works fine with uniform scaling. */ + float scale = 1.0 / length(mat3(ModelMatrixInverse) * binor); + world_pos = center_wpos + binor * thick_time * scale; + } + else { + world_pos = center_wpos; + } + + gl_Position = point_world_to_ndc(world_pos); + +#ifdef USE_GEOM + vert.pos = point_world_to_view(world_pos); +#endif + + /* Small bias to always be on top of the geom. */ + gl_Position.z -= 1e-3; + + /* ID 0 is nothing (background) */ + interp.ob_id = uint(resource_handle + 1); + + /* Should be 2 bits only [0..3]. */ + uint outline_id = outline_colorid_get(); + + /* Combine for 16bit uint target. */ + interp.ob_id = (outline_id << 14u) | ((interp.ob_id << SHIFT) >> SHIFT); + + view_clipping_distances(world_pos); +} -- cgit v1.2.3