← Pixel Dreamer Studio

Find and fix the seam in a repeating texture

Compare the pixels that meet when the texture repeats with the pixels next to each other inside it.

A scrolling energy, fire or distortion shader repeats its noise texture, and if the right edge does not continue into the left edge, a line runs across the effect where they meet. It is hard to see in the texture itself and easy to see when it moves. The script below measures it: how much the pixels change across the edge where the texture repeats, divided by how much they change between neighbours inside it. In our Godot 4.7 test a NoiseTexture2D with seamless off scored 9.46 left to right and 7.23 top to bottom, and 28 to 34 at a lower frequency. With seamless on: 0.93 and 1.01. A square cut out of the middle of a bigger noise image, a common way to make one by hand, scored 11.17.

The code

Save it as seam_check.gd and load it with const Seam := preload("res://seam_check.gd"). Then print(Seam.check(preload("res://textures/energy_noise.png"))) prints two numbers, left_right and top_bottom. Near 1 means the edges continue like the rest of the texture. Several times higher means a seam. For a NoiseTexture2D, wait for its changed signal before checking, because the image is made in the background.

extends RefCounted
## Check whether a texture repeats without a seam. It compares the pixels that meet when the
## texture repeats (last column with the first, last row with the first) with neighbouring
## pixels inside the texture.
##   const Seam := preload("res://seam_check.gd")
##   print(Seam.check(preload("res://textures/energy_noise.png")))
## A ratio near 1 repeats cleanly. Well above 1, a line shows where the texture repeats or scrolls.


static func check(tex: Texture2D) -> Dictionary:
	var img := tex.get_image()
	if img.is_compressed():
		img.decompress()
	var w := img.get_width()
	var h := img.get_height()
	var inside := 0.0
	for y in h:
		for x in range(w - 1):
			inside += _diff(img.get_pixel(x, y), img.get_pixel(x + 1, y))
	var step := inside / float(h * (w - 1))  # the usual change from one pixel to the next
	var across_x := 0.0
	for y in h:
		across_x += _diff(img.get_pixel(w - 1, y), img.get_pixel(0, y))
	var across_y := 0.0
	for x in w:
		across_y += _diff(img.get_pixel(x, h - 1), img.get_pixel(x, 0))
	return {
		"left_right": snappedf(across_x / h / maxf(step, 0.00001), 0.01),
		"top_bottom": snappedf(across_y / w / maxf(step, 0.00001), 0.01),
	}


static func _diff(a: Color, b: Color) -> float:
	return (absf(a.r - b.r) + absf(a.g - b.g) + absf(a.b - b.b)) / 3.0

What we measured

NoiseTexture2D, 256 by 256, FastNoiseLite seed 7, checked with the script. Two runs gave the same numbers.

Why it happens

When a texture repeats, its last column is drawn right next to its first. Noise is smooth from one pixel to the next, but the two edges of a normal noise image come from places far apart in the noise, so they do not match. The smoother the noise, the smaller the change between neighbours and the more the jump at the edge stands out, which is why the lower frequency scored higher. With seamless on, Godot makes the noise wrap around so the edges meet. Cutting a square from a bigger image does not help, its edges still come from different places.

What to change

Ready-made textures that tile: 60 VFX Textures has 20 seamless noise textures to scroll for energy, dissolves and distortion, plus 26 shape masks and 14 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