Update palette shader for 16x16 palettes (GLES2)

This commit is contained in:
Luke Hubmayer-Werner 2023-07-26 22:49:17 +09:30
parent cb7f292e17
commit 7fcd05816c
2 changed files with 5 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=2] [gd_resource type="ShaderMaterial" load_steps=2 format=2]
[ext_resource path="res://shaders/palette_shader.tres" type="Shader" id=1] [ext_resource path="res://shaders/palette_shader.gdshader" type="Shader" id=1]
[resource] [resource]
shader = ExtResource( 1 ) shader = ExtResource( 1 )

View File

@ -1,7 +1,4 @@
[gd_resource type="Shader" format=2] shader_type canvas_item;
[resource]
code = "shader_type canvas_item;
//uniform usampler2D tex; //uniform usampler2D tex;
uniform sampler2D palette; uniform sampler2D palette;
const float index_scale = 255.0 / 16.0; const float index_scale = 255.0 / 16.0;
@ -14,8 +11,9 @@ void fragment() {
COLOR.a = 0.0;*/ COLOR.a = 0.0;*/
// GLES2 // GLES2
float color_idx = texture(TEXTURE, UV).a * index_scale; float color_idx = texture(TEXTURE, UV).a * index_scale;
COLOR = texture(palette, vec2(color_idx, 0.5)); float row = trunc(color_idx) / 16.0;
float col = fract(color_idx);
COLOR = texture(palette, vec2(col, row));
if (color_idx == 0.0) if (color_idx == 0.0)
COLOR.a = 0.0; COLOR.a = 0.0;
} }
"