some adjustments on alpha by pixel
All checks were successful
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
All checks were successful
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
This commit is contained in:
parent
ab0e577c6f
commit
38544ed3f1
@ -774,11 +774,11 @@ impl Gfx {
|
|||||||
let fetch_x = if tile.entry.flip_x() { size - 1 - local_x } else { local_x };
|
let fetch_x = if tile.entry.flip_x() { size - 1 - local_x } else { local_x };
|
||||||
let fetch_y = if tile.entry.flip_y() { size - 1 - local_y } else { local_y };
|
let fetch_y = if tile.entry.flip_y() { size - 1 - local_y } else { local_y };
|
||||||
let px_index = tile.bank.get_pixel_index(tile.entry.glyph_id, fetch_x, fetch_y);
|
let px_index = tile.bank.get_pixel_index(tile.entry.glyph_id, fetch_x, fetch_y);
|
||||||
if px_index == 0 {
|
let color = tile.bank.resolve_color(tile.entry.palette_id, px_index);
|
||||||
|
if color.alpha() == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let color = tile.bank.resolve_color(tile.entry.palette_id, px_index);
|
|
||||||
target.back[world_y as usize * target.screen_w + world_x as usize] = color.raw();
|
target.back[world_y as usize * target.screen_w + world_x as usize] = color.raw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -823,17 +823,12 @@ impl Gfx {
|
|||||||
let fetch_x = if sprite.flip_x { size - 1 - local_x } else { local_x };
|
let fetch_x = if sprite.flip_x { size - 1 - local_x } else { local_x };
|
||||||
let fetch_y = if sprite.flip_y { size - 1 - local_y } else { local_y };
|
let fetch_y = if sprite.flip_y { size - 1 - local_y } else { local_y };
|
||||||
|
|
||||||
// 1. Get index
|
|
||||||
let px_index = bank.get_pixel_index(sprite.glyph.glyph_id, fetch_x, fetch_y);
|
let px_index = bank.get_pixel_index(sprite.glyph.glyph_id, fetch_x, fetch_y);
|
||||||
|
let color = bank.resolve_color(sprite.glyph.palette_id, px_index);
|
||||||
// 2. Transparency
|
if color.alpha() == 0 {
|
||||||
if px_index == 0 {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Resolve color via palette (from the tile inside the sprite)
|
|
||||||
let color = bank.resolve_color(sprite.glyph.palette_id, px_index);
|
|
||||||
|
|
||||||
back[world_y as usize * screen_w + world_x as usize] = color.raw();
|
back[world_y as usize * screen_w + world_x as usize] = color.raw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -999,16 +994,23 @@ mod tests {
|
|||||||
use prometeu_hal::tile::Tile;
|
use prometeu_hal::tile::Tile;
|
||||||
use prometeu_hal::tilemap::TileMap;
|
use prometeu_hal::tilemap::TileMap;
|
||||||
|
|
||||||
fn make_glyph_bank(tile_size: TileSize, palette_colors: &[(u8, Color)]) -> GlyphBank {
|
fn make_glyph_bank(tile_size: TileSize, palette_colors: &[(u8, u8, Color)]) -> GlyphBank {
|
||||||
let size = tile_size as usize;
|
let size = tile_size as usize;
|
||||||
let mut bank = GlyphBank::new(tile_size, size, size);
|
let mut bank = GlyphBank::new(tile_size, size, size);
|
||||||
for (palette_id, color) in palette_colors {
|
for (palette_id, color_index, color) in palette_colors {
|
||||||
bank.palettes[*palette_id as usize][1] = *color;
|
bank.palettes[*palette_id as usize][*color_index as usize] = *color;
|
||||||
}
|
}
|
||||||
for y in 0..size {
|
bank
|
||||||
for x in 0..size {
|
}
|
||||||
bank.pixel_indices[y * bank.width + x] = 1;
|
|
||||||
}
|
fn make_filled_glyph_bank(
|
||||||
|
tile_size: TileSize,
|
||||||
|
pixel_index: u8,
|
||||||
|
palette_colors: &[(u8, u8, Color)],
|
||||||
|
) -> GlyphBank {
|
||||||
|
let mut bank = make_glyph_bank(tile_size, palette_colors);
|
||||||
|
for index in 0..bank.pixel_indices.len() {
|
||||||
|
bank.pixel_indices[index] = pixel_index;
|
||||||
}
|
}
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
@ -1094,6 +1096,90 @@ mod tests {
|
|||||||
assert_eq!(gfx.back[9 * 10 + 9], Color::WHITE.0);
|
assert_eq!(gfx.back[9 * 10 + 9], Color::WHITE.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sprite_draws_opaque_color_index_zero() {
|
||||||
|
let bank = make_filled_glyph_bank(TileSize::Size8, 0, &[(0, 0, Color::GREEN)]);
|
||||||
|
let mut back = vec![Color::BLACK.raw(); 8 * 8];
|
||||||
|
let sprite = Sprite {
|
||||||
|
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
layer: 0,
|
||||||
|
flip_x: false,
|
||||||
|
flip_y: false,
|
||||||
|
bank_id: 0,
|
||||||
|
active: true,
|
||||||
|
priority: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
Gfx::draw_sprite_pixel_by_pixel(&mut back, 8, 8, &sprite, &bank);
|
||||||
|
|
||||||
|
assert_eq!(back[0], Color::GREEN.raw());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sprite_skips_alpha_zero_color_index_zero() {
|
||||||
|
let bank = make_filled_glyph_bank(TileSize::Size8, 0, &[(0, 0, Color::TRANSPARENT)]);
|
||||||
|
let mut back = vec![Color::RED.raw(); 8 * 8];
|
||||||
|
let sprite = Sprite {
|
||||||
|
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
layer: 0,
|
||||||
|
flip_x: false,
|
||||||
|
flip_y: false,
|
||||||
|
bank_id: 0,
|
||||||
|
active: true,
|
||||||
|
priority: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
Gfx::draw_sprite_pixel_by_pixel(&mut back, 8, 8, &sprite, &bank);
|
||||||
|
|
||||||
|
assert_eq!(back[0], Color::RED.raw());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cached_tile_draws_opaque_color_index_zero() {
|
||||||
|
let bank = make_filled_glyph_bank(TileSize::Size8, 0, &[(0, 0, Color::GREEN)]);
|
||||||
|
let mut back = vec![Color::BLACK.raw(); 8 * 8];
|
||||||
|
let mut target = RenderTarget { back: &mut back, screen_w: 8, screen_h: 8 };
|
||||||
|
let entry = CachedTileEntry {
|
||||||
|
active: true,
|
||||||
|
glyph_id: 0,
|
||||||
|
palette_id: 0,
|
||||||
|
flags: 0,
|
||||||
|
glyph_asset_id: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
Gfx::draw_cached_tile_pixels(
|
||||||
|
&mut target,
|
||||||
|
CachedTileDraw { x: 0, y: 0, entry, bank: &bank, tile_size: TileSize::Size8 },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(target.back[0], Color::GREEN.raw());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cached_tile_skips_alpha_zero_color_index_zero() {
|
||||||
|
let bank = make_filled_glyph_bank(TileSize::Size8, 0, &[(0, 0, Color::TRANSPARENT)]);
|
||||||
|
let mut back = vec![Color::RED.raw(); 8 * 8];
|
||||||
|
let mut target = RenderTarget { back: &mut back, screen_w: 8, screen_h: 8 };
|
||||||
|
let entry = CachedTileEntry {
|
||||||
|
active: true,
|
||||||
|
glyph_id: 0,
|
||||||
|
palette_id: 0,
|
||||||
|
flags: 0,
|
||||||
|
glyph_asset_id: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
Gfx::draw_cached_tile_pixels(
|
||||||
|
&mut target,
|
||||||
|
CachedTileDraw { x: 0, y: 0, entry, bank: &bank, tile_size: TileSize::Size8 },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(target.back[0], Color::RED.raw());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_draw_rect() {
|
fn test_draw_rect() {
|
||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
@ -1127,7 +1213,11 @@ mod tests {
|
|||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
banks.install_glyph_bank(
|
banks.install_glyph_bank(
|
||||||
0,
|
0,
|
||||||
Arc::new(make_glyph_bank(TileSize::Size8, &[(0, Color::RED), (1, Color::GREEN)])),
|
Arc::new(make_filled_glyph_bank(
|
||||||
|
TileSize::Size8,
|
||||||
|
1,
|
||||||
|
&[(0, 1, Color::RED), (1, 1, Color::GREEN)],
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut scene = make_scene([0, 0, 0, 0]);
|
let mut scene = make_scene([0, 0, 0, 0]);
|
||||||
@ -1152,9 +1242,15 @@ mod tests {
|
|||||||
let banks = Arc::new(MemoryBanks::new());
|
let banks = Arc::new(MemoryBanks::new());
|
||||||
banks.install_glyph_bank(
|
banks.install_glyph_bank(
|
||||||
0,
|
0,
|
||||||
Arc::new(make_glyph_bank(
|
Arc::new(make_filled_glyph_bank(
|
||||||
TileSize::Size8,
|
TileSize::Size8,
|
||||||
&[(0, Color::RED), (1, Color::GREEN), (2, Color::BLUE), (4, Color::WHITE)],
|
1,
|
||||||
|
&[
|
||||||
|
(0, 1, Color::RED),
|
||||||
|
(1, 1, Color::GREEN),
|
||||||
|
(2, 1, Color::BLUE),
|
||||||
|
(4, 1, Color::WHITE),
|
||||||
|
],
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user