Parallax: In-game data consumption and rendering
The game starts by setting up the parallax sprites according to data from the level tool, and from there on, calls the .sat and .ptc stream once every frame. I use a memcopy of the SAT for easy manipulation, and just "blast" this over to the VDP early each frame. Performance numbers are further below.
To make it look good, we need to use the EC-bit. The cost of setting EC-bit on all sprites in one go, even with all data precomputed would be, at a minimum (without any calculation and routine overhead): set_vram_add_write + 26 sprites * 16 colors = 8 * OUTI + 26 * 16 * OUTI = cycles. 7560/7980 cycles.
To make it look good, we need to use the EC-bit. The cost of setting EC-bit on all sprites in one go, even with all data precomputed would be, at a minimum (without any calculation and routine overhead): set_vram_add_write + 26 sprites * 16 colors = 8 * OUTI + 26 * 16 * OUTI = cycles. 7560/7980 cycles.
- Instead I spread this over multiple frames, doing a data prep at frame 7 and an VRAM update in frame 0. The comparable VRAM update peak number becomes: 1805 cycles.
What are the drawbacks?
- Data size obviously.
- We can not change the background at runtime. For example, I made some cool chemtrails from the Wave form at some point -- that really looked stupido when the parallax showed on top.
- Palette animation is not optimal if the colors are supposed to look transparent (faked by using same color as background), like this:
- Starting a level midway is not fast, as the stream is diff-based.
- That means that we need to spin through the level frame by frame from the start. In Go Figure I try to hide this behind a "level starting" screen when nothing else is going on.
- The time it takes to spin through depends a lot on the level, but picking a sample midway measurement from the heaviest level, Blackout, we see that a midway spin of about 3000 level frames has a cost of 9042412 cycles.
- This gives a total wait of 2.5 seconds. Other titles could consider key-framing data, but one key-frame would likely cost 64kB (uncompressed), so it isn't just a no-brainer.
Cycle numbers
Final words
The amount of up-front work, as well as data amounts are really big, but the cycle costs at runtime ended up surpringsly low.The parallax effect | Design of the system | The masker tool | In-game data consumption and rendering
Comments
Post a Comment