From c4522ea1a3212f3dafe3c4f55de4a17228902bcf Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Tue, 25 Jul 2023 14:49:32 +0930 Subject: [PATCH] GLES2 mode --- load_sprites.gd | 6 +++--- project.godot | 1 + shaders/palette_shader.tres | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/load_sprites.gd b/load_sprites.gd index 5226521..4cdeaec 100644 --- a/load_sprites.gd +++ b/load_sprites.gd @@ -23,7 +23,6 @@ var weapon_textures = {} func texture_from_image(image: Image, flags: int = 0) -> ImageTexture: var tex = ImageTexture.new() tex.create_from_image(image, flags) - tex.flags = Texture.FLAG_CONVERT_TO_LINEAR return tex func bgr555_to_color(short: int) -> Color: @@ -46,7 +45,8 @@ func generate_palette_rgbf(rom: File, offset: int, length: int = 16) -> Image: return img func generate_palette_rgb8(rom: File, offset: int, length: int = 16) -> Image: - # Implicit sRGB -> linear conversion on ImageTexture creation from RGB8 Image ruins this + # Safe for GLES2 only! + # Implicit sRGB -> linear conversion on ImageTexture creation from RGB8 Image ruins this in GLES3 mode rom.seek(offset) var data = ByteArray(length*3) # img.lock() @@ -76,7 +76,7 @@ func generate_palette_rgb5_a1(rom: File, offset: int, length: int = 16) -> Image return img func generate_palette(rom: File, offset: int, length: int = 16) -> Image: - return generate_palette_rgb5_a1(rom, offset, length) + return generate_palette_rgb8(rom, offset, length) func ByteArray(size: int) -> PoolByteArray: var arr = PoolByteArray() diff --git a/project.godot b/project.godot index 75c6e65..d7dd57f 100644 --- a/project.godot +++ b/project.godot @@ -35,5 +35,6 @@ color=false [rendering] +quality/driver/driver_name="GLES2" environment/default_clear_color=Color( 0, 0, 0.517647, 1 ) environment/default_environment="res://default_env.tres" diff --git a/shaders/palette_shader.tres b/shaders/palette_shader.tres index 5a2441d..f37265d 100644 --- a/shaders/palette_shader.tres +++ b/shaders/palette_shader.tres @@ -3,13 +3,19 @@ [resource] code = "shader_type canvas_item; //uniform usampler2D tex; -uniform sampler2D palette: hint_normal; +uniform sampler2D palette; +const float index_scale = 255.0 / 16.0; void fragment() { - //uint color_idx = textureLod(tex, UV, 0.0).r; - uint color_idx = uint(textureLod(TEXTURE, UV, 0.0).r * 255.0); + // 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; + COLOR = texture(palette, vec2(color_idx, 0.5)); + if (color_idx == 0.0) COLOR.a = 0.0; } "