ray differentials & texture anti-aliasing
November 12th, 2005 by BramzOn Mercury’s request, I’ve been playing with ray differentials and texture filtering this week. Ray differentials are essentially derivatives of the viewing ray with respect to the image plane. They give us an estimation of how much of the surface being hit is covered by one pixel on the image plane, the ray’s “footprint”. This can be used for proper texture filtering. There’s a great paper on that topic by Homan Igehy. The idea is that when a viewing is reflected or refracted, you properly recalculate the ray differentials to simulate the divergent effect you get when hitting for example a reflecting sphere.
Of course, to see the full effect of ray differentials, you need proper texture filtering. the Image texture already had mipmapping and trilinear filtering, which was nice. But I also wanted a box filter for the CheckerBoard texture used in the previous post. As usual, a axis aligned box is estimated based on the ray differentials. Then the checkerboard function (1 for texture A, 0 for texture B) is integrated over this box. This turned out to be a little bit tricky. I estimate the integral first by counting complete tiles in the box, to correct it on each side with partial tiles. The key of this is to know what’s the integral over the box (0, 0) to (du, dv) if du < 1 and < 1. It turns out to be the following with sx and sy the split values of the checkerboard pattern (usually 1/2 and 1/2)
min(du, sx) * min(dv, sy) + max(du – sx, 0) * max(dv – sy, 0)
The resulting code can be found in src/textures/checker_board.cpp on the CVS.
Below, I’ve added a render of a reflecting and refracting sphere on a checkerboard pattern to illustrate the effect. The script is on the CVS: examples/textures/anti_aliasing.py. The reflecting sphere looks OK, but the refracting one still has problems. I’ve magnified it in the bottom picture. There’s a large region that is way to blurry. I’ve indicated the edges of this region so you can clearly see this isn’t what’s supposed to happen. I suspect the problem is either in the code to refract a ray differential, or in the differential geometry of the sphere. To be continued …
November 12th, 2005 at 1:17 pm
Hah, yeah … it’s something that had to be done anyway :) Those filtering algorithms, you mean about the ray differentials?
November 12th, 2005 at 12:59 pm
I had no idea you’d work so hard fix the texture filtering immediately. :) I haven’t even heard of some of these filtering algorithms.
Anyway, it’s looking really great. Keep up the good work.
November 14th, 2005 at 12:39 pm
i know i should be editing your refl/refr article (pls mail me texnixcentre doc :)), but…
“The idea is that when a viewing is reflected or refracted, you properly recalculate the ray differentials” -> “The idea is that when a view ray is reflected or refracted, you properly recalculate its differentials”
i’m actually going to continue editing it now…
November 14th, 2005 at 12:40 pm
oh and (as i’ve said online) this looks really really cool :D can’t wait until you’ve fixx0red the mesh bugs and commited the latest source!
November 15th, 2005 at 10:18 am
it’s a matter of hours now :) I’ve sent you a zip with the tex file …