5 ms·
This is really neat. Though in practice if you are using this kind of thing I'm pretty sure you will want to combine it with atlasing (i.e. construct an atlas o
by pcwalton 11y ago
This is really neat. Though in practice if you are using this kind of thing I'm pretty sure you will want to combine it with atlasing (i.e. construct an atlas of glyphs via render to texture). That's because it's a waste of time to rerasterize glyphs in the FS every frame (which appears to be 200+ lines) instead of caching the results and reducing the per-frame work to a 5-line FS that just blits. In most apps pans are more common than zooms and the same glyphs are used over and over, so this usually ends up being a win. Using atlases also reduces the number of raster operations because the same glyphs tend to appear on the page repeatedly, and by using atlases you rasterize each glyph only once. Even more importantly, though, atlasing gives you the ability to reuse a blitting fragment shader to render other content (images, figures, etc.) as well as glyphs from the atlas in order to reduce state changes.
- baldajan 11y agoThat was my first thought. This is brilliant, but the FS is way overworked, making this less practical and going back to the original solution (because it's fast). It's a trade off between speed and variability, which for games (and most apps) speed trump variability (especially because of consistent design). But given generating a texture atlas is a "1 time task"; and recompiling the curves in the GPU is per frame in the paper, the next best thing I guess is off loading the glyph atlas generator to the GPU, not CPU, since the GPU maybe faster. It's really awesome research!
- carterehsmith 11y agoWait. I guess you did not read the article at all? It is all about atlasing. There are issues with atlas of glyphs; so rather than putting the whole glyphs in atlas, he slices the glyphs in a grid, the grid being defined by the intersection of the underlying Bezier curves. And then he puts the grid pieces in atlas.
- pcwalton 11y ago> Wait. I guess you did not read the article at all? It is all about atlasing. Yes, I understand the technique. Perhaps I should be more clear about my terminology. I'm using "atlas" in the narrow sense of "actual pieces of bitmap data stored in a texture". My point is that this technique should not be a substitute for atlasing in this sense, but could well be combined with it.
- CyberDildonics 11y agoI don't know why you are being downvoted, that is what is happening and I am not convinced that straight textures would be better. We already know that SDF textures are better than straight texture atlases anyway. The technique is obviously practical in some respect (since it renders a pdf faster than anything else I've seen) and the quality of the text is very sharp, even close up. Super sharp lines when zoomed in may not seem like a big deal, but as you increase resolution you will reap the benefits since the same size text will be sharper.
- armitron 11y ago> We already know that SDF textures are better than straight texture atlases anyway. This is isn't true. SDF textures can be "better" for "some" applications (like games that want to display stencils mostly at arbitrary zoom levels without losing a lot of quality) but they're also visibly lower-quality compared to glyphs rendered by freetype at each one of these zoom levels. So, for an application that simply displays lots of text while infrequently changing the glyph size, SDF textures are not a good solution.
- CyberDildonics 11y agoYou are essentially saying that an SDF texture isn't as good as a freetype glyph rendered at the resolution it is being displayed at. If you don't have to change the zoom of what you are looking at you don't have to use a texture at all, you can just use the pixels from the freetype vector render directly.
- pcwalton 11y agoThe FS is something like 200 lines (verified in the WebGL debugger). A blitting shader is about 5. If fragment shading load doesn't matter, then of course you don't need straight textures. But if you want to reduce the load on the GPU and do the efficient thing, without any quality loss, it's better to use atlases. > We already know that SDF textures are better than straight texture atlases anyway. Even that depends. SDFs are slow to construct and, because they have a special FS, you have to pay attention to the number of state changes. They do have the advantage (unlike this technique) of having a very simple FS--they can even be used in some fixed function hardware!--making it practical to rerasterize glyphs every frame. > The technique is obviously practical in some respect (since it renders a pdf faster than anything else I've seen) That says a lot about how existing PDF renderers are slow and nothing about what is the fastest thing to do on the GPU.
- derefr 11y agoThere's also the higher level—the thing web browser rendering engines do, where you generate a texture for each "tile" (single-layer viewport rectangle) of likely-to-be-static text, and carry those around until you have to zoom or the text changes. I'm not sure if you need the medium-level (font atlasing) if you have both lower-level (bezier-curve atlasing), and higher-level (pre-composited "tiles.") This is one of the reasons I really like WebGL, actually: for GUI elements, you can usually skip rendering them within the game altogether, instead using plain HTML+CSS controls positioned above the <canvas>, where they'll be treated as separate "tiles" that aren't dirtied by whatever your game is doing. Imagine: relatively-static fully-RGBA-translucent stuff sitting on top of your animating viewport, composited into a final image each frame, "for free."
- panic 11y agoThe font atlas is definitely still worth it. For example: your comment, which fits in a single browser tile, is made up of 735 drawn glyphs. There are 50 distinct glyphs used (not counting italics because I'm lazy). Assuming it takes twice as long to draw a glyph into an atlas but half as long to draw it once it's in the atlas, an atlas that starts completely empty will speed up text drawing for your comment by 66% (735 divided by 50 * 2 + (735 - 50) * 0.5, which is 442.5). And this underestimates the savings by a lot (drawing glyphs from an atlas is much more than two times as fast, and some glyphs are probably in the atlas already).
- derefr 11y agoThe question is about amortized time-cost, though. • Most frames won't involve zooming or text-change—and therefore will be handled at "zero" time-cost by re-using the pre-composited tile. • The frames that do involve text-change (but not zoom) can benefit from font-atlasing. • The frames that involve discrete zoom, where text goes from one integral font size (represented in the atlas) to another integral font size (also in the atlas) can also benefit from font-atlasing. • The frames that involve continuous zoom—such as in this demo—can't benefit from font-atlasing, because the frames where the font is e.g. 7.037773pt large can't be served from the atlas. Keep in mind that the only reason we do discrete zoom-levels in PDF readers, text editors, etc. is that font-atlasing is "the optimization we have", and it calls for discrete zoom levels. When the UX affordance is for continuous zoom—think about pinch-to-zoom in Mobile Safari, or about zooming into Google Earth—font-atlasing doesn't and can't work. But this technique can. Now, in games in particular, "continuous zoom" is a pretty rare edge-case. GUI elements don't tend to get zoomed into[1]. And "in-VR" elements, like street signs in an FPS, aren't usually designed as a bunch of geometry[2], but rather as a very high-detail flat texture that maybe gets mipmapped from far away. "Zooming" by approaching a street sign doesn't make the fonts on it re-render themselves; there are no fonts on it, they're just baked into an image. --- [1] Well, maybe; I could see a case for continuous zoom of the fonts—and other GUI geometry—plastered over units in RTS games. "Pan up" with units selected, they stay selected but their unit names+stats get smaller and smaller and eventually get obscured by draw-distance and atmosphere effects, just as if they were actually "there" in the scene instead of part of the GUI. (Makes me think of the windows in the TV show ReBoot.) [2] This does make me imagine a Blade Runner-esque game full of holographic signs, though. Those could definitely benefit from this approach.)
- crzwdjk 11y agoThis latter bit is exactly what modern 2D display drivers already do, or at least what the NVIDIA binary X driver does. It keeps a glyph cache in video memory and just blits from it to the extent that it can. It's still counting on the software to do the rasterization though, and I don't think there's a way to do the rasterizing on the GPU and then feed that data straight into the glyph cache.