21 lines
699 B
Plaintext
21 lines
699 B
Plaintext
shader_type canvas_item;
|
|
uniform sampler2D glyph_atlas : hint_normal;
|
|
uniform vec2 tilemap_size = vec2(32.0, 20.0); // Update this to match the texture size
|
|
|
|
// tile_atlas hardcoded to 64x4 tiles for now
|
|
|
|
void fragment() {
|
|
// GLES2
|
|
vec2 xy = UV * tilemap_size; // Texel-space coord of our texture
|
|
float t = texture(TEXTURE, UV).r;
|
|
int tile_idx = int(t * 255.0); // Luminosity channel (any RGB channel works)
|
|
// Convert tile_idx to a texel coordinate, then to a UV coordinate
|
|
ivec2 tile_xy = ivec2(tile_idx%64, tile_idx/64);
|
|
vec2 tile_uv = vec2(tile_xy)/64.0;
|
|
// Get sub-tile UV
|
|
vec2 sub_tile_uv = fract(xy);
|
|
vec2 uv = tile_uv + (sub_tile_uv/64.0);
|
|
|
|
COLOR = texture(glyph_atlas, uv);
|
|
}
|