This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/gpu_shader_icon_frag.glsl

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.6 KiB
GLSL
Raw Normal View History

UI: Icon number indicator for data-blocks Adds the possibility of having a little number on top of icons. At the moment this is used for: * Outliner * Node Editor bread-crumb * Node Group node header For the outliner there is almost no functional change. It is mostly a refactor to handle the indicators as part of the icon shader instead of the outliner draw code. (note that this was already recently changed in a5d3b648e3e2). The difference is that now we use rounded border rectangle instead of circles, and we can go up to 999 elements. So for the outliner this shows the number of collapsed elements of a certain type (e.g., mesh objects inside a collapsed collection). For the node editors is being used to show the use count for the data-block. This is important for the node editor, so users know whether the node-group they are editing (or are about to edit) is used elsewhere. This is particularly important when the Node Options are hidden, which is the default for node groups appended from the asset libraries. --- Note: This can be easily enabled for ID templates which can then be part of T84669. It just need to call UI_but_icon_indicator_number_set in the function template_add_button_search_menu. --- Special thanks Clément Foucault for the help figuring out the shader, Julian Eisel for the help navigating the UI code, and Pablo Vazquez for the collaboration in this design solution. For images showing the result check the Differential Revision. Differential Revision: https://developer.blender.org/D16284
2022-10-20 16:37:07 +02:00
/**
* Draw the icons, leaving a semi-transparent rectangle on top of the icon.
*
* The top-left corner of the rectangle is rounded and drawned with anti-alias.
* The anti-alias is done by transitioning from the outer to the inner radius of
* the rounded corner, and the rectangle sides.
*/
void main()
{
/* Top-left rounded corner parameters. */
const float circle_radius_outer = 0.1;
const float circle_radius_inner = 0.075;
/**
* Add a bit transparency to see a bit of the icon, without
* getting on the way of readability. */
const float mask_transparency = 0.25;
vec2 circle_center = vec2(circle_radius_outer - text_width, 0.5);
fragColor = texture(image, texCoord_interp) * color;
/* radius in icon space (1 is the icon width). */
float radius = length(mask_coord_interp - circle_center);
float mask = smoothstep(circle_radius_inner, circle_radius_outer, radius);
bool lower_half = mask_coord_interp.y < circle_center.y;
bool right_half = mask_coord_interp.x > circle_center.x;
if (right_half && mask_coord_interp.t < circle_center.y + circle_radius_outer) {
mask = smoothstep(circle_center.y + circle_radius_inner,
circle_center.y + circle_radius_outer,
mask_coord_interp.t);
}
if (lower_half && mask_coord_interp.s > circle_center.x - circle_radius_outer) {
mask = smoothstep(circle_center.x - circle_radius_inner,
circle_center.x - circle_radius_outer,
mask_coord_interp.s);
}
fragColor = mix(vec4(0.0), fragColor, max(mask_transparency, mask));
}