40 lines
1.3 KiB
GLSL
40 lines
1.3 KiB
GLSL
#version 460
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
#extension GL_EXT_scalar_block_layout : require
|
|
#extension GL_EXT_shader_16bit_storage : require
|
|
|
|
in Varyings {
|
|
layout(location = 0) flat uint instance;
|
|
layout(location = 1) vec2 positionSSPX;
|
|
} var;
|
|
|
|
#include "includes/gui_box_common.glsl"
|
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
float boxSDF(vec2 p, vec2 center, vec2 halfExtents, float borderRadius) {
|
|
vec2 q = abs(p - center) - halfExtents + borderRadius;
|
|
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - borderRadius;
|
|
}
|
|
|
|
#define BOX _Boxes[var.instance]
|
|
|
|
void main() {
|
|
vec2 halfExtentsPX = 0.5 * BOX.sizePX;
|
|
vec2 centerSSPX = BOX.positionSSPX + halfExtentsPX;
|
|
float borderHalfWidthPX = 0.5 * BOX.borderWidthPX;
|
|
|
|
float interiorSDF = boxSDF(var.positionSSPX, centerSSPX, halfExtentsPX, BOX.borderRadiusPX) + BOX.borderWidthPX;
|
|
float borderSDF = abs(interiorSDF - borderHalfWidthPX) - borderHalfWidthPX;
|
|
|
|
float interiorCoverage = clamp(-interiorSDF + 0.5, 0.0, 1.0) * BOX.backgroundColor.a;
|
|
float borderCoverage = clamp(-borderSDF + 0.5, 0.0, 1.0) * BOX.borderColor.a;
|
|
float totalCoverage = interiorCoverage + borderCoverage;
|
|
|
|
fragColor = vec4(
|
|
interiorCoverage * BOX.backgroundColor.rgb +
|
|
borderCoverage * BOX.borderColor.rgb,
|
|
totalCoverage
|
|
);
|
|
}
|