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

Can you turn off texture filtering (want to use pixely low res textures) #233

Open
Tim-Harlow opened this issue Dec 29, 2020 · 9 comments
Open
Labels
question Further information is requested

Comments

@Tim-Harlow
Copy link

Can you turn off texture filtering (want to use pixely low res textures)? Currently, if I lower the resolution of the texture, it just makes it more blury.

@Zylann
Copy link
Owner

Zylann commented Dec 30, 2020

This question was answered countless times for pixel-art games, in various ways. The same applies in 3D: find your texture in the filesystem dock, select it, then go to the Import tab: it has a filter option. Uncheck it and click "Reimport".

image

@Zylann Zylann added the question Further information is requested label Dec 30, 2020
@manum45
Copy link

manum45 commented Oct 3, 2023

This option is not present anymore in Godot4's Texture2D import. According to this, filtering is now configured in the CanvasItem, which I suppose only works for 2D. How can filtering be turned of in Godot 4?

@Zylann
Copy link
Owner

Zylann commented Oct 3, 2023

Changing the sampling mode is unfortunately more effort now, both for you and me:

The plugin requires a shader to render. The way Godot 4 expects you to do this now, is to modify the shader directly, by adding filter[_nearest, _linear][_mipmap][_anisotropic] after the uniform line corresponding to textures you want to change.
For plugin makers, that means it is not exposable as a checkbox or dropdown. It requires a different shader for every possible combination of hints and render modes you want, and so duplicate variants of every shader the plugin provides.

Because of this, the easiest for you is to fork the shader you desire and add these hints to it. You can do so by creating a new shader under the Custom Shader property (which will copy the current built-in shader as a new unique shader; or create the copy manually), and switch Shader Type to Custom.

Then for example, in classic4:

uniform sampler2D u_ground_albedo_bump_0 : source_color;
uniform sampler2D u_ground_albedo_bump_1 : source_color;
uniform sampler2D u_ground_albedo_bump_2 : source_color;
uniform sampler2D u_ground_albedo_bump_3 : source_color;
uniform sampler2D u_ground_normal_roughness_0;
uniform sampler2D u_ground_normal_roughness_1;
uniform sampler2D u_ground_normal_roughness_2;
uniform sampler2D u_ground_normal_roughness_3;

Change these lines into:

uniform sampler2D u_ground_albedo_bump_0 : source_color, filter_nearest_mipmap;
uniform sampler2D u_ground_albedo_bump_1 : source_color, filter_nearest_mipmap;
uniform sampler2D u_ground_albedo_bump_2 : source_color, filter_nearest_mipmap;
uniform sampler2D u_ground_albedo_bump_3 : source_color, filter_nearest_mipmap;

uniform sampler2D u_ground_normal_roughness_0 : filter_nearest_mipmap;
uniform sampler2D u_ground_normal_roughness_1 : filter_nearest_mipmap;
uniform sampler2D u_ground_normal_roughness_2 : filter_nearest_mipmap;
uniform sampler2D u_ground_normal_roughness_3 : filter_nearest_mipmap;

image

@manum45
Copy link

manum45 commented Oct 3, 2023

Thanks for the quick reply, this works!

@drd-dev
Copy link

drd-dev commented Jan 14, 2024

Just used this, works great!

@cessar1
Copy link

cessar1 commented Jan 19, 2024

Thanks!

@Calinou
Copy link
Contributor

Calinou commented Jan 24, 2024

The way Godot 4 expects you to do this now, is to modify the shader directly, by adding filter[_nearest, _linear][_mipmap][_anisotropic] after the uniform line corresponding to textures you want to change.

I wonder if the Godot shader language could feature filter_tweakable and repeat_tweakable that can be set to any filter mode in the inspector if at least one instance of it is present in a shader. This would be a relatively easy way of exposing filter modes in a way that doesn't require extensive changes to the shader compiler. The main difficulty would be seeing whether the hint is used at least once and displaying it in the inspector in this case. The downside is that you wouldn't be able to have multiple filter modes configurable in a single shader, but it's a rare use case in my experience.

@Zylann
Copy link
Owner

Zylann commented Jan 24, 2024

Actually if there was a way to treat #define as tweakable in shader/material properties then it would make this easier to implement, because then I could expose a specific option that translates into #define PIXELATED_TERRAIN in the ShaderMaterial, which would then account for it if it's coded using it. Basic shader variants management really, I believe there was a PR but no idea where it went. Managing shader variants in Godot isn't quite fun at the moment, I believe Terrain3D has to develop their own shader generation system as well.
If there is a place for the user to set global #defines then it could be a start, though that would only work globally and requires some clicking/typing.

@Zylann
Copy link
Owner

Zylann commented Jan 24, 2024

Actually, thinking about it, if sampler settings don't actually require a different shader under the hood (I don't recall GLSL requiring to specify that), it would be wasteful to go that route because it involves shader compilation (the choice of coupling this to shaders is purely a Godot thing?). But it would still be useful for other features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants