Godot 4 Texture Repeat for shader sampler2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rakkarage
shader_type canvas_item;
uniform sampler2D noise;
void fragment() {
	vec2 uv = vec2(UV.x + TIME, UV.y);
	COLOR.rgba = texture(TEXTURE, uv).rgba;
}

Here is some very simple shader code that causes the texture to scroll. But it does not work when I pass in my own texture unless I stop animation. Which makes me think it has something to do with texture repeating and sampler2D? Because repeating needs to be enabled to use time in shader? idk

Does anyone know how to make this work in 4? some kinda sampler2d repeat hint? or idk? Maybe a bug? But someone must have got this working by now?

Please and thanks.

enter image description here

ViewportTexture repeat flag has no effect #36820
ViewportTexture repeat flag has no effect · Issue #36820 · godotengine/godot · GitHub

maybe related?

rakkarage | 2022-02-17 03:51

:bust_in_silhouette: Reply From: Andrea

i’m no expert of shader, but isnt the UV supposed to be between 1 and 0?
I suppose your code works in a repeated texture because somehow the UV.x>1 is going to look at the texture “on the right”, but it a normal texture it caps the values at 1.

If you notice, for every UV.x>1, it consider UV.x=1. In fact the resulting picture became equivalent to the right border of the original picture

thanks. ya i guess that is why repeat is needed.

rakkarage | 2022-02-17 15:51

:bust_in_silhouette: Reply From: rakkarage

some kinda sampler2d repeat hint?

uniform sampler2D noise: filter_nearest, repeat_enable;