11/03/2008

11-03-08 - Curves

I finally read Ignacio's talk on displaced subdivision with the NV geometry shader pipeline. You can find the whole talk with audio and such online but I like just the PDF . There's a lot of good stuff in there. A lot of the issues are general issues for low-high poly work, it's just that most people so far have been just ignoring the problems and creating meshes with bad discontinuities.

Ignacio's stuff is based on the Charles Loop paper "Approximating Catmull-Clark Subdivision Surfaces with Bicubic Patches". It's funny that it's really just a fancy version of the PN Triangles hack; the actual geometry surface made is not continuous, but there's a separate tangent field over it which makes the shading look smooth.

While there I noticed a bunch of Loop papers I hadn't read. The Loop-Blinn thing from 05 was particularly interesting because I've talked to a few people in the last N years about rendering fonts better. Thatcher worked on it a bit at Oddworld, and recently Sean's been doing it at RAD for our new GUI product. The Loop Blinn Paper described how to use a pixel shader to shade quadratic or cubic curves. The cubic stuff seems like rather a pain in the butt, but piecewise quadratic is certainly good enough for glyphs. Also they sort of gloss over the details of anti-aliasing, which is of course crucial; there's not much point in being this careful with curves unless you're going to get the antialiasing right.

The MDK Curvy Blues blog covers the same material and claims there are some mistakes in the Loop-Blinn paper. There's also a nice GLSL conics paper and demo app of the Loop-Blinn technique.

Zheng Qin, Michael McCool and Craig Kaplan seem to be doing a lot of work on this stuff at Waterloo. I sort of assume you're familiar with the simple Valve Alpha-test Distance Field thing ; the Qin work is the basis of the Valve technique and is more robust and general, but much more complicated. The Valve technique is probably okay in a game development scenarios where artists are monitoring how their work looks in game and are used to tweaking with weird algorithms, but it definitely has parameters that you have to tweak, and the use of single (or even two) distances can cause bad degeneracies if you're not careful, whenever you have details that are close to the size of a pixel in the distance map.

9 comments:

  1. A pet peeve of mine in Linux (FreeType, Xft, whatever) is that the font filters aren't gamma correct. They're tweaked for black text on white backgrounds, and look pretty bad with white text on black backgrounds.

    And since you are certainly going to have an opinion on this, how do you feel about font hinting/grid fitting?

    A bit off topic:

    Iñigo Quílez (I sent you a link on this guy, and you posted about him here) has this thing on raycasting distance fields:

    http://rgba.scenesp.org/iq/divulgation/nvscene2008/nvscene2008.htm

    ReplyDelete
  2. And since you are certainly going to have an opinion on this, how do you feel about font hinting/grid fitting?
    ---------

    I'm not sure I have a big opinion about that, but it does remind of something I once ranted about in email :

    99% of the sampling literature is wrong.

    When your original underlying data contains infinite frequency step functions, and your output reproduction takes a finite sample set and interpolates using some high frequency function such as a step function or other, then the basic sampling theorem simply does not apply.

    ReplyDelete
  3. So would this imply you favor strong font hinting, since you get a benefit from aligning vertical or horizontal font features with the pixel grid? I think this makes the most sense for text intended to be read. It pisses me off that the crossbar in an 'e' is blurry on this Mac I'm typing on.

    Of course, sometimes it is important to preserve letterforms at the expense of legibility. It is certainly prettier that way, and probably much easier to deal with.

    ReplyDelete
  4. The best font anti-aliasing I've seen uses clear-type-style AA horizontally without hinting horizontally, but does hint vertically.

    ReplyDelete
  5. Whoah, that guy is nuts. His major contention is that LCD manufacturers are not making higher res displays because of the Windows font system !? And Microsoft is intentionally screwing up font layout to hurt other people !? Serious tin foil hat.

    IMO Cleartype is awful. I see shimmery colors in it. His example of "A Quick Brown Fox..." offset 1/10 pixel is particularly bad, if I stare at it red and blue pops out all over.

    But I've always been super sensitive to any blur in screens. For the reasonable future bitmap fonts or strongly hinted fonts are the only way to get crisp text.

    Acrobat seems to do a pretty terrible job, it would probably be better with that technique.

    Still nothing compares to just printing things out with a good laser printer. 10 year old tech FTW.

    ReplyDelete
  6. Hi Sean,

    Yeah, we've had this conversation before at mollyrocket (this is Won, using my nearly defunct Blogger ID). There are a number of points that guy makes in his essay that I disagree with. The MS conspiracy theory is a bit nuts.

    I like the idea of subpixel rendering, but it seems to be playing with fire. The original Blinn/Platt paper talks about designing these really nice reconstruction filters, but my suspicion is that everything is just doing (at best) a 3-subpixel non-gamma-correct box. The reconstruction filter for Xft doesn't even cross pixel boundaries (or at least it didn't used to). The real dice your are rolling though is that monitors are probably very poorly calibrated by default.

    There aren't too many cases when you really care about rendering text in some way where hinting really hurts you. I mean, who cares about preserving letterforms? In most cases (e.g. logos) you are treating the text as graphics, anyway. Certainly readers generally care more about legibility. So I don't understand why anyone would want vertical-only hinting. Why not grid-fit to subpixel boundaries?

    The notable counterexample today is the iPhone, where users are constantly rotating and zooming web pages. The text rendering on the iPhone is unhinted (like all Apple products), but they don't even bother with subpixel rendering. Presumably, it helps that they use such a high DPI display. On a 200 DPI display, 8-bit grayscale text is pretty close to print.

    I suppose you can make the argument that one day, all UIs will be like this, and future monitor DPIs will be much higher. But for now, there's alot of benefit for optimizing legibility on our current crude displays. At least for Latin text, which is pretty ubiquitous.

    ReplyDelete
  7. The first graphics I programmed were for a vector display terminal on an HP mini computer. You drew things by sending HPGL commands, the same commands you sent to the plotter (which was handy cuz we could just send frames to the plotter), the commands were like MOVETO PENUP PENDOWN.

    Anyway, the lines were nice and sharp ;) though flickery and green.

    Consumers just care more about size than res. Super high res displays have existing for a long time, there were CRT's with crazy high res, and now there are LCDs at 200 dpi. For example :

    http://gizmodo.com/gadgets/monitors/toshiba-rolls-out-22+inch-3840x2400-monitor-318115.php

    ReplyDelete
  8. Why not grid-fit to subpixel boundaries?

    I agree that's going to be a huge win for no-blur people like Charles; if your font is going to hint to have pixels be exactly three sub-pixels wide (i.e. black), why not hint to be exactly three sub-pixels wide everywhere.

    There are two issues. One is that it probably still looks more color-y than black does--true black has biased colored edges on LCDs, but they're consistent everywhere so they probably don't jump out as much.

    The other is you probably have to write an actual font hinter, not just hack onto freetype and a generic vector curve munging program, to actually guarantee that all of your stuff stays exactly three or six subpixels wide. Which is I guess why nobody's done it.

    Obviously I'm not espousing the anti-grain guy's conspiracy theories. Also, it's kind of weird: those fonts look AWESOME to me on my 20" 1600x1200 display at home, so I was assuming them not looking good to other people was just the blur/no-blur taste issue, but actually it doesn't look as awesome to me on the 30" 2560x1600 display, it looks more blurry. I think they have a pretty similar dot size, so I'm not sure why I react differently. (I actually sit further from the 30".)

    ReplyDelete
  9. cbloom --

    Yeah, my friend has one of those 200DPI displays, the IBM T221 "Big Bertha." He got it so that he could play more tables of online poker simultaneously. I think the iPhone is more like 160DPI. Still, nothing like the 1200+ DPI you get on a laser printer, but continuous tone certainly helps.

    When you see the colors in the "Sub-pixel positioning quick brown fox" example, do you see the color fringes on the characters, or do you see a color shift from line to line? I only see the latter on my laptop and workstation.

    sean --

    So I wonder how FreeType does subpixel rendering. I think it snaps-to-grid on pixel boundaries, then rasterizes once at 3x resolution. You could get different results if you do subpixel offsets of the glyph outlines, and rasterize 3x at normal resolution. My hypothesis is that a very simple reconstruction filter (i.e. less blurry) would be adequate, and you could even do this with b/w rasterization.

    ReplyDelete