Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable anisotropic filtering for 3D materials by default on desktop platforms #37847

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Apr 13, 2020

This results in better appearance for textures viewed from oblique angles. Many other engines now enable it by default. On today's desktop platforms, the performance impact is minimal if other effects are already taxing the GPU.

The anisotropic filtering quality can be configured as usual in the Project Settings. Setting it to 1 should disable it even if individual materials have it enabled, so this is easy to revert if you don't want it.

I see screenshots of Godot projects not using anisotropic filtering too often – let's change that! 🙂

This closes godotengine/godot-proposals#3134.

Preview

I used this Sponza demo for the screenshots. Click to view at full size, look at the floor.

Before

aniso_off

After

Note: the screenshot below uses 4× anisotropic filtering, not 8× which is the new default on desktop platforms.

aniso_on

@Calinou Calinou added this to the 4.0 milestone Apr 13, 2020
@akien-mga akien-mga requested a review from reduz April 13, 2020 13:33
@Logharaa
Copy link
Contributor

Logharaa commented Jul 5, 2020

Why is it not merged?

@Calinou
Copy link
Member Author

Calinou commented Jul 5, 2020

@Logharaa reduz said on IRC he'd prefer this to be implemented in a more fine-grained fashion.

@Logharaa
Copy link
Contributor

Logharaa commented Jul 5, 2020

@Calinou Oh ok thanks for the info!

@reduz
Copy link
Member

reduz commented Oct 19, 2020

Mobile cant deal with this as well, and it needs to be tested on lower end devices too, so lets wait a bit on this one

@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from f5764fd to ebf43c9 Compare November 7, 2020 15:54
@Calinou
Copy link
Member Author

Calinou commented Nov 7, 2020

I amended the pull request to use 8× anisotropic filtering on desktop and 1× on mobile (which effectively disables it there).

@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from ebf43c9 to 26bfca0 Compare November 7, 2020 15:56
@Calinou Calinou changed the title Enable anisotropic filtering for 3D materials by default Enable anisotropic filtering for 3D materials by default on desktop platforms Nov 7, 2020
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from 26bfca0 to 391a922 Compare November 7, 2020 16:02
@Calinou Calinou requested a review from a team as a code owner November 7, 2020 16:02
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch 2 times, most recently from 94a406e to dd0dd5c Compare November 7, 2020 16:05
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from dd0dd5c to f60ac01 Compare April 1, 2021 23:30
@Calinou Calinou requested review from a team as code owners April 1, 2021 23:30
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from f60ac01 to 044ed04 Compare April 1, 2021 23:48
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch 3 times, most recently from 5152d5a to 1d56552 Compare August 16, 2021 03:34
@reduz
Copy link
Member

reduz commented Jul 28, 2022

This needs testing on low end desktop devices to ensure it makes a difference in performance or not.

@YuriSizov YuriSizov added this to the 4.1 milestone Feb 9, 2023
@clayjohn clayjohn modified the milestones: 4.1, 4.x May 23, 2023
@fire
Copy link
Member

fire commented Nov 6, 2024

@Calinou Do you think we can cover enough devices to turn this on by default?

@fire
Copy link
Member

fire commented Nov 6, 2024

I salvaged the PR, but I'll let it simmer in my branch of Godot Engine for a bit until I submit it.

https://github.com/V-Sekai/godot/tree/vsk-default-enable-anisotropic-filtering-4.4

This results in better appearance for textures viewed from oblique
angles. Many other engines now enable it by default.
On today's desktop platforms, the performance impact is minimal if
other effects are already taxing the GPU.

The default value chosen (8x) is a good balance between performance
and quality. Depending on the scene, you may be able to use 16x
anisotropic filtering with little to no cost in terms of frame time.

The anisotropic filtering quality can be configured as usual in the
Project Settings. Setting it to 1x will disable it even if individual
materials have it enabled, so this is easy to revert if you don't
want it.
@Calinou Calinou force-pushed the default-enable-anisotropic-filtering branch from 1d56552 to 0a69239 Compare November 7, 2024 00:01
@Calinou Calinou requested review from a team as code owners November 7, 2024 00:01
@Calinou
Copy link
Member Author

Calinou commented Nov 7, 2024

Rebased and tested again (using @fire's work as a base), it works as expected.

I've also modified the glTF importer to handle this for material import (remember to reimport 3D scenes for this change to apply, e.g. by removing the .godot/ folder).

@fire fire requested a review from clayjohn November 7, 2024 17:23
Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codestyle checks out. Kinda surprised that anisotropic filtering wasn't already the default; always assumed it was a pretty free feature (maybe not for really low-end devices?)

@Repiteo Repiteo modified the milestones: 4.x, 4.4 Nov 25, 2024
@clayjohn
Copy link
Member

I agree with reduz, this needs confirmation that it won't harm low end devices. I'm confident that it is a good change for most dedicated GPUs, but I suspect that many integrated GPUs will take a performance hit from this. Since this imposes a new default on all users, we need to be careful and validate these changes before we go ahead.

@Calinou
Copy link
Member Author

Calinou commented Nov 28, 2024

I did some tests of https://github.com/Calinou/godot-sponza-4 on my laptop (on AC in balanced mode):

PC specifications
  • CPU: Intel Core i9-13900H
  • GPU: Intel Iris Xe / NVIDIA GeForce RTX 4060 Laptop GPU
  • RAM: 48 GB (16 + 32 GB DDR4-3200 C22)
  • SSD: Solidigm P44 Pro 2 TB
  • OS: Windows 11 23H2
Type master (no AF) This PR (8x AF)
Intel, Mobile, 1152x648 296 FPS (3.38 mspf) 283 FPS (3.54 mspf)
Intel, Mobile, 2560x1600 90 FPS (11.11 mspf) 88 FPS (11.36 mspf)
Intel, Compatibility, 1152x648 490 FPS (2.04 mspf) 492 FPS (2.03 mspf)
Intel, Compatibility, 2560x1600 144 FPS (6.94 mspf) 140 FPS (7.14 mspf)
NVIDIA, Mobile, 1152x648 1510 FPS (0.66 mspf) 1487 FPS (0.67 mspf)
NVIDIA, Mobile, 2560x1600 611 FPS (1.64 mspf) 599 FPS (1.67 mspf)
NVIDIA, Compatibility, 1152x648 1695 FPS (0.59 mspf) 1727 FPS (0.58 mspf)
NVIDIA, Compatibility, 2560x1600 798 FPS (1.25 mspf) 797 FPS (1.25 mspf)

The performance difference is very small on average, especially compared to the significant gain in quality. Limiting ourselves to 8x probably did the heavy lifting here, since it's basically twice as cheap as 16x with only a slight loss in visual quality. (Console versions of games often limit themselves to 8x AF for a similar reason, since CPU and GPU memory is shared.)

Note that this is a scene with no post-processing effects applied, so scenes with post-processing will spend a greater time in areas other than anisotropic texture sampling (therefore reducing the % impact of anisotropic filtering).

@Zireael07
Copy link
Contributor

What about Android devices? They're the ones which are really low-end for Godot...

@Calinou
Copy link
Member Author

Calinou commented Nov 28, 2024

What about Android devices? They're the ones which are really low-end for Godot...

I've tested 8x AF on my Samsung Galaxy Z Fold4 and couldn't spot a performance difference on its main screen (it always ran at a locked 120 FPS, also on Truck Town).

However, this PR doesn't enable anisotropic filtering by default on mobile (since the .mobile feature tag override is used to set it to 1x, which is the same as disabled). We could revisit this in a future PR - I expect 2x AF to perform well on all mobile devices nowadays, maybe even 4x.

@clayjohn
Copy link
Member

However, this PR doesn't enable anisotropic filtering by default on mobile (since the .mobile feature tag override is used to set it to 1x, which is the same as disabled). We could revisit this in a future PR - I expect 2x AF to perform well on all mobile devices nowadays, maybe even 4x.

The performance impact of anisotropic textures doesn't work like that. There is no inherent performance penalty from using it (except for on very old devices), the performance cost comes from the additional bandwidth needed to sample it. Mobile devices are often bottlenecked by reading from textures, so multiplying the cost of texture reads is prohibitive. Desktop devices are almost never bottlenecked by texture reads, so its a free quality improvement. Remember, taking more time for something that isn't the bottleneck is essentially free (until you optimize your existing bottleneck).

Low end integrated devices struggle more with texture reads than dedicated GPUs do. So we need to test there to assess the realistic impact. Testing on a high end device or a dedicated GPU won't give you any useful information unfortunately

@clayjohn clayjohn modified the milestones: 4.4, 4.x Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

Set default 3D material sampling method to Linear Mipmap Anisotropic
8 participants