Atlas Region Tiled Repeat (2D)

For when you want to repeat the texture of a sprite that’s part of an atlas. When using linear filtering a little bit of the seem is visible even with the slight adjustment (seem_hiding and seem_scale) which reduces texture bleed a little.

All you need is to set your atlas as a regular texture (not an AtlasTexture) on the sprite and set up the region using the sprite region properties, then you can set the tile_factor shader parameter to adjust the tiling.

Setting the sprite’s scale and tile_factor to the same values should scale it up appropriately.

Shader code
shader_type canvas_item;

uniform vec2 tile_factor = vec2(1.0, 1.0);

void fragment() {
    vec2 tex_size = vec2(textureSize(TEXTURE, 0));
    vec2 seem_hiding = vec2(1.0/64.0) / tex_size;
    vec2 seem_scale = vec2(1.0) - seem_hiding * 2.0;
    
    vec2 tiled_pixel = mod((UV - REGION_RECT.xy) * tile_factor, REGION_RECT.zw) * seem_scale + seem_hiding;
    
    COLOR = texture(TEXTURE, (tiled_pixel + REGION_RECT.xy));
}
Tags
atlas, repeat, tile
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Cammymoop

Atlas Region Tiled Repeat (3D)

Related shaders

Atlas Region Tiled Repeat (3D)

Outline for Atlas Texture Region

Tiling / Repeat SPR

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments