gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Graphics > Fractional part of scrolling register for rotated/scaled BGs

#13096 - bomberman - Fri Dec 05, 2003 11:01 am

Hi there,

I'm working on a game which uses zoom feature (ratio < 1) and scrolling at the same time.
There is a problem with the zoom. Let's say I display with ratio 2/3, the scaling register will get value 384 ( = 256 *( 1/ (2 / 3)).
This means that the GBA will display only 2 pixels out of three consecutive pixels. In other words, if my bitmap sequence for a line is ABCABCABC, after scaling, it will be ABABAB. This is if scrolling register is 0. Now if I scroll one pixel to the right (scrolling register becomes 256), it will start removing a row not from point (0, 0) of the map, but from (1, 0) which is the first point displayed on the screen. So the display becomes BCBCBC. And if I scroll 2 pixels to the right (scrolling register value is 512), it will display CACACA. Result is when you scroll, everything flashes because at each new position, the removed row is not the same. Hope I was clear on this explanation !!!

I doubt that the fractional part of the scrolling register represents a fraction of pixel, it has no meaning.

What I noticed, however, is if fractional part is 0, then in case of 2/3 ratio, it removes the 3rd row in a sequence. If fractional part is 128, it removes the second row in a sequence, and if I put 256 (which in fact is a plain pixel), then I scroll one more pixel. Result is:
scroll register at 0: ABABAB
scroll register at (256 + 128): BABABA
scroll register at (512 + 256): ABABAB

My scrolling is now fine !!! I can reproduce it with a ratio like 4/5 with using fractional part of 64, 128, 192, 256 depending on my (scrolling register % 5), i.e for a bitmap sequence like ABCDE, I'll have:
scroll register at 0: ABCDABCD
scroll register at (256 + 64): BCDABCDA
scroll register at (512 + 128): CDABCDAB
scroll register at (768 + 192): DABCDABC
scroll register at (1024 + 256): ABCDABCD

In short, it seems that rather than being a fraction of pixel, the fractional part of the register controls which rows are to be removed. With simple cases like that it works fine. My intuition tells me that I am on the right path, but I can not figure out what is the exact schema in a generic case like a "non standard" ratio of 4/7 for example.

Anyone has a clue or already experimented this ???

Thanks

#13098 - tepples - Fri Dec 05, 2003 3:21 pm

What you're seeing is the harsh aliasing of nearest-neighbor downsampling. The "fractional" part of the rot/scale translation registers (BG2X, BG2Y, BG3X, BG3Y) becomes more useful as you zoom in. Try writing 192 to the scaling registers and seeing how it scrolls, and you'll understand why it's called "fractional." If you're going to be staying zoomed out for a while, try blurring your texture tiles.

To work out the general schema for say 4/7, try adding 0, ceil(256/7), ceil(256*2/7), ceil(256*3/7), ceil(256*4/7), ceil(256*5/7), ceil(256*6/7).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#13103 - bomberman - Fri Dec 05, 2003 5:00 pm

Quote:

To work out the general schema for say 4/7, try adding 0, ceil(256/7), ceil(256*2/7), ceil(256*3/7), ceil(256*4/7), ceil(256*5/7), ceil(256*6/7).


This is the schema I use for a ratio of (n-1)/n. So it would work for 6/7. Adding ceil(256+i/n), 0 <= i <= n works only for a ratio of (n-1)/n. In case of p/n with p < n, this does not work anymore and we need another pattern :O(