Hacker News new | ask | show | jobs
by mxmxnxor 1984 days ago
Is there a something similar but uses array of bytes as output to application viewport pixels framebuffer? I think it will be way more interesting, especially pixels rendering part. You need implement vector rasterizer (because after you parse ttf font file glyphs represented as sequence of lineTo(x,y) and quadTo(cx,cy,x,y) instructions). You need to implement proper antialiasing (based on area coverage, not sampling, because it gives 256 shades of color not 16x of something like msaa in games). You need to choose some of rendering approaches - for example rasterizing vector objects one by one with blending to background or do some deferring approach with resolving intersection between objects geometrically (to reduce overdraw) and only then walk over pixels and calculate its colors. You also need to implement some dynamic caching and adaptive streaming because you want to zoom big blobs of text and without caching e.g rendering as vector you will not get 60fps and smooth curves without pixelization or LOD changing artifacts)
2 comments

There's super interesting super-fast very high quality font rendering technique on GPU using extremely simple fragment shader and low-res prerendered texture that contains 3-channel signed distance field.

https://youtu.be/6l_oSHWFbb0

That distance fields encoded in the texture are really freaky to capture sharp corners as median of three of them when texture gets interpolated:

https://github.com/copperspice/cs_paint/blob/master/demo/res...

Apparently it's called MSDF fonts and you can read about how to use it practice here

https://css-tricks.com/techniques-for-rendering-text-with-we...

Then it would be “build your own FreeType”.

Zooming big blobs of text at 60fps without caching remains an open problem as it’s necessary to use a GPU shader and all of the approaches make one or another lacklustre trade-offs.

Can you explain more what the problem is?
It's simply that drawing a non trivial amount of(nice looking) generic text (accurately) seems simple but actually takes a lot of logic and a lot of processing time relative to a rendering deadline. There are a lot of reasons for this but largely it comes down to having to do a lot of individual rendering every time something changes and when one thing needs to be rerendered (e.g. the user zoomed) it likely means everything needs you have to bulk render everything again in the next 16 or fewer ms.

https://gankra.github.io/blah/text-hates-you/ has a decent description of many of the problems seen with rendering text in the browser setting (which is on the more complex side of text rendering).