Basic waterfall scroll

This commit is contained in:
Luke Hubmayer-Werner 2023-07-28 18:03:37 +09:30
parent 544ca5be0b
commit 05571c3adb
3 changed files with 25 additions and 2 deletions

View File

@ -233,6 +233,9 @@ func snes_load_worldmap(rom: File):
image = snes_mode7_compressed_to_tile(tiledata, tile_palettes[tile]) image = snes_mode7_compressed_to_tile(tiledata, tile_palettes[tile])
tile_images.append(image) tile_images.append(image)
# tile_textures.append(texture_from_image(image)) # tile_textures.append(texture_from_image(image))
if world_ts == 0: # Waterfall hack: lay it out vertically, pushing out dummy tiles
tile_images[0x97] = tile_images[0x88]
tile_images[0x98] = tile_images[0x87]
worldmap_tile_individual_imgs.append(tile_images) worldmap_tile_individual_imgs.append(tile_images)
worldmap_tile_atlas_textures.append(texture_from_image(make_tile_atlas(tile_images))) worldmap_tile_atlas_textures.append(texture_from_image(make_tile_atlas(tile_images)))

View File

@ -3,11 +3,18 @@ uniform sampler2D tile_atlas : hint_normal;
uniform sampler2D palette : hint_normal; uniform sampler2D palette : hint_normal;
// uniform float tile_width = 8.0; // uniform float tile_width = 8.0;
uniform float tilemap_width = 512.0; // Require square tilemap for now uniform float tilemap_width = 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
const float index_scale = 255.0 / 16.0; const float index_scale = 255.0 / 16.0;
const vec2 sea_tile_uv = vec2(0.125, 0.375); 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_end = vec2(0.25, 0.5);
const vec2 sea_tile_size = sea_tile_uv_end - sea_tile_uv; 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 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_size = waterfall_tile_uv_end - waterfall_tile_uv;
const vec2 waterfall_tile_size_inv = 1.0/waterfall_tile_size;
// This shader maps from tileID texels to Tiles, and then applies palette. // This shader maps from tileID texels to Tiles, and then applies palette.
// tiles hardcoded to 16x16 tiles for now // tiles hardcoded to 16x16 tiles for now
@ -24,7 +31,7 @@ vec2 get_tile_atlas_uv(float tile_id, vec2 uv) {
// Sea HScroll tile UV modulation // Sea HScroll tile UV modulation
// Make this branchless later // Make this branchless later
if (all(greaterThanEqual(out_uv, sea_tile_uv)) && all(lessThan(out_uv, sea_tile_uv_end))) { if (enable_sea_scroll && all(greaterThanEqual(out_uv, sea_tile_uv)) && all(lessThan(out_uv, sea_tile_uv_end))) {
vec2 sea_tile_uv_diff = out_uv - sea_tile_uv; vec2 sea_tile_uv_diff = out_uv - sea_tile_uv;
vec2 pos = sea_tile_uv_diff * sea_tile_size_inv; vec2 pos = sea_tile_uv_diff * sea_tile_size_inv;
// Silly warpy effects // Silly warpy effects
@ -39,7 +46,18 @@ vec2 get_tile_atlas_uv(float tile_id, vec2 uv) {
pos.x = fract(pos.x - TIME/4.267 + (pos.y * (9.0/16.0))); pos.x = fract(pos.x - TIME/4.267 + (pos.y * (9.0/16.0)));
out_uv = mix(sea_tile_uv, sea_tile_uv_end, pos); out_uv = mix(sea_tile_uv, sea_tile_uv_end, pos);
} }
// TODO: waterfall VScroll UV modulation // Waterfall VScroll UV modulation
// This has a super annoying property of being a 2tall tile scroll laid out horizontally
// In sprite_loader we hack the atlas such that we can just vscroll each one
if (enable_waterfall_scroll && all(greaterThanEqual(out_uv, waterfall_tile_uv)) && all(lessThan(out_uv, waterfall_tile_uv_end))) {
vec2 waterfall_tile_uv_diff = out_uv - waterfall_tile_uv;
vec2 pos = waterfall_tile_uv_diff * waterfall_tile_size_inv;
// Real animation seems to scroll in a cycle of shift col 1px, next frame, shift col 1px, next frame, increment by 4 rows twice, shift that one, repeat
// 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8
// For now, don't bother about the double increment
pos.y = fract((pos.y - TIME*1.3 + (pos.x * (4.5/32.0))) * 0.5);
out_uv = mix(waterfall_tile_uv, waterfall_tile_uv_end_hack, pos);
}
return out_uv; return out_uv;
} }

View File

@ -5,3 +5,5 @@
[resource] [resource]
shader = ExtResource( 1 ) shader = ExtResource( 1 )
shader_param/tilemap_width = 512.0 shader_param/tilemap_width = 512.0
shader_param/enable_sea_scroll = true
shader_param/enable_waterfall_scroll = true