Tile Map

A tile map shader emulating array uniform functionality that enables “constant” performance scaling regardless of tilemap size.

Shader code
shader_type canvas_item;

uniform float txr_width;
uniform float txr_height;
uniform float tile_width;
uniform float tile_height;
uniform float tile_count;

void fragment() {
	vec2 txr_size = vec2(txr_width, txr_height);
	COLOR = texture(TEXTURE,
		(mod(UV * txr_size, 1) * tile_width // offset
		+ vec2(floor(texture(TEXTURE, UV).r * tile_count) * tile_width., txr_height - tile_height) // map
		/ txr_size // normalize
	);
}
Live Preview
Tags
tile, tile map
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.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments