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;
}
#endif