xBR algorithm tutorial

So, 10 years since I created this thread. The filter is already 11 years old.

Revisiting this algorithm and reading again this thread I can see how I was pursuing the wrong goals.

At first, the idea was to get rid of pixelization at all costs. And the costs were high. To get rid of pixelization, you smooths out the diagonal edges, which seemed a good idea at first. Cartoon games looked good. Yet, when you use it with a game with textures, you take note how textures get a disgusting visual and small details on sprites melt.

The goal of sharpness and death to pixels was misguided.

After seeing how retrogamers like pixel art and preserve certain small details, I decided to tweak super-xbr with different goal now. It only smooths out explicit diagonals and let the ambiguous as is.

It’s true you lost sharpness a bit and the output is a bit blurred. That’s because a true upscale always result in a bit of blur.

Anyway, I think the result is great and you can see by looking at the pictures below. Pixels art is preserved, textures are organic and explicit diagonals are smoothed.

To get these visuals I just tweaked super-xbr parameters a bit. I have creted a preset you can use, just unzip it and put inside slang_shaders folder. I’ll call this super-2xbr.

super-2xbr - 22-06-22 - slang.zip

More on galley: https://imgbox.com/gallery/edit/Jn6BITG5y8/nr8rPCXfIeUaOgwC

7 Likes

that looks great, man :slight_smile:

Have you checked out MMPX? It’s essentially just scalenx lv2 plus a bunch of rules to skip certain pixels to preserve more of the pixel art flavor.

3 Likes

I didn’t know about that. I’ll look into it and see how it compares to others. Sounds good! It seems focused in sharp output like standard xbr, hqx or scalefx.

super-xbr is more all purpose scaler like jinc, cubic or bilinear. Speaking of it, I think it looks much better than cubic, jinc or lanczos outputs.

EDIT: tested mmpx here. I think it needs further developments on rules and blending, because it let many raw pixels behind and it doesn’t look good near the smoothed ones. Even on SMW, which is a very cartoon game, it shows many flaws in pixel treatment.

3 Likes

Looks really good @Hyllian!

I took a look at your zip package, is it correct that it is only a preset which uses the existing XBR shaders?

3 Likes

Even though I never liked this kind of upscaling, I must admit that this one looks quite nice.

3 Likes

Yes, I adjusted the edge strength parameter so that not obvious edge regions aren’t smoothed out. And some other minor tweaks.

By the way, compare it with nnedi3 output and see how it stands with a fraction of its required power.

3 Likes

At first view you might think that it’s just some bicubic or lanczos filter. But if you look closer and test games, in motion, mainly, you’ll see that HUDs, fonts, small details and texture are more preserved with super-2xbr.

Fonts and huds gallery: https://imgbox.com/gallery/edit/QYblsHYzB0/DiClW7QiGK1WzpbF

2 Likes

I spent some time revisiting the old xBR shaders and decided to put some effort to organize the slang code, as they were just ports of Cg.

I cut out most of cg compatible code in favor of pure slang ones. And I’ve changed the color distance function (thanks to valious suggestions from @guest.r). The old code was very fast, but wasn’t very accurate on discerning some color gradient.

On top of that, I have improved the AA code, which works at any resolution (interger and non-integer) and will preserve crispness even at 4k resolutions. And merged the noblend shader with that AA. A switch param was inserted to allow toggling between the two options.

So, summarizing:

  • New color distance function to improve IQ;
  • Merge noblend and aa shaders in same files;
  • Better param descriptions;
  • New param to switch between noblend and aa;
  • New lv1, lv2-multipass and lv3-9x.

I made a Pull Request on github repo with the changes. If you don’t wanna wait for the main repo be updated (EDIT: main libretro repo updated! So, just update your slang shaders through Retroarch online updater!), here’s a pack of new shader/presets:

xbr updated - 22-07-16.zip

And some screenshots from xbr-lv3-9x:

More on gallery: https://imgbox.com/gallery/edit/BdbTjTWRyI/aXCWJ8RplC2Ep2SD

5 Likes

looks great man :smiley:

That copyright circle-C in the SMW shot is :chef-kiss:

2 Likes

I’m ‘somewhat’ familiar with the changes and they are very nice. xBR is fast, consistent and nice looking.

Also looking forward to @Hyllian 's possible new shading projects. :smiling_face_with_three_hearts:

6 Likes

Well, if there ever was a case where I might use this kind of upscaler, it’s this:

Source image:

Toonstruck-220716-225719

4 Likes

The best target for this kind of filter are games that don’t use too much color gradient. All 8-bit and prior generation games. For 16-bit, all Mario, Zelda and cartoon games.

For most 16-bit and further generations (32-bit and up) there are better filters that blend subtle color gradients.

3 Likes

Released today on repo (use update online to get it) this xbr-small-details that skips most dithering and relevant pixels when filtering. The result is a bit less smelted than regular xbr shaders and textures are more preserved:

Gallery: https://imgbox.com/gallery/edit/GyClrfRcwP/dimw6SMp0w0toHUk

6 Likes

Some improvements on xbr-lv2-small-details. Now dithering is almost completely intact.

It’s available on slang repo already.

Some screens:

Gallery: https://imgbox.com/gallery/edit/4jGhy8V7dI/waPxx431rW4N1O3w

6 Likes

New versions of xBR and Super-xBR added to slang libretro repo!

What’s new:

  • Major cleanup to xBR folder. Now only six presets in main folder. Most of old presets are now inside “other presets” new folder for historical reasons.

  • In main folder only multipass and gamma corrected versions available. Blending in linear gamma now favors white pixels the same way as dark ones, which means dark lines are thinner and produces a pleasant result in cartoon games;

  • I have changed some core rules of xBR and now dithering looks less weird when filtered. I even provided an option to not touch dithering at all, which looks good in some dithered plagued games;

  • The old small-details version is now the default as I think some pixels can’t be touched or else drawing details are lost when filtered;

  • Added new params, now the user can control the level of smoothness. At max, it’ll reminds old xbr versions, at min it’ll be more pixelized. So, some place in between must be the sweet spot and the user can decide now.

  • After thinking about it, I decided that a bit of blur is necessary as a final touch and not let a very sharp output. So, the main presets are slightly blurred compared to old versions (these can be used inside “other presets” folder yet). It isn’t an issue if you don’t play with your nose touching the display (LOL);

  • And finally, got rid of those fancy names (3p, 2p, 6p, etc).

xBR screenshots:

Super-xBR screenshots:

Gallery: https://imgbox.com/gallery/edit/sooQy2v31R/hGDzGaEJblivg9gc

10 Likes

Did you integrate a deposterize algorithm? Would be nice to see with deposterisation

Is there a Super-XBR version for ReShade?