AuthorTopic: Scaler for pixel art  (Read 2598 times)

Offline yrizoud

  • 0010
  • *
  • Posts: 330
  • Karma: +0/-0
    • View Profile

Scaler for pixel art

on: April 05, 2013, 01:33:18 pm
On the Allegro programming forums, user Siegelord made a pixel shader for upscaling pixel art.
It's nothing like all the interpolating algorithms (eagle, 2xsai, hq3x..), on the contrary it's something so simple that I'm surprised nobody did it before.
To quote user Pkrcel, "You are basicaly interpolating only at the "borders" of the scaled pixel ".
It's designed for up-scaling at arbitrary sizes, for example to resize a low-res game's window without being constrained to specific factors.
Thought this could interest some pixel-friendly coders here. Siegelord's test program is made with Allegro 5, but the shaders themselves are in glsl and hlsl - and their source is public domain.

Offline surt

  • 0011
  • **
  • Posts: 570
  • Karma: +0/-0
  • Meat by-product
    • not_surt
    • http://pixeljoint.com/p/2254.htm
    • View Profile
    • Uninhabitant

Re: Scaler for pixel art

Reply #1 on: April 05, 2013, 02:11:59 pm
Just looks like standard area-based resampling to me. Am I missing something?  ???
To me it seems to have the worst aspects of both nearest-neighbor resampling and bilinear resampling. Blocky and blurry.

Offline yrizoud

  • 0010
  • *
  • Posts: 330
  • Karma: +0/-0
    • View Profile

Re: Scaler for pixel art

Reply #2 on: April 05, 2013, 03:20:17 pm
Well it looks like what some LCD screens do when you ask them a non-native resolution, but I didn't know of a software equivalent (or even a name for this algorithm).

As for its merits, look at the font, for example the word ENERGY : With nearest neighbor, the white pixels at top are one full pixel smaller than most of the other lines, and it's painfully obvious that the top line of the font is too thin. With the shader, the average "lightness"/importance of all pixels is equal.

Offline ptoing

  • 0101
  • ****
  • Posts: 3063
  • Karma: +0/-0
  • variegated quadrangle arranger
    • the_ptoing
    • http://pixeljoint.com/p/2191.htm
    • View Profile
    • Perpetually inactive website

Re: Scaler for pixel art

Reply #3 on: April 05, 2013, 04:37:05 pm
And scaling it up like 80 or so pixels in both dimensions would make for a nice clean 3x scale. It does look better than linear, sure. But there is no good reason why you could not run it at a slightly higher res and keeping a clean pixel ratio.
There are no ugly colours, only ugly combinations of colours.

Offline yrizoud

  • 0010
  • *
  • Posts: 330
  • Karma: +0/-0
    • View Profile

Re: Scaler for pixel art

Reply #4 on: April 05, 2013, 06:36:06 pm
Physical screen limit! For example I use emulators a lot on oldish computers with 1024x768 screens.
Scaling 320x240 thrice gives 960x720, the border is not too wasteful but it still breaks the immersion compared to actual fullscreen.  Especially with emulators that can only run as a window, the desktop is visible around it.
Algorithm can also be a good option to render non-square pixels that have an unfriendly ratio : for example VGA had slightly "tall" pixels (120%), Amiga resolutions had slightly "flat" pixels (about 94%).

Offline ptoing

  • 0101
  • ****
  • Posts: 3063
  • Karma: +0/-0
  • variegated quadrangle arranger
    • the_ptoing
    • http://pixeljoint.com/p/2191.htm
    • View Profile
    • Perpetually inactive website

Re: Scaler for pixel art

Reply #5 on: April 05, 2013, 08:10:46 pm
I have been using emulators for almost 2 decades now, never seen one which can not go full screen _o
And in any case, a black border imo does nothing to break immersion in any way. You are looking at a picture on a rectangle in front of you, surrounded by room. I doubt that the rectangle having a bunch of black around the actual image changes anything for most people, but I grant you that you might be an exception. I for one prefer clean pixels and a slightly smaller viewing area over blurred and bigger.

VGA can be scaled nicely to 1600x1200 if you want clean, and even if you use a different scale you could do something like you are doing and scale so that it only needs to be applied vertically. 1024x768 is ancient by now, even my monitor from 1996 could run 1600x1200.

And small stuff like 100:94 scale pixels can be neglected. I agree that in some cases (like VGA even) it can look weird to have the wrong aspect, CPS stuff being a more extreme case than VGA for example. And for CPS you kinda need something like you are doing (Which newer versions of MAME do perfectly well for example), because the resolution required to scale cleanly without antialias between pixels is pretty huge.
There are no ugly colours, only ugly combinations of colours.