Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Best way to composite two 4bpp planar tiles?

Reply to topic
Author Message
  • Joined: 23 Aug 2009
  • Posts: 68
  • Location: Seattle, WA
Reply with quote
Best way to composite two 4bpp planar tiles?
Post Posted: Wed Sep 25, 2019 5:33 pm
This question is similar to how games like Golden Axe do "sprites" by compositing graphics data into BG tiles.

I'm looking for a method to take two arbitrary tiles A and B and composite them such that the opaque pixels from tile B overwrite those on tile A. This could be a blit being done to RAM or back to VRAM.

This is pretty straightforward if the color data of tile B is linear (i.e., not split into bitplanes): run through tile B's pixel data, and any pixel that's not the transparent color gets written to its corresponding location on tile A.

Where I'm stuck is doing this quickly on 4bpp bitplane tiles, like you'd get if you arbitrarily read tile data from VRAM.

It's easy if you're doing a regular operation like OR/AND/XOR, but tougher once transparency gets into the mix.

Here are some approaches I've considered:

1. I could transform the bitplanes of tile B into a linear stream, but this feels inefficient.

2. I could create a 1bpp transparency mask that goes along with the graphics data, but that's extra data to be maintained or generated.

3. I could pull the 4 bits of each pixel from each bitplane byte and compare them to the transparency color, but that seems slow and painful. You're either doing a lot of increments/decrements to a 16-bit register pair or using slow index registers to rotate the bits out of each pixel.

Any suggestions?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12917
  • Location: London
Reply with quote
Post Posted: Wed Sep 25, 2019 6:15 pm
I think the mask is the only way. If colour 0 is the transparent one then you can OR the bitplanes together to make the mask, but it seems a false economy to do that to save 8 bytes of ROM. Do you also want to place things with pixel precision?

One approach is to use sprites for the transparent tiles and background tiles for the rest. This is what Phantasy Star does for its enemies, but you still have difficulty with the sprite limit at the top and bottom edges unless you're creative with the artwork.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2507
Reply with quote
Post Posted: Thu Sep 26, 2019 2:46 pm
if you mean tile B *aligned* on top of tile A then it's kind of 'easier', otherwise you're probably going to create non-planar data and compare those pixel by pixel, then derive planar data.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Aug 2009
  • Posts: 68
  • Location: Seattle, WA
Reply with quote
Post Posted: Thu Sep 26, 2019 6:59 pm
The intent was a “perfect” alignment, which does simplify things. Having a transparency map riding sidecar is probably the easiest, and it’s easy to generate at runtime if need-be.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!