-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix blurry text #1494
Fix blurry text #1494
Conversation
I'm quite happy the bad font quality turned out to be a bug after all, thanks for having a look at this |
@@ -17,7 +17,6 @@ using .GLAbstraction | |||
const atlas_texture_cache = Dict{Any, Tuple{Texture{Float16, 2}, Function}}() | |||
|
|||
function get_texture!(atlas) | |||
Makie.set_glyph_resolution!(Makie.High) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? If it is we should probably have GLMakie set the glyph resolution on init, not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is we should probably have GLMakie set the glyph resolution on init, not here.
That's already the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, I think I added this, to make sure Makie gets the correct texture atlas - sadly this is a Makie global variable... E.g., when using GLMakie, then WGLMakie and then switching back to GLMakie you'll get pretty weird artifacts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, nvm, this works on an existing texture atlas...
activate!
is the right place: https://github.com/JuliaPlots/Makie.jl/blob/master/GLMakie/src/GLMakie.jl#L42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to get artifacts when doing empty!(Makie.global_texture_atlas)
and removing the cached files. But I'm not getting them anymore. I don't think I got when switching between WGLMakie and GLMakie either.
The test failures are the animated surface. I think we can ignore those |
Amazing! |
@@ -41,7 +41,7 @@ flat in vec4 f_uv_texture_bbox; | |||
// These versions of aastep assume that `dist` is a signed distance function | |||
// which has been scaled to be in units of pixels. | |||
float aastep(float threshold1, float dist) { | |||
return min(1.0, f_viewport_from_u_scale)*smoothstep(threshold1-ANTIALIAS_RADIUS, threshold1+ANTIALIAS_RADIUS, dist); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably check if that changed anything. For text it was irrelevant, but maybe it matters for scatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a difference in characters scatters. I guess it's fine
The failing test is lines(Rect(0, 0, 1, 1), linewidth=4)
scatter!([Point2f(0.5, 0.5)], markersize=1, markerspace=SceneSpace, marker='I')
current_figure() which yields which matches what I'd expect the marker to look like. Here it is with the render from FreeTypeAbstraction below it: using FreeTypeAbstraction
lines(Rect(0, 0, 1, 1), linewidth=4)
font = findfont("Dejavu Sans")
char = 'I'
img, fe = renderface(font, char, 400)
w, h = size(img)
l = 0.5 - w/800
r = 0.5 + w/800
b = 0.5 - h/800
t = 0.5 + h/800
image!(l..r, b..t, img[:, end:-1:1], colormap=(:white, :black))
scatter!(
[Point2f(0.5, 0.5)], markersize=1, markerspace=SceneSpace, marker=char,
color = (:orange, 0.4)
)
current_figure() |
Yeah it's not unlikely, that we should just update the reference images for that .. we should take the chance and pin down the expected behavior |
The short version of my changes is that a real numbered markersize with a character or string marker is now drawn as scaled version of the respective character. I.e. The scaling changes result in this: scene = Scene()
campixel!(scene)
scatter!(scene, Point2f[(50, 100), (100, 100), (150, 100), (200, 100)], marker="^l_j", markersize=50)
scatter!(scene, Point2f[(50, 100), (100, 100), (150, 100), (200, 100)], color = :red, markersize=4)
text!(scene, ["^", "l", "_", "j"], position = Point2f[(50, 200), (100, 200), (150, 200), (200, 200)], textsize = 50, align=(:center, :center))
scene |
Perfect, I think that matches how I implemented it in Cairomakie |
Up to maybe a pixel or two the "^l_j" example is the same between CairoMakie, GLMakie and WGLMakie now. Though CairoMakie can't do string markers, only characters so I switched to 4 individual scatter plots. I think from my side this is done now. (short_test_13 should fail on every run now, but have the same as the one I showed above.) |
Sweet!!!! |
I was using https://github.com/JuliaPlots/Makie.jl/blob/cb9087ee9055313260611e7eafa8e7a0a0184024/GLMakie/assets/shader/distance_shape.frag#L158-L160 |
Ah I see... Would be nice to test those boundingboxes somewhere still, to see if they match what freetype expects... |
They don't because they have padding :p I guess you could run a character through the text machinery and then check if the |
Nice work, thank you! |
Well, we do need a function that correctly gives us the rendered boundingbox of a glyph for a certain font & fontsize ... I lost a bit track which one that is right now, but maybe that's a good chance to find the correct one and document & test it! |
Ok I'll give it a try |
Closes #1470
The problem here was that the glyph padding did not make it into the texture atlas.
Makie uses a signed distance field approach, which essentially encodes the distance to the closest edge at each pixel. From that you can recover the original symbol by evaluating
color = text_color * (distance > 0)
at each pixel (assuming positive distances inside the symbol). Antialiasing essentially swaps the step function(distance > 0)
for a smoothed step function (i.e. sigmoid). This means some small negative distances outside the original shape are included. We need to make sure that these are available, otherwise we get artifacts like in #1470.On current master this is not the case. Padding is included in the texture generation but is discarded when the signed distance fields gets inserted into the texture atlas. This pr changes that - with it the padding is included during insertion and it's increased so that we have 1.5px padding at a textsize of 8px. (1px padding still looked blurry.)
Note that this chunks up the glyph size quite a bit. If we run into "texture atlas is too small. Resizing not implemented yet. Please file an issue at Makie if you encounter this" errors we should be fine decreasing the default glyph resolution to 32px. (In case you find this pr because of that error please do report it. You can clear your cache by deleting the files at
Makie.get_cache_path()
and restarting Julia orempty!(Makie.global_texture_atlas)
.)Before and after:
(Textsizes are 8, 10, 16, 20, 32, 64, 100)
And specifically the figure from #1470
TODO: