From 7fcd05816cf1bd9ff287139e0ee7e3a9208a16b9 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Wed, 26 Jul 2023 22:49:17 +0930 Subject: [PATCH] Update palette shader for 16x16 palettes (GLES2) --- palette_mat.tres | 2 +- .../{palette_shader.tres => palette_shader.gdshader} | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) rename shaders/{palette_shader.tres => palette_shader.gdshader} (74%) diff --git a/palette_mat.tres b/palette_mat.tres index 899f2dc..d7f53a7 100644 --- a/palette_mat.tres +++ b/palette_mat.tres @@ -1,6 +1,6 @@ [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] shader = ExtResource( 1 ) diff --git a/shaders/palette_shader.tres b/shaders/palette_shader.gdshader similarity index 74% rename from shaders/palette_shader.tres rename to shaders/palette_shader.gdshader index f37265d..096abfb 100644 --- a/shaders/palette_shader.tres +++ b/shaders/palette_shader.gdshader @@ -1,7 +1,4 @@ -[gd_resource type="Shader" format=2] - -[resource] -code = "shader_type canvas_item; +shader_type canvas_item; //uniform usampler2D tex; uniform sampler2D palette; const float index_scale = 255.0 / 16.0; @@ -14,8 +11,9 @@ void fragment() { COLOR.a = 0.0;*/ // GLES2 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) COLOR.a = 0.0; } -"