implement label drawable
This commit is contained in:
44
openVulkanoCpp/Shader/label.frag
Normal file
44
openVulkanoCpp/Shader/label.frag
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user