Hacker News new | ask | show | jobs
by gnramires 2126 days ago
> In the article, talking about smoothstep approximation of sinc: "I'd argue the smoothstep version looks better" Why would this be? I would have thought the theoretically correct sinc version would look nicer.

In this case we are sort of mimicking the eye. The eye doesn't do sinc-bandlimiting (it does a sort of angular integration -- it sums the photons received in a region).

I say "sort of", because we're really doing two steps: first we are projecting a scene into a screen, and then the eye is viewing the screen. We want (in most cases) that what the eye sees in the screen corresponds to what it would see directly (if seeing the scene in reality).

The naive rendering approach simply samples an exact point for each pixel. When there's high pixel variation (higher spatial frequency than the pixel frequency), as you move the camera the samples will alternate rapidly which wouldn't correspond to the desired eye reconstruction. The eye would see approximately an averaged (integrated) color over a small smooth angular window.

Note we really never get the perfect eye reconstruction unless the resolution of your display is much larger than the resolution your eye can perceive[1]. But through anti-aliasing at least this sampling artifact disappears.

This window-integration is not an ideal sinc filtering! Actually it's not bandlimiting at all! since it is a finite-support convolution -- bandlimiting is just a convenient theoretical (approximate/incorrect) description.

In the frequency domain this convolution is not a box (ideal sinc filtering), it's smooth with ripples. In the spatial domain (that's really used here), it probably does look something like a smoothstep (a smooth window)[2]. The details don't matter if the resolution is large[3].

[1] Plus we would actually need to model other optical effects of the eye (like focus and aberration) that I won't go into detail :) But you can ask if interested.

[2] It looks something like this: https://foundationsofvision.stanford.edu/wp-content/uploads/... found here: https://foundationsofvision.stanford.edu/chapter-2-image-for... This describes only the optical behavior of the eye, there's also the sampling behavior of the retina.

[3] Because our own eye integrates the pixels anyway. Again this does ignore other optical effects of the eye (such as "focus" and aberration) that vary with distance to the focal plane, and more.

TL;DR: The correct function looks something like this https://foundationsofvision.stanford.edu/wp-content/uploads/... , which seems close to a smoothstep.

1 comments

Just fixing a mistake: what I described is the window function, not the integrated (in this case, cosine) function that was used in the article. In this case there would still be ripples when applying the shown window function (in cosine integration). I do think ripple-free are probably better functions (or some faster decaying ripples) because of limited floating point precision generating artifacts (which can be seen in the center in the second demo).

Experimentally playing around a little I've found

fcos = cos(x) * sin(0.5 * w)/(0.5 * w) * smoothstep(6.28,0.0,0.38*w)

To be a good compromise between eliminating high frequency ripple and maintaining good definition.