Unify text shader handling
This commit is contained in:
@@ -8,13 +8,10 @@ layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
layout(set = 3, binding = 0) uniform TextConfig
|
||||
{
|
||||
vec4 textColor;
|
||||
vec4 borderColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float borderSize;
|
||||
vec4 textColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float smoothing;
|
||||
bool applyBorder;
|
||||
} textConfig;
|
||||
|
||||
float median(float r, float g, float b) {
|
||||
|
||||
@@ -8,29 +8,17 @@ layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
layout(set = 3, binding = 0) uniform TextConfig
|
||||
{
|
||||
vec4 textColor;
|
||||
vec4 borderColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float borderSize;
|
||||
vec4 textColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float smoothing;
|
||||
bool applyBorder;
|
||||
} textConfig;
|
||||
|
||||
void main()
|
||||
{
|
||||
float distance = texture(texSampler, texCoord).r;
|
||||
float alpha = smoothstep(textConfig.threshold - textConfig.smoothing, textConfig.threshold + textConfig.smoothing, distance);
|
||||
if (textConfig.applyBorder)
|
||||
{
|
||||
float border = smoothstep(textConfig.threshold + textConfig.borderSize - textConfig.smoothing,
|
||||
textConfig.threshold + textConfig.borderSize + textConfig.smoothing, distance);
|
||||
outColor = mix(textConfig.borderColor, textConfig.textColor, border) * alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
outColor = vec4(textConfig.textColor) * alpha;
|
||||
}
|
||||
outColor = vec4(textConfig.textColor) * alpha;
|
||||
|
||||
if (textConfig.backgroundColor.a != 0)
|
||||
{
|
||||
|
||||
32
openVulkanoCpp/Shader/sdfTextWithBorder.frag
Normal file
32
openVulkanoCpp/Shader/sdfTextWithBorder.frag
Normal file
@@ -0,0 +1,32 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
layout(set = 3, binding = 0) uniform TextConfig
|
||||
{
|
||||
vec4 textColor;
|
||||
vec4 borderColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float borderSize;
|
||||
float smoothing;
|
||||
} textConfig;
|
||||
|
||||
void main()
|
||||
{
|
||||
float distance = texture(texSampler, texCoord).r;
|
||||
float alpha = smoothstep(textConfig.threshold - textConfig.smoothing, textConfig.threshold + textConfig.smoothing, distance);
|
||||
|
||||
float border = smoothstep(textConfig.threshold + textConfig.borderSize - textConfig.smoothing,
|
||||
textConfig.threshold + textConfig.borderSize + textConfig.smoothing, distance);
|
||||
outColor = mix(textConfig.borderColor, textConfig.textColor, border) * alpha;
|
||||
|
||||
if (textConfig.backgroundColor.a != 0)
|
||||
{
|
||||
outColor = mix(textConfig.backgroundColor, outColor, alpha);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec4 color;
|
||||
//layout(location = 0) in vec4 color;
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
@@ -10,12 +10,9 @@ layout(set = 2, binding = 0) uniform sampler2D texSampler;
|
||||
layout(set = 3, binding = 0) uniform TextConfig
|
||||
{
|
||||
vec4 textColor;
|
||||
vec4 borderColor;
|
||||
vec4 backgroundColor;
|
||||
float threshold;
|
||||
float borderSize;
|
||||
float smoothing;
|
||||
bool applyBorder;
|
||||
} textConfig;
|
||||
|
||||
void main()
|
||||
|
||||
Reference in New Issue
Block a user