implement label drawable

This commit is contained in:
ohyzha
2024-08-22 13:29:18 +03:00
parent f7f4897aff
commit a2923966fa
7 changed files with 682 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
#version 450
layout(location = 0) in vec4 color;
layout(location = 1) in vec2 texCoord;
layout(location = 0) out vec4 outColor;
layout(set = 5, binding = 0) uniform LabelData
{
vec2 textSize;
float radius;
float arrowLength;
bool hasRoundedCorners;
bool hasArrow;
} labelInfo;
void main()
{
if (labelInfo.hasRoundedCorners)
{
vec2 bbox;
if (!labelInfo.hasArrow)
{
bbox = labelInfo.textSize;
}
else
{
bbox = vec2(labelInfo.textSize.x, labelInfo.textSize.y + labelInfo.arrowLength);
}
const float arrowLength = labelInfo.hasArrow ? labelInfo.arrowLength : 0;
vec2 uvScaled = texCoord * bbox;
//vec2 uvNoArrow = texCoord * labelInfo.textSize;
float distX = min(uvScaled.x, bbox.x - uvScaled.x);
float distY = min(uvScaled.y - arrowLength, bbox.y - uvScaled.y);
float distanceFromEdge = distX * distY;
float scaledRadius = labelInfo.radius/10000.f;
if (distanceFromEdge < scaledRadius)
{
discard;
}
}
outColor = color;
}