Sampler2d in a shader doesn't respect filtering options

Godot Version

4.3

Question

I am creating a tilemap system that can render large seamless textures to subsets of tiles. To do this, I’m using a chroma key shader applied to a tilemap object, that replaces all the pixels of a certain color with a texture2d passed into the shader via a sampler2d object. It works great, and renders the image overlaying the tiles perfectly, except for one problem. The filtering option for texture2d is set to “linear” by default, and i want it to be “nearest”, i.e. no filter. I have set the default canvas texture option to “nearest” in project settings, and this seems to work for just popping in the image as a sprite, but the shader still seems to be using the linear filtered one no matter what I do.

In Unity you can just set the filtering options per-texture, and I’m not sure how to do that in godot or why that wouldn’t be an option. Any ideas? Thanks!

Can you post your shader? Typically you can set the filtering on the sampler2D using the filter_ hints (see Shading language — Godot Engine (stable) documentation in English).

1 Like

Yes! Here it is:

1 Like

Yeah, try

uniform sampler2D overlay_texture : filter_nearest;
1 Like

My savior! Thank you. That’s super clean and easy!

1 Like

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