17
$\begingroup$

The 99 lines of C path tracer Smallpt renders a 2x2 subpixel grid for each pixel it intends to render and then does a tent filter to combine them.

There is an interesting presentation explaining the code here, and it mentions the tent filter but doesn't explain why it's there.

Can anyone explain why a tent filter would be preferable in this case over a box blur (just averaging the samples)?

Would it be higher quality to go with something better than a tent filter, such as bicubic hermite interpolation?

$\endgroup$

2 Answers 2

19
$\begingroup$

The theoretical ideal antialiasing filter for discretely sampled data is a sinc filter, because it perfectly removes all frequencies higher than the Nyquist frequency, while leaving alone all the lower ones. So, to some extent, we can expect antialiasing filters that more closely resemble the sinc filter to produce better-quality images.

The tent filter (triangle filter) certainly resembles the central peak of the sinc filter more closely than does the box filter:

sinc, triangle, and box filters

A bicubic filter (e.g. Mitchell-Netravali) could capture the shape of the sinc even more precisely, including its first two negative lobes.

The reality of filter selection is a bit more subtle than "approximate sinc as well as possible", since there are different kinds of artifacts that can be generated by "non-ideal" antialiasing filters, such as aliasing, overblurring, and ringing. Also, different filters may be more or less computationally expensive. So it's a game of trying to trade off the different artifacts against each other and against performance. Different scenes/images may favor one choice or another, and it's also partly an aesthetic judgement.

As for why smallpt uses a tent filter in particular, I would guess for a combination of performance (it's a quick filter to evaluate) and brevity—it can be done in a couple lines of code, while a bicubic filter would take a bunch more code.

Incidentally, smallpt actually uses a 2x2 subpixel grid and places a tent filter at each subpixel, then averages together the results of the four subpixels. So the overall effect is, curiously, that of the sum of four tents, which ends up looking like a pyramid with a flat top:

subpixel tent filters

I'm not sure if this was intentional, or just happened to be the way it worked out. My guess is this results in a somewhat sharper image than if a single tent filter per pixel were used (because of the narrower support), but probably also more visible aliasing.

$\endgroup$
2
  • $\begingroup$ I can't help saying thanks! Acturally, I first understand this as stratified sampling with 4 strata. And I make the number of "strata" customizable, like 9, 16... Now, I know it is a "trapezoid" filter(not so common in other renderers). And as the number of my "strata" tends to be infinity, the filter becomes a box filter, where I'm painting the lily... Interesting! $\endgroup$
    – chaosink
    May 1, 2018 at 15:48
  • $\begingroup$ Hi Nathan, in the first graph, the box filter should have a range [-0.5, 0.5] along the X axis. $\endgroup$
    – chaosink
    Jan 12 at 20:38
4
$\begingroup$

I just looked at Wikipedia articles about Bilinear interpolation. A tent filter is a kind of Bilinear interpolation. A Bilinear interpolation interpolates on 2 dimensions. It first linearly interpolates on one dimension and then the other.

enter image description here

When you look at this picture, it first does it on the column and then the row for example.

The reason why this could be better than averaging colors, is that when one of the points gets closer to the center than another one, it contributes more to the final color. With averaging the colors, all the points contributes equally, even when one point is closer to the center than another point.

If all the 4 points are on fixed positions on a equal distance from the center, then you get exactly 25% contribution on all points, that's the same as averaging.

This means that when you implement anti aliasing by just rendering at 4 times higher resolution, and then down sampling it. The output between the 2 ways should be the same, as far as I understand it.

So, which filter should you use? Well, it depends on what you want and your situation. If you pick random sub pixel locations for your samples, then it might be better to use a Bilinear interpolation. If all the points are fixed and you just render out at a higher resolution, then averaging could be useful. In the end this is all just some sub pixel things that normally you don't or barely notice, so if there is some kind if AA, then it's good enough. But that's just my opinion and probably that of the average viewer of 3D animation or something like that.

A Bicubic interpolation gives you a smoother look. Bicubic: enter image description here

Bilinear: enter image description here

Which is better? Well, it depends on what you like, and I don't think that there will be a huge difference.

My sources: https://en.wikipedia.org/wiki/Reconstruction_filter#Image_processing

https://en.wikipedia.org/wiki/Bilinear_interpolation

https://en.wikipedia.org/wiki/Bicubic_interpolation

(Images are from Wikipedia and are public domain)

I hope this helps, I just want to say that I am not a professional on this, I'm just somebody that just likes computer graphics stuff. It could be that I made some mistakes. If so, just say it and I change it!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.