PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Realtime scaling using bilerp

Hello,

For my game, I would like to improve the visual quality by reducing a 400x300 game screen to 240x320, using bilinear filtering. The source bitmap is 16bpp (using PHal). There are some obvious optimizations possible for this scenario: The bilinear weight factors are the same each frame for individual columns and rows.

My question is: Does anyone have some code for this handy (perhaps one the emu authors), preferably in fast ARM/XScale assembly?

I want to make this optional in my game, but still it would be nice if an (overclocked) iPaq 1915 would be able to use this at 20fps or more.

BTW Nutcracker 2005 is still coming along nicely, the large slowdown in development is caused by a graphic artist that joined the 'team'. He's redoing all graphics and working on level design. You won't be disappointed, the game is going to be awesome. :)

- Jacco.
I have nothing pre-coded but as always, post it in C and I'll do it in ARM for you. (I finally have an XScale device and I want to play with pre-loading anyway ;) ).
joshbu [MSFT] · 10 Oct 2005, 20:58 UTC
FYI: There are several non 4x3 devices coming to market. I;m not sure if you care or not, but the downsample isn't going to look very good if the aspect ratios don't match.

Also, there are several HIDPI devices en-route as well, which would work out to a blocky looking upsample, probably.
Hmm I tried it with some quick and dirty code in my windows emulated version (no speed issues there), and the result is not as good as I hoped. Problem is that I am scaling from 400x300 to 320x240, which means that only a few rows/columns are omitted. This gives a nasty popping effect when scrolling (made worse by the art: There are many thin bright lines in the tiles). I'll have to render to a larger bitmap (480x360 or so) or I'll skip this idea...

BTW I also tried semi-HDR with a nice bloom filter. That does help a bit as it blurs the bright lines slightly. :)
Phantom wrote:
BTW I also tried semi-HDR with a nice bloom filter. That does help a bit as it blurs the bright lines slightly. :)


Hey, I would be interested by your bloom filter, do you think it can be applied without killing the framerate ?
Phantom wrote:Hmm I tried it with some quick and dirty code in my windows emulated version (no speed issues there), and the result is not as good as I hoped. Problem is that I am scaling from 400x300 to 320x240, which means that only a few rows/columns are omitted. This gives a nasty popping effect when scrolling (made worse by the art: There are many thin bright lines in the tiles). I'll have to render to a larger bitmap (480x360 or so) or I'll skip this idea...

BTW I also tried semi-HDR with a nice bloom filter. That does help a bit as it blurs the bright lines slightly. :)


Hi Phantom, if you are doing the bilin correctly and using a float/fixed value for your scrolling you shouldn't see any popping as you describe. My guess is probably your scroll target is based on an integer value? If so smooth it over X seconds and make it a float, then feed this into your bilin routine and it should scroll smooth.

You should only see the popping if you are doing a nearest pixel resize, so something must be wrong.

BTW for my current game I was doing a resize as well (nearest) and even that didn't turn out to be fast enough to do real time full screen on most devices, it is off by default, but users can turn it on. IMO you should render to the native resolution if at all possible, as this will look the best by far and be the fastest.
Phantom wrote:
BTW I also tried semi-HDR with a nice bloom filter. That does help a bit as it blurs the bright lines slightly. :)


Sounds cool, is it actually like real HDR, or is it just a diffuse glow really?
It's a fake diffuse glow. I'm not rendering to a floating point target. :)

BTW you can do fast blooming by summing pixels, subtrating the 'tail' and adding the 'head'. This way, a 8x8 box filter costs just as much as a 2x2 filter.

mm40: Thanks for the suggestion, I'll try that. I do think however I should take out this feature, I think it's too expensive. Problem is, I'm still working with 40x40 tiles like I did in the original Nutcracker, and frankly I think they are a tad too large to see enough of the scenery right now. I do adjust the camera to compensate; if you look right your vehicle is to the left of the centre of the screen for example. Works quite well, but ideally I would like 32x32 tiles. Perhaps I should go over all the art to make it so. :(

- Jacco.
BTW you can do fast blooming by summing pixels, subtrating the 'tail' and adding the 'head'. This way, a 8x8 box filter costs just as much as a 2x2 filter.


Well, box filters are linear separable, so a 2d box filter can be implemented as 2 1d box filters. On top of this, since it is a box filter, taps are position independent (ie. all equal), which means independent of its size you need only 4 add/sub instructions for a 2d block filter per output sample.

Other than that, a correct implementation of bilinear filtering should have almost no artifacts when scrolling. Of course on hardware accelerated devices like the X50v you can use the graphic hardware to do the bilinear scaling for you.

Tala
Tala wrote:Other than that, a correct implementation of bilinear filtering should have almost no artifacts when scrolling. Of course on hardware accelerated devices like the X50v you can use the graphic hardware to do the bilinear scaling for you.

Tala


True, if you are on the x50 you could also render to a 480x640 window eliminating the need for scaling.