I'm writing a simple text editor using Vulkan for rendering, and I'm seeing some strange outline around the rendered letters if I take a screenshot of the text and zoom in, which bothers me because I can't explain why it's there.
Here's what RenderDoc shows in the texture view (note that in the pixel context view at the bottom right there's no outline around the text)
However, if I take a screenshot and zoom in, I'll see this border around the letters:
I use a pre-rendered font atlas in a texture stored as R8_UNORM. Then I use a very basic shader which takes the texture and produces a pixel with premultiplied alpha, ready to be blended by just adding the colors of src and dest:
#version 450 core
layout(set = 1, binding = 0) uniform sampler2D texSampler;
layout(location = 0) in vec2 v_tex_coord;
layout(location = 1) in vec3 v_color;
layout(location = 0) out vec4 f_color;
void main() {
f_color = vec4(v_color, 1.0) * texture(texSampler, v_tex_coord).a;
}
I'm puzzled and out of ideas on why this outline is there - I don't see why the pixels next to text border would suddenly become darker when I'm only adding positive color components and none of them are negative (just to make sure there are no negative components I tried modifying the shader and took absolute value of every component with exactly the same result).
In case it matters, my swapchain surface format is B8G8R8A8_UNORM and the colorspace is SRGB_NONLINEAR_KHR. The colors are exactly what I expect them to be so I assumed that gamma-wise it's OK but maybe I'm wrong.
Would appreciate any help with this.
UPD. I just made it work on my office Macbook and there's no outline there! So it must be something to do with either my window surface on windows or even with screenshot-taking apps (I've tried snipping tool, printscr and snip & sketch)
1-src.alpha
. Non-premultiplied src:dest' = dest * (1-src.alpha) + src * (src.alpha)
Premultiplied src:dest' = dest * (1-src.alpha) + src
$\endgroup$src
is a white pixel with a 10% opacity and thedest
is somedest_color
. Then the resulting color will bedest_color * 0.9 + 0.1 * 1.0
, which is always brighter thandest_color
. I've just made all the text white and there's still an outline :(. Thank you very much for looking into it, it's hard to debug without having the app running. $\endgroup$1.0
(why not assign an alpha value oftexture(texSampler, v_tex_coord).a
?). Presumably your DST blend factor should be set to VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA. And the SRC blend factor should be set to VK_BLEND_FACTOR_ONE. How did you set up your blending? Is blending enabled? (I assume so) Pedantically:alpha = texture(texSampler, v_tex_coord).a; f_color = vec4(v_color, 1.0) * alpha
orvec4(v_color * alpha, alpha)
$\endgroup$