Thursday, May 11, 2017

Extra layers via tile replacement

Here's what the background scroll in Launch Base Zone 1 looks like: some basic parallax where the shrubbery scrolls faster than the construction towers, which in turn scroll faster than the mountains... wait a minute.


The mountains are scrolling behind the towers! How can this be possible without a third background plane?

The effect in question was previously discussed in this Sega 3D Classics interview for 3D Shinobi III. (Scroll down to "What it took to make 3-1 3D".) Essentially, as the background plane scrolls, the game directly overwrites the mountain graphics in VRAM with one of the following patterns, based on the camera's horizontal position:


Because each pattern is identical to the last, except shifted horizontally by a single pixel, running them in the opposite direction of the camera creates the illusion of an additional layer further back, scrolling at an even slower speed.

This trick was first seen in Sonic 2's Hill Top Zone, but Sonic 3 elevates it to an art form, using it in almost every stage. No more than eight separate patterns are ever needed; since tiles are 8 pixels across, switching everything one tile over ensures the proper continuation.

4 comments:

  1. I think a post about how the Mega Drive does parallax scrolling and what the limitations are would be useful for this one. "An introduction to Mega Drive graphics, part 2" covers part of it, but doesn't mention that graphics can scroll in front of other (static) graphics all within one background plane. The way the beginning of this post was written made it seem like the shrubs and towers were on different planes and I got all confused.

    ReplyDelete
    Replies
    1. Sorry if this post wasn't exactly clear. I think you're right, I should have outlined the basic parallax effect beforehand. There's a chance for me to get back to this in an upcoming post, so I'll just push that up the pipeline.

      The gist of it is, graphics *can't* scroll in front of other graphics within the same background plane. Yet everything is on one plane.

      As the camera moves horizontally, the game DMAs different images over where the mountains are. The illusion of an extra layer is created by having these images all be identical, except shifted horizontally one pixel at a time.

      Delete
    2. So if, hypothetically, the mountains weren't moving at all, the game would still need to DMA the mountain graphics to display in the gaps between the structures with each frame? I definitely think this concept deserves a post of its own, it seems my noob brain is having trouble with it.

      (Same guy as above, I've just decided to ditch the anonymity from now on)

      Delete
    3. Think of it this way: if you replaced the eight mountain patterns above with the letters A, B, C, etc, then when the camera scrolls left and right the ENTIRE mountain range would quickly flip through the letters of the alphabet.

      The mountains only look like they're moving because all the patterns look alike.

      Delete