Skip to content

Support tiling AtlasTexture in TextureRect#113808

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
kleonc:texture_rect_tiling_atlas_texture
Feb 20, 2026
Merged

Support tiling AtlasTexture in TextureRect#113808
Repiteo merged 1 commit into
godotengine:masterfrom
kleonc:texture_rect_tiling_atlas_texture

Conversation

@kleonc

@kleonc kleonc commented Dec 9, 2025

Copy link
Copy Markdown
Member

Fixes #113691.

Adds support for tiling an AtlasTexture assigned to a TextureRect by drawing it as a nine patch, which already supports tiling a texture region.

Before
v4.6.dev6.official [dec5a37]
After
this PR
vTNIzuJt0w godot windows editor dev x86_64_7Ufqyqdyz7
@arkology

Copy link
Copy Markdown
Contributor

In basic situation (without margins and atlas nesting) works great.

I don't understand how atlas margins supposed to work in this situation, so I just recorded a video.

Godot_v4.6-dev6_win64_kX5jEjY60q.mp4
@kleonc kleonc force-pushed the texture_rect_tiling_atlas_texture branch from a7b651f to f859c08 Compare December 11, 2025 11:45
@kleonc kleonc requested a review from a team as a code owner December 11, 2025 11:45
@kleonc

kleonc commented Dec 11, 2025

Copy link
Copy Markdown
Member Author

I don't understand how atlas margins supposed to work in this situation,

If properly supported, the whole atlas texture should be tiled treated as a single "unit", including the margins. Like this:

Godot_v4.5.1-stable_win64_UYYpo76D5F.mp4

Here's script drawing the above (each "tile" is a separate quad):

@tool
extends Control

@export var texture: AtlasTexture

func _process(delta: float) -> void:
	queue_redraw()

func _draw() -> void:
	var texture_size := texture.get_size()
	var drawable_area := Rect2(Vector2.ZERO, size)
	var repeat_count: Vector2i = (size / texture_size).ceil()
	for y in repeat_count.y:
		for x in repeat_count.x:
			var cell_coords := Vector2(x, y)
			var cell_rect_unclamped := Rect2(cell_coords * texture_size, texture_size)
			var cell_rect_clamped := cell_rect_unclamped.intersection(drawable_area)
			var src_rect := Rect2(Vector2.ZERO, cell_rect_clamped.size)
			draw_texture_rect_region(texture, cell_rect_clamped, src_rect)

so I just recorded a video.

Which clearly shows that margins are nor handled "as expected".

To handle the margins properly the tiling would need to be drawn either:

  • As many separate quads.
  • As a single quad, but the margins-area would need to be discarded in the fragment shader. This would require modifying the canvas shader for supporting it. But for big margins this would be inefficient (normally for AtlasTextures the margins part is not rendered at all, it's included in the texture size only logically; only the region part is actually rendered / runs the shader).

So for now I'll only add a note that tiling an AtlasTextures with margins is not supported.

In basic situation (without margins and atlas nesting) works great.

Regarding atlas nesting, note that any number of nested atlas textures (assuming no cyclic dependency, which would likely lead to crashing as it's not being prevented / checked against) can be simplified to a single combined region+margin (nesting can't result in holes etc.), aka it's equivalent to considering a single AtlasTexture. For supporting nesting only such cumulated final region needs to be calculated. Updated the PR accordingly (so nesting with no margins should work just fine).

@arkology

Copy link
Copy Markdown
Contributor

As we started deeper discussion about margins. I have 2 PRs, #101000 and #101024, where I broke my mind and gave up because of margins😄 Not sure I'll ever finish them.

Comment thread doc/classes/TextureRect.xml Outdated
@KoBeWi KoBeWi modified the milestones: 4.x, 4.7 Feb 13, 2026
Comment thread scene/gui/texture_rect.cpp Outdated
@kleonc kleonc force-pushed the texture_rect_tiling_atlas_texture branch from f859c08 to 8f77f5a Compare February 14, 2026 14:04
@kleonc kleonc requested a review from KoBeWi February 14, 2026 14:07
@kleonc kleonc force-pushed the texture_rect_tiling_atlas_texture branch from 8f77f5a to a289ee7 Compare February 14, 2026 14:22
@Repiteo Repiteo merged commit 25045e3 into godotengine:master Feb 20, 2026
20 checks passed
@Repiteo

Repiteo commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@kleonc kleonc deleted the texture_rect_tiling_atlas_texture branch February 20, 2026 20:23
ppiecuch added a commit to ppiecuch/godot that referenced this pull request Mar 15, 2026
… thorvg etc) and backport of several Godot4 enhancements

PR godotengine#90431 — --import CLI flag (editor/editor_file_system.h, main/main.cpp)
PR godotengine#113808 — AtlasTexture tiling in TextureRect (scene/gui/texture_rect.cpp, scene/gui/texture_rect.h)
PR godotengine#110925 — OBJ bump multiplier (editor/import/resource_importer_obj.cpp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment