Set the node's texture_repeat to Enabled, in the Inspector under CanvasItem > Texture > Repeat. A new 2D node is set to Inherit and the project default is Disabled, so every UV past 1.0 reads the texture's last column. In our Godot 4.7 test a Sprite2D whose shader added 0.5 to UV.x showed that one color over 136 of its 256 pixels. With repeat enabled the second half showed the start of the texture again. A Sprite2D region 4 times as wide as its texture broke the same way, 194 of 256 pixels, while a TextureRect in Tile mode tiled correctly either way.
The code
Put it on a Sprite2D with a seamless texture and set speed in texture widths per second. It turns repeat on, adds a small scrolling shader and keeps the offset between 0 and 1, so the number never grows: 5 seconds at 0.25 left it at about 0.25, not 1.25. The shader draws the texture as it is, so it ignores the node's Modulate.
extends Sprite2D
## A 2D sprite whose texture scrolls forever. texture_repeat has to be Enabled:
## the 2D default clamps every UV past 1.0 to the edge pixel, so half the sprite turns into one smeared color.
@export var speed := Vector2(0.25, 0.0) # texture widths per second
var offset_uv := Vector2.ZERO
func _ready() -> void:
texture_repeat = CanvasItem.TEXTURE_REPEAT_ENABLED
var shader := Shader.new()
shader.code = """shader_type canvas_item;
uniform vec2 offset_uv;
void fragment() {
COLOR = texture(TEXTURE, UV + offset_uv);
}
"""
var mat := ShaderMaterial.new()
mat.shader = shader
material = mat
func _process(delta: float) -> void:
offset_uv = (offset_uv + speed * delta).posmod(1.0) # stays small, so it never loses precision
(material as ShaderMaterial).set_shader_parameter("offset_uv", offset_uv)
What we measured
A 64 by 8 texture with red rising from 0 to 255 from left to right, drawn 256 pixels wide with nearest filtering, in the Compatibility renderer. We counted the pixels across the middle that showed red 255, the last column, and read the red at 8 points from left to right. Two runs gave the same numbers.
- The shader with UV + 0.5 and repeat left at its default: 136 of 256 pixels at the edge color. The 8 points read 145, 178, 210, 242, then 255 four times.
- The same with Repeat Enabled: 8 pixels, the texture's last two columns where they belong. The 8 points read 145, 178, 210, 242, 16, 48, 80, 113: the texture started over.
- A Sprite2D with Region on, 256 pixels wide on the 64 pixel texture, repeat at its default: 194 of 256, the texture once and then its edge. With Repeat Enabled: 8, the texture 4 times.
- A TextureRect 256 wide in Tile mode: the texture 4 times with repeat at its default and with it enabled alike.
- A shader that read its own sampler2D uniform marked repeat_enable, on a node left at its default: 136 of 256, the same as no repeat at all. In our test the hint did not help and the node setting did.
- texture_repeat on a new Sprite2D was 0, Inherit, and 2, Enabled, after the script ran. The project setting rendering/textures/canvas_textures/default_texture_repeat was 0, Disabled.
Why it happens
Whether a texture repeats is decided by the node that draws it, not by the texture file. A 2D node set to Inherit takes the setting from above it, and at the top that is the project default, Disabled. With repeat off, a UV of 1.3 reads the same column as 1.0, so everything past the edge becomes the last column stretched out. A TextureRect in Tile mode tiled fine either way in our test, which is why the problem tends to show up with shaders and sprite regions.
What to change
- A scroll that jumps once an hour is a different problem: shader TIME wraps every 3600 seconds.
- Black gaps between parallax layers instead of stretched lines: Parallax2D repeat_times.
Textures made to scroll: 60 VFX Textures has 20 noise textures, 2048 px, that tile seamlessly in both directions, for flowing energy, dissolves and distortion, plus 26 shape masks and 14 8x8 flipbooks.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: 60 VFX Textures has 20 seamless noise textures to scroll for energy, dissolves and distortion, plus 26 shape masks and 14 flipbooks.
More how-tos: Shaders, materials and lights
- A 3D outline that stays the same width on screen
- Find and fix the seam in a repeating texture
- PS1 vertex wobble that is the same near and far
- Snow that stays on the roofs
- Packed ORM maps on a StandardMaterial3D
- Neon signs that share a material but not a colour
- A MatCap that stays the right way up from every side
- Keep floors, roads and roofs sharp when the camera looks along them
- Make WorldEnvironment color grading apply to a 2D game
- Get a hard cel-shaded light edge from StandardMaterial3D's Toon mode
- Make metallic materials stop looking black or flat
- Make a glowing sign or screen actually light the wall around it
- Use a LUT strip for color grading in Godot 4
- Tiling textures that keep their size on any mesh
- A sharp low-resolution PS1 look
- Only 8 lights show on a long wall in Compatibility
- Hit flash shader for 2D sprites
- Flash a 3D enemy white when it takes a hit
- Dissolve shader for 3D models
- 2D outline shader that is not cut off
- 3D outline shader without gaps at the corners
- A force field shield with a hit ripple
- Normal map inverted: DirectX vs OpenGL
- Full-screen post-process shader in 3D
- Scroll a shader texture for hours without the once-an-hour jump