5
\$\begingroup\$

In my Minecraft-clone style game, blocks are textured with a border that is lighter then the block color. See picture below:

Blocks, with GL_NEAREST

To achieve this effect without the textures being blurry I use this code:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Without setting the MAG_FILTER to GL_NEAREST, it looks like this:

Without GL_NEAREST

This is ugly and blurry. The upper picture (with GL_NEAREST enabled) is obviously superior. My issue is that the edges in the upper picture are aliased (it is more obvious if you view the photo full-size.)

Is there any way to anti-alias textures? It does not look very good if the borders are aliased like this. Alternatively, is there any way to get rid of the aliasing on the borders?

Thank you for any help!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Just to be clear, you're talking about the aliasing between the white and gray portions of the textures, not on the outer side of the geomtry, right? Do you have multisampling turned on just in case? \$\endgroup\$ Jan 7, 2012 at 18:49
  • \$\begingroup\$ Exactly. I have 4x antialiasing enabled, so the outside of the geometry is not aliased at all. If you enlarge the first picture you can see that the line between the border and the interior part of the texture is aliased. \$\endgroup\$ Jan 7, 2012 at 18:52
  • 1
    \$\begingroup\$ I think you might have to implement a more advanced type of filtering on the pixel shader. The first resource I've run into was this although I only glanced through it. \$\endgroup\$ Jan 7, 2012 at 19:07
  • 1
    \$\begingroup\$ It reads: In this section we look at methods for improving the visual quality of rendered textures using interpolation filters and antialiasing. We also present a method for restoring sharp edges in interpolated textures. So I think it might be what you need. \$\endgroup\$ Jan 7, 2012 at 19:08

2 Answers 2

5
\$\begingroup\$

Well, the simplest way to do it is use a higher-resolution texture, together with a full mip chain, trilinear filtering, and you'll probably want to turn on anisotropic filtering as well; that should give you smooth edges without (as much) over-blurring.

Another approach would be to use distance field textures, which are specifically for two-tone images (in the paper, for text rendering, where the two tones are the text color and transparent). They are able to get sharp, but aliased edges at any level of magnification. This should work for minification too although they only touch on it in the paper.

\$\endgroup\$
1
  • \$\begingroup\$ This is the approach I've taken. Thanks for the help. \$\endgroup\$ Jan 9, 2012 at 6:14
5
\$\begingroup\$

If you were to employ post-process antialiasing such as SMAA, it would not differentiate between geometric edges and texel edges. This might be sufficient in conjunction with the nearest neighbor texture filtering.

\$\endgroup\$
2
  • \$\begingroup\$ +1 This seems like a good alternative to implementing a more advanced texture filtering algorithm. \$\endgroup\$ Jan 7, 2012 at 19:11
  • \$\begingroup\$ Just keep in mind that there is an SMAA method demonstrated that uses a depth buffer to give a greater bias towards geometric edges. Basically you don't want to use that. Determine edges with chroma/luma instead. \$\endgroup\$
    – ChrisC
    Jan 7, 2012 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .