GLES2 mode

This commit is contained in:
Luke Hubmayer-Werner 2023-07-25 14:49:32 +09:30
parent fb336cc69a
commit c4522ea1a3
3 changed files with 13 additions and 6 deletions

View File

@ -23,7 +23,6 @@ var weapon_textures = {}
func texture_from_image(image: Image, flags: int = 0) -> ImageTexture: func texture_from_image(image: Image, flags: int = 0) -> ImageTexture:
var tex = ImageTexture.new() var tex = ImageTexture.new()
tex.create_from_image(image, flags) tex.create_from_image(image, flags)
tex.flags = Texture.FLAG_CONVERT_TO_LINEAR
return tex return tex
func bgr555_to_color(short: int) -> Color: 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 return img
func generate_palette_rgb8(rom: File, offset: int, length: int = 16) -> Image: 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) rom.seek(offset)
var data = ByteArray(length*3) var data = ByteArray(length*3)
# img.lock() # img.lock()
@ -76,7 +76,7 @@ func generate_palette_rgb5_a1(rom: File, offset: int, length: int = 16) -> Image
return img return img
func generate_palette(rom: File, offset: int, length: int = 16) -> Image: 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: func ByteArray(size: int) -> PoolByteArray:
var arr = PoolByteArray() var arr = PoolByteArray()

View File

@ -35,5 +35,6 @@ color=false
[rendering] [rendering]
quality/driver/driver_name="GLES2"
environment/default_clear_color=Color( 0, 0, 0.517647, 1 ) environment/default_clear_color=Color( 0, 0, 0.517647, 1 )
environment/default_environment="res://default_env.tres" environment/default_environment="res://default_env.tres"

View File

@ -3,13 +3,19 @@
[resource] [resource]
code = "shader_type canvas_item; code = "shader_type canvas_item;
//uniform usampler2D tex; //uniform usampler2D tex;
uniform sampler2D palette: hint_normal; uniform sampler2D palette;
const float index_scale = 255.0 / 16.0;
void fragment() { void fragment() {
//uint color_idx = textureLod(tex, UV, 0.0).r; // GLES3
uint color_idx = uint(textureLod(TEXTURE, UV, 0.0).r * 255.0); /*uint color_idx = uint(textureLod(TEXTURE, UV, 0.0).r * 255.0);
COLOR = texelFetch(palette, ivec2(int(color_idx), 0), 0); COLOR = texelFetch(palette, ivec2(int(color_idx), 0), 0);
if (color_idx == uint(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; COLOR.a = 0.0;
} }
" "