2xSaI and other filters

Discussion of tools and resources for game developers

Post » Mon Feb 23, 2009 9:21 pm

Sometimes you discover that the images you have made for your game are too small for your purposes. For example, you decide to switch from an old-school 320x200 style to something allowing more details. Or you use sprite rips as placeholders, but the resolution of the rips is lower than you'd like.
There are numerous ways of addressing that, ranging from the standard bicubic filtering found in most image editors and to Genuine Fractals, $160 Photoshop plugin.
There are, however, several lesser-known options.
Well, who am I kidding, most of us used an emulator at least once, so most people already know what filters like 2xSaI or SuperEagle do.

Anyway, here's a bunch of such filters:

[list:1ctrjojv]
[*:1ctrjojv]Scale2x - despite what the name suggests, it allows 2x, 3x and 4x scaling. Also it respects alpha, if only 1-bit.[/*:m:1ctrjojv]
[*:1ctrjojv]HQ2x - honest 2x scaling here. Probably the best real-time scaling algorithm there is right now.[/*:m:1ctrjojv]
[*:1ctrjojv]HQ3x - same as the above, only 3x. The page contains the explanation of the algorithm.[/*:m:1ctrjojv]
[*:1ctrjojv]HQ4x - same as the above, only 4x. Just like it's 'smaller brothers', doesn't support alpha.[/*:m:1ctrjojv][/list:u:1ctrjojv]

Here is a sample of Scale2x:

and here's HQ3x:


There's also good old 2xSaI, with SuperEagle bundled with it, but you'll need to compile those manually.

Of course, no algorithm can add detail to your image, but at least the filtered sprites are a good starting point for further tweaking.

Anyway, filters from the list are downloadable as executables, but those only allow processing a single file at a time, which is a pain if you have a lot of files to enlarge.

I made a simple script to automate such tasks.
It takes a name of a filter and a folder name and runs all the images in that folder through the specified filter. It is really dumb, it only processes files of a fitting format (tga for HQ?x, png for scale2x. HQ?x also allows bmp, but only 24bpp, I think, so I only allow tga just to be sure it processes it without errors), and it will processes all such files in a folder. Have some files that don't need enlarging? Move them somewhere else. It also doesn't have any kind of GUI and is purely commandline. Also, it relies on the aforementioned exe files, but it doesn't even check for their presence. It simply passes strings for the shell to execute.

Usage:
As I said, it takes two parameters: first one is a filter name (scaler2, scaler3, scaler4, hq2x, hq3x or hq4x) and a folder name. If you run it without parameters, it will use scaler2 on the folder you run it from. If you run it with just one parameter it will use it as a filter name, and apply this filter to the current folder.

Requirements:
You should put the filter exes (and all they need to run, namely libpng.dll and zlib.dll for the scalerx) in the same folder as my script. It uses scalerx.exe, not scaler.exe, by the way.
The folder will contain the following:
[list:1ctrjojv]
batchfilter.rb (or batchfilter.exe, if you use the "compiled" version)
hq2x.exe
hq3x.exe
hq4x.exe
libpng.dll
scalerx.exe
zlib.dll
[/list:u:1ctrjojv]
Let me say this again: the script does not check if those files are present. You have been warned.

Anyway, without further ado, here's the script:
[url:1ctrjojv]http://willhostforfood.com/access.php?fileid=56328[/url:1ctrjojv]
It is written in Ruby, so you'll need a Ruby interpreter to run it. If downloading 25Mb for a tiny script doesn't sound like fun for you, you can use the exe version:
[url:1ctrjojv]http://willhostforfood.com/access.php?fileid=56330[/url:1ctrjojv]
It's quite large (1.5MB), since it basically contains a Ruby interpreter plus the original script, but it's still smaller than 25Mb, right?

Anyway, I really hope that someone sees merit in it and rewrites it in C or something, so it's not so horribly bloated.
B
4
G
4
Posts: 65
Reputation: 1,305

Post » Mon Feb 23, 2009 10:20 pm

Looks a bit like GreyCstoration
[url:1q1ewz6b]http://cimg.sourceforge.net/greycstoration/demonstration.shtml[/url:1q1ewz6b]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Feb 23, 2009 11:43 pm

I'm sure modern GPUs are powerful enough to run these filters dynamically, if they are written in a shader. Construct only supports shader model 2 at the moment though, and DirectX 9 only supports up to PS 3. I wonder if anyone's managed to put these filters in a shader yet, and if so, what shader model is necessary.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Feb 24, 2009 2:51 am

I don't think these filters really need shaders, they've been in things like console emulators with no hardware acceleration for years. Filters like 2xSaI and such are meant to be real-time filters.

But making a shader maybe would benefit it? I dunno.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Feb 24, 2009 3:19 am

Running effects in software doesn't really work particularly well with DirectX: you start to have to move graphics data between the GPU and CPU every frame, which is very slow.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Feb 24, 2009 12:38 pm

[quote="newt":f261q2c7]Looks a bit like GreyCstoration
[url:f261q2c7]http://cimg.sourceforge.net/greycstoration/demonstration.shtml[/url:f261q2c7][/quote:f261q2c7]

Well, for resizing they seem to use something similar to anisotropic diffusion. Anyway, it is intended for photos, and therefore not very good for sprites, as it makes 'em only slightly less blurry than bicubic. HQ?x and the likes, on the other hand, keep the colors crisp and the outlines sharp. Well, none of these filters are perfect anyway...
B
4
G
4
Posts: 65
Reputation: 1,305

Post » Tue Feb 24, 2009 1:18 pm

Personally I kind of like it, sort of a cross between watercolors, and oils.
Might be a nice stylization for a game, something different anyways.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun May 03, 2009 5:49 am

This whole discussion is widely overlooked though it's been so widely used in emulators for years. If they can do it in real time with emulators, why hasn't someone more tech savvy not tackled this?

I may want to learn python just to find a way to write a script. It makes games look way nicer and could be the deciding factor in the future of 2D gaming.
B
24
S
6
G
6
Posts: 255
Reputation: 3,649

Post » Sun May 03, 2009 2:41 pm

I think the issue is the flow of information. A cpu has no problem running the filter, but the filter needs to be run after the screen has been drawn. If I'm not mistaken, the flow of data goes CPU to GPU to monitor. To run the filter, you'd have to send the data from the CPU to GPU, back to the CPU to run the filter, back to the GPU again and then to the monitor. Your framerate would take a HUGE hit.

The reason emulators and such can do it is they're using software rendering via the CPU - the graphics card isn't doing the rendering like construct does. Unless it can be coded as a pixel shader and therefore runs on the card, or construct gets a software renderer, it's not efficient in the slightest.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun May 03, 2009 4:16 pm

It would be nice then to see if someone can design a pixel shader to do it.

On that topic, is there any pixel shader that already is in construct that makes low res images look nicer and more smooth?
B
24
S
6
G
6
Posts: 255
Reputation: 3,649

Next

Return to Tools and Resources

Who is online

Users browsing this forum: No registered users and 2 guests