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

Add Texture Smooth Pixel Filter property to BaseMaterial3D #88650

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

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Feb 21, 2024

When enabled, this displays the texture with an appearance that mimics nearest-neighbor filtering with a shader to smooth out aliasing between pixels. This can be used for a pixel art look that is still antialiased regardless of the current antialiasing method in use.

This is also available in SpriteBase3D and Label3D. This could also be implemented in Decal (via a project setting to toggle it for all decals), but this may be left to a future PR as it's more complex.

Thanks to @CptPotato for providing the shader code 🙂

Testing project: test_smooth_pixel_filtering.zip

Preview

Disabled Enabled
Disabled Enabled

On Label3D (alpha transparency) and SpriteBase3D (alpha scissor transparency, so only the internals are smoothed out):

Label3D and SpriteBase3D

Without mipmaps

Watch videos in fullscreen to avoid aliasing (viewport resolution is 1280×720, but videos are 3840×2160).

Disabled

nearest.mp4

Enabled

smooth_pixel_filter.mp4

With mipmaps + 16× anisotropic filtering

Disabled

nearest_aniso.mp4

Enabled

smooth_pixel_filter_aniso.mp4

@caimantilla
Copy link

I'll be shocked if this doesn't make it in seeing as so many games use it. Having to hack around with shader material is a pain, especially since it makes it tough to use the 3D sprite nodes. This is much better...

@akien-mga akien-mga requested a review from a team February 29, 2024 07:23
Copy link
Contributor

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

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

Docs are just fine and say all you need to know about it.

The feature itself is highly requested for games with this art-style. Even me and a group of friends could actually make use of this.

doc/classes/BaseMaterial3D.xml Show resolved Hide resolved
doc/classes/Label3D.xml Show resolved Hide resolved
scene/resources/material.cpp Outdated Show resolved Hide resolved
@Calinou Calinou force-pushed the basematerial3d-add-smooth-pixel-filter branch from 818cb20 to 3e65973 Compare March 7, 2024 07:29
@PerikiyoXD

This comment was marked as off-topic.

@Calinou
Copy link
Member Author

Calinou commented May 6, 2024

@PerikiyoXD Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

When enabled, this displays the texture with an appearance that mimics
nearest-neighbor filtering with a shader to smooth out aliasing between pixels.
This can be used for a pixel art look that is still antialiased
regardless of the current antialiasing method in use.

This is also available in SpriteBase3D and Label3D.
@Calinou Calinou force-pushed the basematerial3d-add-smooth-pixel-filter branch from 3e65973 to 3827d6b Compare June 12, 2024 00:54
@Mickeon
Copy link
Contributor

Mickeon commented Sep 17, 2024

This was discussed a while ago in a rendering meeting under @clayjohn 's discretion (I believe?).

The meeting notes about this are as follows:

  • Simplify PR, then it would be acceptable (texture_custom, remove textureSize)
  • In the future we need to avoid being put in this position, so we need to make the process of using custom shaders en masse easier
  • Add ability to grab albedo_tex in shader material in Sprite3D to override the main texture. To make using custom shaders more feasible

Just putting these here for safe-keeping. I hope you're taking notes too, Calinou! Cheers!

@Calinou
Copy link
Member Author

Calinou commented Sep 17, 2024

  • Simplify PR, then it would be acceptable (texture_custom, remove textureSize)

What do you mean by texture_custom? Is it a way of improving code reuse by making every material sampling function use this method, then redirecting it to texture() or texture_point_smooth() depending on the setting? If so, I can look into doing that.

Also, how can I get rid of textureSize() while allowing arbitrary-sized textures to work with this material? Different PBR maps may also have a different resolution for each PBR map.

  • Add ability to grab albedo_tex in shader material in Sprite3D to override the main texture. To make using custom shaders more feasible

Sounds good, it might be worth creating a dedicated proposal for this though, as I feel this is out of scope for this particular PR.

@clayjohn
Copy link
Member

What do you mean by texture_custom? Is it a way of improving code reuse by making every material sampling function use this method, then redirecting it to texture() or texture_point_smooth() depending on the setting? If so, I can look into doing that.

Ya, just a wrapper function for texture sampling so that the code isn't duplicated every time you want to sample a texture.

Also, how can I get rid of textureSize() while allowing arbitrary-sized textures to work with this material? Different PBR maps may also have a different resolution for each PBR map.

texture size should be passed in as a uniform

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

Successfully merging this pull request may close these issues.

Add an option to use smooth pixel texture filtering in BaseMaterial3D
6 participants