Wednesday, July 25, 2018

opengl - Texture antialiasing?


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!



Answer



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.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...