uniform sampler2D texture is hazy/pixelated compared to original texture

Godot Version

4.4

Question

I’ve got a PNG that is 1920x1080 and imported into my project. Project settings / Rendering / Default Texture Filter is set to Nearest.

I create a Sprite2D and set its’ texture to my texture and it looks perfect.

Now add a shader material & shader code to that Sprite2D with a texture as a uniform that has my texture loaded into it.

The following shader code results in 2 different images depending on which texture I sample, the core sprite texture or the parameter being passed in:

shader_type canvas_item;
uniform sampler2D pattern: filter_nearest;

void fragment() {

  • // this line looks perfect, crisp and clear*

  • COLOR = texture(TEXTURE, UV);*

  • // this line has a haziness to it and has developed some pixelation*

  • COLOR = texture(pattern, UV);*
    }

Any thoughts on what might be causing the texture to be sampled differently if it’s a parameter versus being assigned directly to the sprite?

Thanks!

Try setting the source_color hint to the sampler2D uniform.

1 Like

What’s the actual imported textures own filtering? I suspect the shader hint is not there to control the filtering, but to guide other aspects of the shaders operation. Can’t find the documentation on what the hints do exactly, anyways.

Yep, that did the trick! Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.