Friday, May 18, 2012

Don't Stretch It

One of the most annoying yet easy-to-make mistakes when it comes to drawing rendertargets to the screen is accidentally invoking filtering.  Even the slightest difference between the rendertarget size/placement and the viewport size/placement can cause stretching, which will invoke the minifaction or magnification texture filter.  If you've set them to "linear," which is a reasonable thing to do, the result is effectively a 2x2 box blur over your whole image.  Nice.  You've just halved the effective resolution.  In the case of D3D9, it's even worse, because you're not safe even if you've got the size right: the texel-to-pixel half-offset madness can still cause the same effect.

Up until a few minutes ago, my path tracer was suffering from this problem.  I noticed it immediately when I switched from GL to CUDA, but figured it might be a CUDA-specific thing and decided to wait until a later time to debug it.  But it occurred to me today that it might be my good old friend texture filtering!  And indeed it was.  Changing the filtering to nearest-neighbor fixed it immediately.  My images now look significantly sharper at edges and high-frequency details.  Here's a comparison:



The latter is correct.

In conclusion: if you think your image looks blurred, texture filtering is probably the culprit!

No comments:

Post a Comment