2024-10-13 22:18:37 -06:00
|
|
|
#version 450
|
2024-10-20 21:59:28 -06:00
|
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
|
|
#extension GL_EXT_buffer_reference : require
|
|
|
|
|
|
|
|
#include "ui_common.glsl"
|
|
|
|
|
2024-10-18 16:31:28 -06:00
|
|
|
layout(set = 0, binding = 0) uniform sampler font_samplers[];
|
|
|
|
layout(set = 1, binding = 0) uniform texture2DArray font_textures[];
|
2024-10-13 22:18:37 -06:00
|
|
|
|
2024-10-21 10:09:52 -06:00
|
|
|
layout(set = 2, binding = 0) uniform sampler samplers[];
|
|
|
|
layout(set = 3, binding = 0) uniform texture2D textures[];
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
layout(location = 0) in vec4 fragColor;
|
|
|
|
layout(location = 1) in vec2 fragUV;
|
2024-11-12 11:56:57 -07:00
|
|
|
layout(location = 2) flat in uint glyph;
|
2024-10-18 22:53:06 -06:00
|
|
|
layout(location = 3) flat in uint index;
|
|
|
|
layout(location = 4) flat in uint type;
|
2024-10-22 17:48:37 -06:00
|
|
|
layout(location = 5) flat in vec2 container_offset;
|
2024-10-13 22:18:37 -06:00
|
|
|
|
|
|
|
layout(location = 0) out vec4 outColor;
|
|
|
|
|
2024-11-12 11:56:57 -07:00
|
|
|
vec4 hsv_to_rgb(vec4 hsv) {
|
|
|
|
float C = hsv[1] * hsv[2];
|
|
|
|
float H = hsv[0]*6;
|
|
|
|
float X = C * (1 - abs(mod(H, 2) - 1));
|
|
|
|
vec4 temp;
|
|
|
|
if(0 <= H && H <= 1) {
|
|
|
|
temp = vec4(C, X, 0, 0);
|
|
|
|
} else if(1 <= H && H <= 2) {
|
|
|
|
temp = vec4(X, C, 0, 0);
|
|
|
|
} else if(2 <= H && H <= 3) {
|
|
|
|
temp = vec4(0, C, X, 0);
|
|
|
|
} else if(3 <= H && H <= 4) {
|
|
|
|
temp = vec4(0, X, C, 0);
|
|
|
|
} else if(4 <= H && H <= 5) {
|
|
|
|
temp = vec4(X, 0, C, 0);
|
|
|
|
} else if(5 <= H && H <= 6) {
|
|
|
|
temp = vec4(C, 0, X, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
float m = hsv[2] - C;
|
|
|
|
return vec4(temp[0] + m, temp[1] + m, temp[2] + m, hsv[3]);
|
|
|
|
}
|
|
|
|
|
2024-10-13 22:18:37 -06:00
|
|
|
void main() {
|
2024-10-24 20:49:59 -06:00
|
|
|
vec2 pos = (gl_FragCoord.xy - vec2(0.5, 0.5))/pc.layer.container.context.scale;
|
2024-10-22 17:48:37 -06:00
|
|
|
vec2 min = container_offset;
|
2024-10-20 21:59:28 -06:00
|
|
|
vec2 max = min + pc.layer.container.size;
|
|
|
|
if(pos.x < min.x || pos.y < min.y
|
|
|
|
|| pos.x > max.x || pos.y > max.y) {
|
|
|
|
discard;
|
|
|
|
}
|
2024-10-18 22:53:06 -06:00
|
|
|
if(type == 0) {
|
|
|
|
outColor = fragColor;
|
|
|
|
} else if(type == 1) {
|
2024-11-12 11:56:57 -07:00
|
|
|
outColor = fragColor * texture(sampler2DArray(font_textures[index], font_samplers[index]), vec3(fragUV, glyph));
|
2024-10-21 10:09:52 -06:00
|
|
|
} else if (type == 2) {
|
|
|
|
outColor = fragColor * texture(sampler2D(textures[index], samplers[index]), fragUV);
|
2024-11-12 11:56:57 -07:00
|
|
|
} else if (type == 3) {
|
|
|
|
outColor = hsv_to_rgb(fragColor);
|
2024-10-18 22:53:06 -06:00
|
|
|
}
|
2024-10-13 22:18:37 -06:00
|
|
|
}
|
|
|
|
|