diff --git a/shaders/worldmap_shader.gdshader b/shaders/worldmap_shader.gdshader index a07d077..dc7f20e 100644 --- a/shaders/worldmap_shader.gdshader +++ b/shaders/worldmap_shader.gdshader @@ -4,16 +4,19 @@ uniform sampler2D palette : hint_normal; uniform float palette_rows = 8.0; // 128 colours // uniform float tile_width = 8.0; uniform float tilemap_width = 512.0; // Require square tilemap for now +uniform float uv_scale = 512.0; // Require square tilemap for now uniform bool enable_sea_scroll = true; // Disable on underwater maps (tileset 3) uniform bool enable_waterfall_scroll = true; // Only enable on tileset 1 +uniform bool enable_tile_globbing = false; // hack for minimap +// uniform vec2 subtile_offset = vec2(0.0); const float index_scale = 255.0 / 16.0; -const vec2 sea_tile_uv = vec2(0.125, 0.375); -const vec2 sea_tile_uv_end = vec2(0.25, 0.5); +const vec2 sea_tile_uv = vec2(2.0, 6.0)/16.0; +const vec2 sea_tile_uv_end = vec2(4.0, 8.0)/16.0; const vec2 sea_tile_size = sea_tile_uv_end - sea_tile_uv; const vec2 sea_tile_size_inv = 1.0/sea_tile_size; -const vec2 waterfall_tile_uv = vec2(7.0/16.0, 8.0/16.0); -const vec2 waterfall_tile_uv_end = vec2(9.0/16.0, 9.0/16.0); -const vec2 waterfall_tile_uv_end_hack = vec2(9.0/16.0, 10.0/16.0); // we hack a second row in the atlas +const vec2 waterfall_tile_uv = vec2(7.0, 8.0)/16.0; +const vec2 waterfall_tile_uv_end = vec2(9.0, 9.0)/16.0; +const vec2 waterfall_tile_uv_end_hack = vec2(9.0, 10.0)/16.0; // we hack a second row in the atlas const vec2 waterfall_tile_size = waterfall_tile_uv_end - waterfall_tile_uv; const vec2 waterfall_tile_size_inv = 1.0/waterfall_tile_size; @@ -26,7 +29,8 @@ vec2 get_tile_atlas_uv(float tile_id, vec2 uv) { float tile_row = trunc(tile_idx16) / 16.0; float tile_col = fract(tile_idx16); vec2 tile_uv = vec2(tile_col, tile_row); // Convert 15.9375 to vec2(0.9375==15/16, (15)/16), this should result in integer coordinates in [0,15] scaled to [0,15/16] for UV - vec2 sub_tile_uv = fract(uv * tilemap_width) / 16.0; + // vec2 sub_tile_uv = fract((uv * uv_scale) + subtile_offset) / 16.0; + vec2 sub_tile_uv = fract(uv * uv_scale) / 16.0; vec2 out_uv = tile_uv + sub_tile_uv; @@ -67,11 +71,14 @@ void fragment() { // GLES2 // vec2 uv_tile = trunc(UV * tilemap_width) / tilemap_width; vec2 uv_tile = UV; - float s = texture(TEXTURE, uv_tile).r; + if (enable_tile_globbing) { + uv_tile += step(0.5, fract(UV*0.5*uv_scale))/tilemap_width; + } + float tile_id = texture(TEXTURE, uv_tile).r; // TODO: move cycling palette to a sampler2DArray or sampler3D rather than rebinding - vec2 lut_uv = get_tile_atlas_uv(s, UV); + vec2 lut_uv = get_tile_atlas_uv(tile_id, UV); float color_id = texture(tile_atlas, lut_uv).r; float color_idx16 = color_id * index_scale; float pal_row = trunc(color_idx16) / palette_rows; diff --git a/test/worldmap_system.gd b/test/worldmap_system.gd index e82664d..945520e 100644 --- a/test/worldmap_system.gd +++ b/test/worldmap_system.gd @@ -11,31 +11,6 @@ var current_texture: Texture var minimap_mode := 0 var minimap_tween := 0.0 -#func _create_palette_and_atlas_texrects() -> void: -# for tileset in 3: -# # Debug the Atlases -# var texrect = TextureRect.new() -# texrect.rect_position.x = tileset * 256 * 2 -# texrect.rect_scale *= 16 -# texrect.texture = SpriteLoader.worldmap_palette_textures[tileset] -# map_texrects.append(texrect) -# add_child(texrect) -# texrect = TextureRect.new() -# texrect.rect_position.x = tileset * 256 * 2 -# texrect.rect_position.y = 256 -# texrect.rect_scale *= 4 -# texrect.texture = SpriteLoader.worldmap_tile_atlas_textures[tileset] -# texrect.material = pal_shader_mat.duplicate() -# texrect.material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[tileset]) -# map_texrects.append(texrect) -# add_child(texrect) -# texrect = TextureRect.new() -# texrect.rect_position.x = tileset * 256 * 2 -# texrect.rect_position.y = 768 -# texrect.rect_scale *= 4 -# texrect.texture = SpriteLoader.worldmap_tile_atlas_textures[tileset] -# map_texrects.append(texrect) -# add_child(texrect) const map_tilesets = [0, 1, 0, 2, 2] const waterfall_scrolls = [true, false, true, false, false] @@ -64,6 +39,7 @@ func _set_map(id: int) -> void: minimap.material.set_shader_param('tile_atlas', SpriteLoader.worldmap_tile_atlas_textures[tileset]) minimap.material.set_shader_param('enable_waterfall_scroll', false) minimap.material.set_shader_param('enable_sea_scroll', false) + minimap.material.set_shader_param('enable_tile_globbing', true) # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -72,8 +48,8 @@ func _ready() -> void: # _create_palette_and_atlas_texrects() self.material = worldmap_shader_mat.duplicate() minimap.material = worldmap_shader_mat.duplicate() - minimap.modulate.a8 = 0xc0 - minimap.rect_scale = Vector2(0.125, 0.125) + minimap.modulate.a8 = 192 + minimap.rect_scale = Vector2.ONE * 0.125 minimap.rect_position = Vector2(8, 168) _set_map(0) @@ -81,13 +57,18 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: self.pos = self.pos.posmod(256.0) - self.minimap_tween -= sign(minimap_tween - minimap_mode) * delta #* 0.06125 + self.minimap_tween -= sign(minimap_tween - minimap_mode) * delta / 4 self.minimap_tween = clamp(minimap_tween, 0, 1) var l = ease(minimap_tween, -3.75) -# l = minimap_tween - minimap.rect_scale = Vector2.ONE * lerp(0.125, 0.5, l) + l = minimap_tween + var minimap_scale = lerp(0.125, 0.5, l) + minimap.rect_scale = Vector2.ONE * minimap_scale minimap.rect_position = Vector2(lerp(8, 64, l), lerp(168, -8, l)) minimap.modulate.a8 = lerp(192, 240, l) +# minimap.material.set_shader_param('subtile_offset', Vector2.ONE*0/8.0) +# minimap.material.set_shader_param('uv_scale', 64 * minimap_scale) + minimap.material.set_shader_param('uv_scale', lerp(512, 1<<5, l)) +# minimap.material.set_shader_param('uv_scale', 512/16) update() var pos := Vector2(0, 0) diff --git a/worldmap_palette_mat.tres b/worldmap_palette_mat.tres index e9f369b..6bd3c2d 100644 --- a/worldmap_palette_mat.tres +++ b/worldmap_palette_mat.tres @@ -6,5 +6,7 @@ shader = ExtResource( 1 ) shader_param/palette_rows = 8.0 shader_param/tilemap_width = 512.0 +shader_param/uv_scale = 512.0 shader_param/enable_sea_scroll = true shader_param/enable_waterfall_scroll = true +shader_param/enable_tile_globbing = false