Scroll Property Elaboration

DCurrent

Site Owner, OpenBOR Project Leader
Staff member
This is a response to @Digital Brilliance Hour's question posted in the following YouTube video. The video was originally meant as a visual aid to answer this question from @aL BeasTie.


Question from @Digital Brilliance Hour:

so this like a street fighter 2 floor?

Yes, and no. Street Fighter and other games like it are using a technique called line scrolling. This relies on a hardware interrupt that occurs each time the video unit draws one line on the screen. With carefully timed (and optimized) code, you can offset the next line more or less. This technique has a wide range of uses:
  • Creating a HUD. Just about any game you see with a designated HUD area is using line scrolling. The HUD is technically part of the background, with line scrolling used to keep it in a static position as the game scrolls. This allowed you to make complex HUD displays without eating up your sprite budget.

    1666978741617.png

  • Faking layers. Ever wonder how some games appear to have far more scrolling layers than the hardware supports? This is how it's done. When you are about to draw the next "layer", you use your interrupt code to offset the next line and create a new "layer". The limitation is that the faked layers cannot overlap, so developers would carefully design the artwork to hide this as much as possible. See Sonic The Hedgehog's first level for an example. Another great one is the second level (train) of Ninja Gaiden 2. The mountains, forest, train, tracks, and grass all scroll at different rates. Notice how there's black matte between each pseudo layer. Pay particular attention to the tracks. The rail is a solid line, and just under it is a black line, then the cross-ties. That one pixel of black gives the NES hardware time to catch its breath before needing to run more interrupt code. Then the cross-ties get their own offset, and naturally they're drawn to appear shadowed out by the train to mask the lack of overlap. It all coalesces beautifully to create an illusion of multiple scrolling layers. Oh, and as above, the HUD is a "layer" too.


  • 3D warping. Fourth gen hardware has enough juice to offset multiple lines one after another. With a bit of math to work out the rate and carefully designed artwork, you could simulate a belt scrolled area with affine transformation. This is what you see in Street Fighter 2. It's explained in detail by the lead developer of Toy Story in the video below:


    This technique is also how the SNES achieves all of its Mode 7 effects. Mode 7 on its own only scales and rotates one background layer, but you can use raster interrupts to change the scale/rotation values by line, and that's how they could build all those plane effects.
These techniques all have a very serious drawback though, especially the 3D warping transformation. Addressing this drawback was the point of my video about scroll property. I'll explain it more below.

OpenBOR does not and cannot use raster line interrupts because those are very specific to each hardware. Instead, OpenBOR applies a simple affine transformation in software, which is what the above tricks were faking anyway. The disadvantage is it's much more CPU taxing, but of course this is compensated by contemporary CPUs having adequate power to do it assuming optimal code. As the effect was originally intended for water, in OpenBOR it's called Watermode. You can apply Watermode to an fglayer, or as a drawmethod to sub-screens. The latter is insanely powerful if you know how to leverage it, and it's what enables OpenBOR to replicate any visual effect seen in any game to date.

Now the big problem. Remember, graphics and physics are two different things. All of the techniques above have to assume your objects are at static Z points, and therefore you can calculate their scroll rates in production. Ex. Street Fighter 2 can warp the floor all it wants, because the fighters are always in the same line scroll position. Same goes for platformers or games where everything is flying. In pseudo 3D environments like an OpenBOR Beat em 'up where objects are usually grounded and do move on the Z axis, this completely falls apart. Once the object changes Z position, its scroll rate won't match and it then appears completely disconnected from the background. There's only four ways to handle this:
  1. Hide it best as you can. Early racers designed their tracks and artwork to hide the scrolling dissonance, and for the most part did a good job.
  2. Design your hardware to handle it all out of the gate. This is what the Sega Super Scaler systems did, and oh man is it sweet. Power Drift from 1988 drew everything, the cars, the tracks, you name it, all using overlapped sprites in precise locations at 60FPS. The hardware to do this was (and remains) insane.


  3. F*** it, nobody will notice. This is what a lot of Super NES games did. The most egregious example I can think of is Batman Returns. Those trashcans give it away instantly.


  4. OpenBOR's Scroll property! Sort of like the Super Scaler solution, but you don't need to melt down the CPU and your sanity trying to rewrite the scrolling algorithm on every frame. Instead, you just work out some delta math to update the scroll property based on Z location, and the engine's scroll routine takes it from there. Done! You still have to do some on update calculations and planning but compared to the old days it’s brain dead simple.
The intention behind Scroll property is placing static entities into the background for adding animations or extra details. However, since it's accessible to script, you can employ the trick I outlined above, combine it with some affine transforms, and you've got yourself some slick looking sprite based 3D that would make Sega proud.

Whew... hope that explains everything!

DC
 
Last edited:
I knew what the function did, but I was curious what could really be done with it. It seemed like a small function that could be powerfully used. I was using it a little in the doom mod but merely for static objects that were animated, like burning torches.
 
Back
Top Bottom