← Pixel Dreamer Studio

Tiling textures that keep their size on any mesh

Turn on world triplanar UVs and set uv1_scale to 1 divided by the metres one tile should cover.

Switch the material to world triplanar UVs, uv1_triplanar and uv1_world_triplanar on, and set uv1_scale to 1 divided by the metres one repeat should cover. Mesh UVs always spread one texture over the whole mesh, so a bigger or scaled mesh stretches it. In our Godot 4.7 test a checker with squares 0.12 m wide on a 1 m quad became 0.50 m wide on a 4 m quad, and the same on a 1 m quad scaled 4 times. The script kept 0.12 by 0.12 on all three.

The code

Attach this to a floor, wall or any MeshInstance3D with a StandardMaterial3D, and set metres_per_tile. It copies the material for this mesh only and turns on world triplanar, so you can resize and scale the mesh freely and the texture keeps its size in metres.

extends MeshInstance3D
## Keeps a tiling texture the same size in metres however big you make this mesh or however you scale it:
## the material takes its UVs from the world position (world triplanar) instead of the mesh's own UVs.

@export var metres_per_tile := 2.0  # how many metres one repeat of the texture covers


func _ready() -> void:
	for i in mesh.get_surface_count():
		var m := get_active_material(i) as StandardMaterial3D
		if m == null:
			continue
		m = m.duplicate()  # change this mesh only, not every mesh sharing the material
		m.uv1_triplanar = true
		m.uv1_world_triplanar = true  # world position, so scale and size no longer stretch it
		m.uv1_scale = Vector3.ONE / metres_per_tile
		set_surface_override_material(i, m)

What we measured

A checker of 8 by 8 squares, unshaded, seen straight on by an orthographic camera at 90 pixels per metre. We measured the squares in the middle of the screen. Two runs gave the same sizes.

Why the texture stretches

A mesh's UVs say where each corner sits on the texture, from 0 to 1. Make the mesh bigger, or scale the node, and the corners move apart while the UVs stay the same, so the one texture is pulled over the new size. uv1_scale on its own can fix one mesh, but every mesh of another size needs its own number. World triplanar ignores the mesh's UVs and projects the texture from the world position along the X, Y and Z axes, so 1 m of floor gets the same piece of texture anywhere.

What to change

Tiling materials for floors and walls: 24 Sci-Fi PBR Materials has 24 seamless sci-fi materials as 2K PNG maps, plus a Godot 4 ready version.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: 24 Sci-Fi PBR Materials has 24 seamless sci-fi PBR materials as 2K PNG maps, plus a Godot 4 ready version.

More how-tos: Shaders, materials and lights