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.
- A 1 by 1 m quad, normal UVs: squares 11 by 11 px, 0.12 by 0.12 m.
- A 4 by 1 m quad, its
sizechanged: 45 by 11 px, 0.50 by 0.12 m. Stretched 4 times across. - A 1 by 1 m quad with the node's
scaleat 4 across: 45 by 11 px, the same stretch. - The script with
metres_per_tile1: 11 by 11 px on all three.
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
metres_per_tile: bigger for a coarser pattern. Match it to the real size the texture was made for, such as 2 m for a floor panel.- World UVs belong to the world, not to the mesh, so this suits floors, walls and other level geometry.
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
- 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
- Scroll or tile a 2D texture without stretched edge lines
- 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
- 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