xBR algorithm tutorial

That’s a very good combination, @guest.r!

It reminds me I have to start working on a lvl6 noblend version. I’m just a bit lazy.

I’ll need to refactore all super-xbr shader presets. I’ll swap jinc by deblur as the final touch. I think it gives a better sharpness and doesn’t introduce ringing.

3 Likes

Hi @Hyllian I’m really enjoying all the use of the downscaled XBR in your shader and others, it looks really great :smiley:.

I was wondering if you could explain what is the difference between the different XBRs, 2p, 3p, 6p, adaptive, lv3-multipass , mlv4-multipass, etc.

3 Likes

Lately I’m a bit busy with real life, but I’ll try to explain your question here. Sorry for my weird english, kkk:

2p, 3p are related to the numbers of passes. So, super-xbr-2p-xxx delivers sxbr filtering in only two passes. Though I can filter in only two passes, it can be improved with an aditional pass. So, usually, I upscale (with sxbr algorithm) at 2x scale in two or three passes. The 3p version is a bit better than 2p in IQ, though a bit slower. The 3p versions fix the half pixel offset result of the sxbr (in two passes) and smooths the overall image quality.

And, the 6p version is just sxbr-3p applied two times so that we can get a 4x scaling.

Now, about the LVL keyword I use (It’s used only for XBR, not super-xbr), it’s related to the kind of staircase that can be completely smoothned by the algorithm. So, for example, a XBR-LV1 can only smooths perfectly a staircase of 45 degree. If the staircase is 60 degree, for example, the result will be a softened staircase not entirely smoothened. For that I need a LVL2 version. The LVL2 takes care of staircases of 30, 45 and 60 degree staircases. And LVL3 takes care of even more kinds of staircases.

The most advanced XBR I could implement is the mlv4, which means multilevel4. While the others use a greedy implementation where they always try to smooth with the biggest LVL possible. This one use some euristics where it always decides the most appropriate LVL (among 1 to 4) for each staircase kind. It’s a bit complex so I had to implement it in four passes.

For future develpment, I think it’s possible to achieve LVL6 (like in ScaleFX), though I couldn’t find an easy way to make it, yet. Maybe someone else can continue from here (@guest.r ? :wink: ).

2 Likes

Thanks so much for the explanation! This helps me a bunch :slight_smile:

Also, not to worry @Hyllian, your English is great! :smile:

2 Likes

I think most folks get it a bit wrong here, since xBR LVL2 is a great achievement and coders who continued xBR focused more or less on the LVL2 implementation. Currently i’m interested in adding some accuracy to the single pass xBR-LVL3 (noblend) and see how it goes. From my observations LVL3 could be a reasonable limitation for fast high consistency arbitrary logic scalers within current times reach.

2 Likes

I strongly agree on the accuracy thing . I think one way to obtain the accuracy , is to allow the shader to produce it’s own artifacts whenever it’s trying to deal with curves .That is to say , not everything has to be vectors especially the curves.

I think the best type of artifacts would be tiny square pixels , even smaller then the raw image.

Here is couple of pics that illustrate how each shader deal with curves

Raw (no shader)

MMPX , new shader that keeps original corners intact

xbr3

scalefx-hybrid-scaler-sharp (default values)

scalefx-hybrid-scaler-sharp (Adjusted values)

Biliner

A shader preset I put together from different passes ,it’s a bit blurry so it can’t show good colors.

(mega link down below )

https://mega.nz/file/cZh3wYLY#1E-VgIiPV3bGJsM-GxBgpziBfrcOkcT7vYxisj-hXiY

I think it would be more accurate to source material if we target a shader that aims to produce a slightly pixelated image (like Hi-res sprites) rather then HD one that would produce vectors on curves.

3 Likes

Fascinating topic. It’s interesting to see how theae shaders developed over time. Quick question: What shader is supposed to be faster, less resoirces hungry? Xbr (2p, 3p?) or ScaleFX?

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