A Guide to the Graphics of the Sega Mega Drive / Genesis

Return to Table of Contents

Palette Swapping

Palette colors can be changed in CRAM while the VDP is in the middle of rendering a frame and then changed back at the end of the frame, a process known as mid-frame palette swapping. This raster effect results in one vertical section of the screen being drawn with one set of palettes, while another section is drawn with another set of palettes. The process can be repeated more than once per frame. This technique can be used to surpass the color limitations of the VDP, although it comes with tradeoffs.

One of the tradeoffs to mid-frame palette swapping is that artifacts will often appear on the screen. These artifacts are known as CRAM dots. Any time a color is written to CRAM while the screen is being actively rendered, that color will appear on the screen in a single pixel rather than the intended color. The more colors written to CRAM at a time, the more CRAM dots will appear. Developers often obscured these dots using sprites, as we will see in some examples below. However, sometimes CRAM dots were left as-is.

Let’s look at an example of mid-frame palette swapping from Burning Force:

Colors are swapped mid-frame several times in this scene from Burning Force.

If we map out the color palettes for each horizontal line of the display, we get this:

A representation of the color palettes in the above Burning Force example. Each column represents an entry on a color palette. A column with more than one color indicates a mid-frame color change. The vertical position where the color changes on the diagram corresponds to the vertical position of the change on the display.

The leftmost 16 columns represent the first palette. This palette is changed three times in a single frame, at the vertical positions where the colors change in the diagram. The second palette is changed twice.

Now, re-watch the above video clip and try to identify where the palettes are changed by mentally aligning the diagram with the video. The first point is just below the cockpit display at the top of the screen (just above the sky). The second point is the horizon—where the sky meets the water. The third point is just above the bottom cockpit display (just below the water). At each of these points, there are noticeable CRAM dots. This is most obvious on the scanlines where two palettes are changed at once, near the cockpit displays. Note that most emulators do not show these dots—the above video was taken from the emulator BlastEm. In the case of Burning Force, the developers did not attempt to hide the CRAM dots. The dots are not so noticeable at the horizon since there is so much animation already and the color of the CRAM dots matches the water, but they are quite jarring near the cockpit display.

If you’re curious how the scrolling water effect works in Burning Force: it’s just palette animation, done by shifting palette colors each frame on a static background plane. It’s the same method used to animate the water in the background of the first stage of Sonic the Hedgehog, but done here at 60 fps with more colors. The tiles themselves are not changing–just the color palette they reference.

An interesting effect that can be done using palette swapping is to create water that covers only the bottom of the screen; anything underwater uses a different palette, typically with a green or blue hue. This creates the illusion of partial transparency.

Gaiares features a very impressive scene with rising water, shown here:

The water in this scene from Gaiares is created using a mid-frame palette swap.

The palette swap occurs at the water line, and it gradually shifts up the screen each frame to give the appearance that the water is rising. Notice the flashing wave sprites that obscure the top of the water—these are used to hide the CRAM dots. An additional nice point to this scene is the line scrolling that occurs underwater (scrolling along a sine wave pattern) to really give the impression of water.

Another well-known example of the water effect is from Sonic the Hedgehog:

The water in this scene from Sonic the Hedgehog is also created using a mid-frame palette swap.

The effect here is similar to the one in Gaiares—there is a layer of flashing wave sprites obscuring the CRAM dots. Sonic the Hedgehog in fact came out six months after Gaiares, so Gaiares may have served as inspiration for how the effect was realized in Sonic. Interestingly, the Japanese version of Sonic, which came out a month after the North American version, featured an addition to this stage: a line scrolling sine wave ripple effect underwater.

The Japanese version of Sonic the Hedgehog featured a line scrolling ripple effect underwater.

The water effect can also be found in Castlevania: Bloodlines:

Another example of water done using a mid-frame palette swap from Castlevania: Bloodlines.

In these three examples, the background plane and sprite tiles themselves are not changing above and below the water. The only things changing are the color palettes.

Next: Vertical Scaling

Return to Table of Contents

List of Effects:
  1. Introduction
  2. Full-Screen Scrolling
  3. Row / Column Scrolling
  4. Line Scrolling
  5. Animation
  6. Multi-Jointed Characters
  7. Tilting / Rotation
  8. Scaling
  9. Shadow and Highlight
  10. Transparency
  11. Silhouette
  12. Palette Swapping
  13. Vertical Scaling
  14. Sprite Raster Effects

Want to post a comment? You can do so here.