ChocolateBird/shaders/palette_shader.gdshader

20 lines
539 B
Plaintext

shader_type canvas_item;
//uniform usampler2D tex;
uniform sampler2D palette;
const float index_scale = 255.0 / 16.0;
void fragment() {
// GLES3
/*uint color_idx = uint(textureLod(TEXTURE, UV, 0.0).r * 255.0);
COLOR = texelFetch(palette, ivec2(int(color_idx), 0), 0);
if (color_idx == uint(0))
COLOR.a = 0.0;*/
// GLES2
float color_idx = texture(TEXTURE, UV).a * index_scale;
float row = trunc(color_idx) / 16.0;
float col = fract(color_idx);
COLOR = texture(palette, vec2(col, row));
if (color_idx == 0.0)
COLOR.a = 0.0;
}