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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to use texture supersampling in BaseMaterial3D #10096

Open
Calinou opened this issue Jul 2, 2024 · 0 comments
Open

Add an option to use texture supersampling in BaseMaterial3D #10096

Calinou opened this issue Jul 2, 2024 · 0 comments

Comments

@Calinou
Copy link
Member

Calinou commented Jul 2, 2024

Describe the project you are working on

The Godot editor 馃檪

Describe the problem or limitation you are having in your project

When you have Label3Ds or Sprite3D icons in the distance, they become pixelated if mipmaps are disabled, or blurry if mipmaps are enabled. This is particularly a problem in some situations:

  • ViewportTextures shown on materials at a distance (e.g. for interactive GUIs in a 3D world) become pixelated as they don't generate mipmaps in real-time.
  • GUIs in XR become pixelated or blurry, and therefore less comfortable to interact with.
  • Label3Ds become pixelated (without mipmaps) or blurry (with mipmaps) at a distance, making them harder to read.

While MSDF fonts can be used to improve font rendering at a distance somewhat, they still remain fairly blurry at low sizes due to the lack of font hinting and suffer from some limitations (such as not supporting colored emoji). There is also no equivalent for Sprite3Ds that can be used out of the box, as it's limited to representations of monochrome vector data in general. Lastly, using MSDF fonts will not help within a ViewportTexture as the ViewportTexture rasterizes the whole thing.

The problem and some solutions are well-described in this article from Ben Golus: Sharper Mipmapping using Shader Based Supersampling

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add an option to use texture supersampling in BaseMaterial3D (and Sprite3D/Label3D). This has a moderate performance cost, so it should be disabled by default and enabled on specific materials or nodes when you need it.

When coupled with negative mipmap biasing (which can be applied in the shader itself using the 3rd argument of GLSL's texture()), this provides better sharpness than the default sampling method while not suffering from any more aliasing. This also benefits standard mipmapped textures as seen in the example below (see the noise texture on the left).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Texture supersampling typically uses one of the two algorithms:

  • Ordered Grid Sumpersampling (OGSS).
  • Rotated Grid Supersampling (RGSS). This technique is generally a straight upgrade from OGSS as it looks a bit better while having the same cost.

I have a prototype branch with RGSS implemented for the albedo map: https://github.com/Calinou/godot/tree/basematerial3d-add-rgss

Here's an example in action (click to view at full size):

Normal

Grid texture from left to right: Nearest, Nearest Mipmaps, Linear Mipmaps, Linear Mipmaps Anisotropic (16脳)

Normal

Rotated grid supersampling (with -1.0 mipmap bias)

RGSS

Ground truth

Rendered at 3840脳2160 and downsampled to 1152脳648.

Ground truth

If this enhancement will not be used often, can it be worked around with a few lines of script?

For materials applied on MeshInstance3D, this can be worked around with a custom shader. However, for Label3D or Sprite3D, this can't be done without a lot of additional work to use the material override.

Is there a reason why this should be core and not an add-on in the asset library?

Most 3D projects with diegetic UI and XR projects will need this at some point to ensure their UI looks good, particularly at lower viewport resolutions (e.g. on Steam Deck).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant