ChocolateBird/shaders/worldmap_shader.gdshader

29 lines
967 B
Plaintext
Raw Normal View History

2023-07-27 19:38:53 +09:30
shader_type canvas_item;
uniform sampler2D tiles;
uniform sampler2D palette;
// uniform float tile_width = 8.0;
uniform float tilemap_width = 256.0; // Require square tilemap for now
const float index_scale = 255.0 / 16.0;
// This shader maps from tileID texels to Tiles, and then applies palette.
// tiles hardcoded to 16x16 tiles for now
// palette hardcoded to 16x16 colors for now
void fragment() {
// GLES2
float tile_idx = texture(TEXTURE, UV).a * index_scale;
vec2 tile_uv = vec2(fract(tile_idx), trunc(tile_idx) / 16.0);
vec2 sub_tile_uv = fract(UV / tilemap_width);
// TODO: add sea HScroll, waterfall VScroll tile UV modulation
// TODO: move cycling palette to a sampler2DArray or sampler3D rather than rebinding
float color_idx = texture(tiles, tile_uv + (sub_tile_uv/16.0)).a * index_scale;
float palette_uv = vec2(fract(color_idx), trunc(color_idx) / 16.0);
COLOR = texture(palette, palette_uv);
if (color_idx == 0.0)
COLOR.a = 0.0;
}