How to set texture sampling filter without using Texture2DParameter

Godot Version

4.2.1.stable

Question

Hello, I’ve been trying to make a VisualShader that creates seamless textures by mixing two texture images and using noise for the weight. It all works perfectly, only that I also need the final texture to have a “nearest” sampling filter so it looks pixelated.

The only way I’ve found so far is by setting the Texture2Ds to be SamplerPorts, taking in a Texture2DParameter that takes in the texture image as a parameter. But I’d like to not have to manually insert the texture file parameter from outside the shader, and instead just have it hardcoded from within it instead, since I’ll be making plenty of these as unique shaders for different materials.

So in other words: how can I have the equivalent of a Texture2D (Texture) node that lets me change its sampling filter? Or alternatively, how to set the sampling filter of the entire final texture?

Hey umm, I am running into a problem of my own, can you tell me how to give the texture2dparameter a texture?

nevermind I figured it out using your way, I am yet to find how to do it the way u asked tho, I’ll look around


For setting the filter, we need to be able to add, for e.g. filter_nearest in the sampler2D’s declaration like this:uniform sampler2D tex_frg_2: filter_nearest. But there is no way of doing that through visual shader, so the answer is NO, you can’t set the filter for Texture2D node from visual shader itself, its necessary to use the Tex2D’s sampler2D port for that

When you setup a uniform sampler, this is equivalent to a texture2dparam

When you use texture 2d you are calling a function.

1 Like

OP was asking if there is a way to set the filter in the Texture2D node itself, which is not possible as of 4.3.

Right, but it never has been, it has always been with the declaration of the uniform sampler2D hint variable. Texture2d visual node is a function.

Oh so Texture2D is just the texture() function from gdshader syntax? But why would the devs give the “Texture” option, it is unnecessarily confusing since you have to inject a sampler2D anyway😐I think it should be removed

1 Like

All visual shader is, is a wrapper to gdshader syntax. The visual shader is compiled into a gdshader at the end of the day.

Although I would say it is confusingly named they should have kept it closer to gdshader naming, but both spatial and canvas shaders exist in the same source file.

Here is the source for all visual shader node gdshader represention. It’s a little abstracted but there is a class per node, and enough context to see what each node represents.

1 Like