Tile UVs

gdshaderinc function for getting 0 to 1 UVs for a single tile from a TileSet

Shader code
#ifndef TILE_UVS
#define TILE_UVS

vec2 get_tile_uvs(vec2 p_uv,vec2 p_tex_size,vec2 p_region_size,vec2 p_margins,vec2 p_separation) {
	vec2 uv = p_uv - p_margins / p_tex_size;
	uv = fract(uv * p_tex_size / (p_region_size+p_separation));
	return uv * (p_region_size + p_separation) / p_region_size;
gdshaderinc, tilemap, tileset
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from award

Barycentric Hexagon

Related shaders

screen tile shader

Tile Map

Tile Based Triangles & Rects

Notify of

Inline Feedbacks
View all comments