SFML community forums

Help => Graphics => Topic started by: oomek on January 29, 2018, 05:01:03 am

Title: Enable anisotropic filtering
Post by: oomek on January 29, 2018, 05:01:03 am
When I use generateMipmap() with default bilinear filtering the results are very poor.  Is it possible to enable anisotropic filtering from SFML? I would like to avoid forcing it through the driver.
Title: Re: Enable anisotropic filtering
Post by: Hapax on January 29, 2018, 11:23:06 pm
Anisotropic filtering doesn't make much sense with 2D.
Title: Re: Enable anisotropic filtering
Post by: oomek on January 29, 2018, 11:31:06 pm
Allow me to disagree. With autogenerated mipmaps zoomed out images look very blurry with default bilinear filtering. When I force aniso through the driver the quality difference is very noticeable. I can sharpen it a little by changing the bias to negative, but then the aliasing and pixel crawling can be seen. With aniso it’s perfectly sharp when scaling and no artiffacts are visible
Title: Re: Enable anisotropic filtering
Post by: Hapax on January 29, 2018, 11:49:55 pm
Wouldn't this just be using mipmaps, which you can do manually by switching the texture rectangle? If so, the question might have been 'can we enable mipmaps?' or something.
Anisotropic filtering shouldn't really help unless the angle of the surface is away from the camera and that can only happen in 3D.
Title: Re: Enable anisotropic filtering
Post by: eXpl0it3r on January 29, 2018, 11:57:04 pm
the question might have been 'can we enable mipmaps?' or something.
You may have missed, that SFML does support mipmaps (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Texture.php#a7779a75c0324b5faff77602f871710a9).

Since you're using OpenGL directly anyways, isn't there an option to set the wanted filtering? (note: I'm an OpenGL noob).
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 12:17:21 am
Anisotropic filtering takes way more samples per pixel than bilinear and it really helps with sharpening mipmaps when you display the texture at for example 25% of its size. I’ve tested it and see a huge difference in sharpness, so the argument that anisotropic filtering is only for textures deformed in 3D space has no grounds.
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 12:21:10 am
I can force aniso in the gpu control panel, but I wish it could be configurable within the app.
Title: Re: Enable anisotropic filtering
Post by: Foaly on January 30, 2018, 01:55:01 pm
There seems to be some confusion what you are trying to request. If you already have some test code, please post it so everybody can check it out. Maybe some screenshots would help too.
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 01:57:00 pm
Sure thing, in the evening I’ll post a video
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 06:46:43 pm
Ok, here is an example image and the explanation of what is happening.

(https://s17.postimg.org/d82n9u5tb/SFML_Anisotrolic_Filtering.png)

When I scale the square image with mipmaps generated to a smaller size with different x/y factors the image is blurred in both axes so you lose a lot of detail. The same happens when I scale an image which is a rectangular shape to a square size.

The conclusion is that anisotropic filtering would really help preserving the scaling detail even in 2D
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 07:01:33 pm
Setting anisotropic filtering for the whole app that would affect the result of the setSmooth() function would be of a tremendous help.
Title: Re: Enable anisotropic filtering
Post by: oomek on January 30, 2018, 08:35:01 pm
Here is a video showing the filtering quality in motion.

https://www.youtube.com/watch?v=nDA9vD92Chg

On the left - anisotropic x16 forced in the GPU driver’s settings
On the right - default bilinear SFML filtering
Title: Re: Enable anisotropic filtering
Post by: Hapax on February 03, 2018, 04:25:49 pm
Is this something that can be achieved with a shader?
Title: Re: Enable anisotropic filtering
Post by: oomek on February 03, 2018, 04:31:13 pm
I’m prety sue it can be. But firstly it will be slower and secondly, what is the point of breaking through an open door :)
Much easier would be to set one flag than rewriting all the shaders.
Title: Re: Enable anisotropic filtering
Post by: Hapax on February 03, 2018, 05:13:41 pm
I just mean that it's at least possible before SFML modifies to include the filtering option, if it does. :)
Title: Re: Enable anisotropic filtering
Post by: oomek on February 05, 2018, 07:51:56 pm
It should be relatively easy to implement according to this guide:
http://www.informit.com/articles/article.aspx?p=770639&seqNum=2
Title: Re: Enable anisotropic filtering
Post by: Foaly on February 05, 2018, 09:49:36 pm
Well I guess it could be done. The question is how to find a good API for implementing it. It would of course be nice to set a kind of level for the texture filtering. Something like
enum FilterLevel
{
    Nearest,
    BiLinear,
    Anisotropic
}
But it will be difficult to fit it to the current Texture::setSmooth API.
Title: Re: Enable anisotropic filtering
Post by: oomek on February 05, 2018, 10:14:25 pm
I don’t think we need an additional api to change the filtering to anisotropic. You just call glTexParameterf() which is used to set the bilinear filtering in SFML. The only problem is with checking if the device supports GL_EXT_texture_filter_anisotropic extension, but that is also one function call available in glTools. I’m preety sure i could set the aniso for all the textures by modifying just one line of SFML code, but without checking if it’s supported.
Title: Re: Enable anisotropic filtering
Post by: Foaly on February 05, 2018, 11:48:10 pm
Hmm I don't think it should be enabled by default when filtering is enabled, as it may come with quiet a performance impact (wikipedia (https://en.wikipedia.org/wiki/Anisotropic_filtering)).
Title: Re: Enable anisotropic filtering
Post by: oomek on February 05, 2018, 11:52:59 pm
Of course, it should be enabled per texture. It’s not expensive on the modern hardware, maybe on devices 10 year old. I’ve never experienced any fps drops, even by one frame when I was enabling aniso.