2023-07-26 22:49:17 +09:30
|
|
|
shader_type canvas_item;
|
2023-07-25 14:21:10 +09:30
|
|
|
//uniform usampler2D tex;
|
2023-07-25 14:49:32 +09:30
|
|
|
uniform sampler2D palette;
|
|
|
|
const float index_scale = 255.0 / 16.0;
|
2023-07-25 14:21:10 +09:30
|
|
|
|
|
|
|
void fragment() {
|
2023-07-25 14:49:32 +09:30
|
|
|
// GLES3
|
|
|
|
/*uint color_idx = uint(textureLod(TEXTURE, UV, 0.0).r * 255.0);
|
2023-07-25 14:21:10 +09:30
|
|
|
COLOR = texelFetch(palette, ivec2(int(color_idx), 0), 0);
|
|
|
|
if (color_idx == uint(0))
|
2023-07-25 14:49:32 +09:30
|
|
|
COLOR.a = 0.0;*/
|
|
|
|
// GLES2
|
2023-07-28 00:06:46 +09:30
|
|
|
float color_idx16 = texture(TEXTURE, UV).r * index_scale;
|
|
|
|
float row = trunc(color_idx16) / 16.0;
|
|
|
|
float col = fract(color_idx16);
|
2023-07-26 22:49:17 +09:30
|
|
|
COLOR = texture(palette, vec2(col, row));
|
2023-07-28 00:06:46 +09:30
|
|
|
COLOR.a = step(0.000001, color_idx16); // Branchless transparency
|
2023-07-25 14:21:10 +09:30
|
|
|
}
|