xBR algorithm tutorial

Has anyone tried removing the branches and using floating point masks? I’ve modified the SABR shaders and was able to go from 2x to 4x GBA upscale on a Nexus 4.

Not sure if it will have as much as an effect for CG on a PS3 (mobile allows less depth on branching)

Sample:

[QUOTE=commiebits;22264]Has anyone tried removing the branches and using floating point masks? I’ve modified the SABR shaders and was able to go from 2x to 4x GBA upscale on a Nexus 4.

Not sure if it will have as much as an effect for CG on a PS3 (mobile allows less depth on branching)

Sample: https://github.com/commiebits/emulator-shaders/blob/e27cca745a49d7e72107309223363b9356ed4cb4/assets/sabr.shader[/QUOTE]

I have a feeling it helps PS3, yes. Thanks for sharing.

News!

Long time since something interesting happened to add to xBR. Now, finally I figured out something I was looking for years! It was so hard to find (maybe I’m dumb) I have created the entire xbr-hybrid variant to overcome this (LOL). Now I’ll finally create a xBR for more genera tasks and more powerful with cartoon AND digitized images. What I’m saying is that the next xbr will be very different from the others as I had to rewrite the shader almost from scratch. It now can detect edges in horizontal and vertical directions (all the old ones only detect in diagonals). There are more two benefits from this approach: firstly, it’s possible to get rid of some annoying artifacts in dithering regions by control the level of interpolation (it can turn totally bilinear, for example); and second, some artifacts of digitized games that some vertical and horizontal lines couldn’t merge, now it can… The only drawback is that I can’t detect corners with this new approach, so the old ones must keep their place yet. The other problem is that I can only scale for 2x, though using jinc2-sharper as a last shader can scale the result to any size almost seamlessly. I think the quality is comparable to nedi with much less artifacts. In this approach I have to test many other things before releasing, so I’ll let some screenshots:

Look at the flamethrower reservatory, the dithering is destroyed by artifacts:

Now, using the bilinear control, it’s possible to take xbr out of the dithering and keep it in other parts (like the character, for example):

more here: http://imgur.com/a/e4mqp

Ok, as a POC, I just added a first version to common-shaders: https://github.com/libretro/common-shaders/tree/master/xbr/super-xbr

It’s a multipass shader with some parameters you can tweak on the fly:

Bilinear Weight: it’s set to 0.4. If you want full xbr effect, turn it to 0.0. Above zero, it can let some patterns untouched. It must be good for games plagued by dithering or with very subtle color gradients (digitized games).

The last pass is a jinc2 customized. It has an anti-ringing, though it isn’t set by default. Just increase it and you can get rid of rings. But beware, the anti-ringing may tone down some texture details too.

It doesn’t have corner detection, so fonts and huds are smoothed to the bones! I didn’t figure out yet how to treat corners in this new implementation. As it’s almost a different filter than the standard xbr, I call it Super xBR from now on. It furthers the concept of edge detection by applying rules to vertical and horizontal edges. By doing this, color gradient changes in these directions are much more smooth then before. For this new implementation multipass is mandatory, or else the speed in single pass would be too slow (for now I think…).

Improved the transition between bilinear and xBR algorithm. It’s already in common shaders. Now the transition is almost seamless!

more screens here: http://imgur.com/a/nRYc2

Great work! (as usual) Can’t wait to try it, btw I’m using the 2xbr-hybrid(scale 2x)+smart-blur, do you think this new filter is better than this?

[QUOTE=final_87;22827]Great work! (as usual) Can’t wait to try it, btw I’m using the 2xbr-hybrid(scale 2x)+smart-blur, do you think this new filter is better than this?[/QUOTE] Well, the visual pleasure is personal. But, for me, I’d say yes.

Added jinc2 interpolation to parts of code when edges are detected. The results improved a bit more! It’s already uploaded to common-shaders: https://github.com/libretro/common-shaders/tree/master/xbr/super-xbr

I just updated common-shaders with the new Super xBR. Now it is more smoother!

Here’s an example:

Upscaled with NNEDI3 (a great filter of Avysinth that use neural networks to scale) at 4x:

Here’s the same image upscaled by Super xBR at 4x using standard config:

And here’s the same image upscaled by Super xBR at 4x using a sharper config:

New version is in this link: https://github.com/libretro/common-shaders/tree/master/xbr/super-xbr

Some shots of SOTN:

Others.

:open_mouth:

Those shots are incredible! The text on Castlevania looks absolutely superb.

Yeah! I had to rerun to believe it was that way! It’s getting in good shape, even corners are appearing now!

That looks really good. How much more demanding is it than the sabr shader or xbr x4 or xbr x5?

It should be on par with those. The burden is well distributed among the passes.

[QUOTE=commiebits;22264]Has anyone tried removing the branches and using floating point masks? I’ve modified the SABR shaders and was able to go from 2x to 4x GBA upscale on a Nexus 4.

Not sure if it will have as much as an effect for CG on a PS3 (mobile allows less depth on branching)

Sample: https://github.com/commiebits/emulator-shaders/blob/e27cca745a49d7e72107309223363b9356ed4cb4/assets/sabr.shader[/QUOTE]

So if I take this shader and save it as .cg and load it on my Android TV Box it should work on android? Or do I need to save it with a different extension or do I have to convert it some how?

You’d need to run th cg2glsl script

Would you be able to convert the shader posted by commiebits for me. I’d like to try it on my Androd Box and keeps failing for me

C:\Users\User\AppData\Local\Programs\Python\Python35\python.exe “C:\Script\cg2glsl.py” C:\Shaders2\Test.cg C:\Shaders\Test.gls

I keep getting a bunch of errors.

C:\Shaders2\Test.cg(1) : error C0000: syntax error, unexpected ‘<’ at token “<” C:\Shaders2\Test.cg(5) : error C0130: invalid character literal C:\Shaders2\Test.cg(9) : error C0000: syntax error, unexpected ‘/’, expecting " :" at token “/” C:\Shaders2\Test.cg(11) : error C0000: syntax error, unexpected integer constan , expecting “::” at token “<int-const>” C:\Shaders2\Test.cg(16) : error C0000: syntax error, unexpected ‘.’, expecting ::" at token “.” C:\Shaders2\Test.cg(26) : error C0104: Unknown pre-processor directive #version C:\Shaders2\Test.cg(31) : error C5060: out can’t be used with non-varying vTexC ord C:\Shaders2\Test.cg(35) : error C5059: stdlib “gl_” variables are not accessibl C:\Shaders2\Test.cg(38) : error C0000: syntax error, unexpected ‘]’ at token “] C:\Shaders2\Test.cg(41) : error C0104: Unknown pre-processor directive #version C:\Shaders2\Test.cg(62) : error C1059: non constant expression in initializatio C:\Shaders2\Test.cg(133) : error C0000: syntax error, unexpected type identifie , expecting ‘{’ at token “vec2” C:\Shaders2\Test.cg(134) : error C0000: syntax error, unexpected type identifie , expecting ‘{’ at token “vec2” C:\Shaders2\Test.cg(135) : error C5060: out can’t be used with non-varying frag entColour C:\Shaders2\Test.cg(137) : error C1013: function “main” is already defined at C \Shaders2\Test.cg(33) C:\Shaders2\Test.cg(271) : error C0000: syntax error, unexpected ‘]’ at token " " Vertex compilation failed … C:\Users\User>C:\Users\User\AppData\Local\Programs\Python\Python35\python.exe " :\Script\cg2glsl.py” C:\Shaders2\Test.cg C:\Shaders\Test.gls C:\Shaders2\Test.cg(1) : error C0000: syntax error, unexpected ‘<’ at token “<” C:\Shaders2\Test.cg(5) : error C0130: invalid character literal C:\Shaders2\Test.cg(9) : error C0000: syntax error, unexpected ‘/’, expecting " :" at token “/” C:\Shaders2\Test.cg(11) : error C0000: syntax error, unexpected integer constan , expecting “::” at token “<int-const>” C:\Shaders2\Test.cg(16) : error C0000: syntax error, unexpected ‘.’, expecting ::" at token “.” C:\Shaders2\Test.cg(26) : error C0104: Unknown pre-processor directive #version C:\Shaders2\Test.cg(31) : error C5060: out can’t be used with non-varying vTexC ord C:\Shaders2\Test.cg(35) : error C5059: stdlib “gl_” variables are not accessibl C:\Shaders2\Test.cg(38) : error C0000: syntax error, unexpected ‘]’ at token "] C:\Shaders2\Test.cg(41) : error C0104: Unknown pre-processor directive #version C:\Shaders2\Test.cg(62) : error C1059: non constant expression in initializatio C:\Shaders2\Test.cg(133) : error C0000: syntax error, unexpected type identifie , expecting ‘{’ at token “vec2” C:\Shaders2\Test.cg(134) : error C0000: syntax error, unexpected type identifie , expecting ‘{’ at token “vec2” C:\Shaders2\Test.cg(135) : error C5060: out can’t be used with non-varying frag entColour C:\Shaders2\Test.cg(137) : error C1013: function “main” is already defined at C \Shaders2\Test.cg(33) C:\Shaders2\Test.cg(271) : error C0000: syntax error, unexpected ‘]’ at token " " Vertex compilation failed … C:\Users\User>

I just updated Super-xBR shaders.

Now the user can tweak the filter weights with just one knob. It’s a param that can vary from 0.0 to 2.0:

0.0 means bilinear filtering. 0.65 is equivalent to cubic filtering 1.29 is sinc filtering (the default value). This is the biggest sane value. Above 1.29 is insanely sharp, which can introduce other artifacts, though it can please some other users.

I developed a fast variant of super-xbr and released on common-shaders: https://github.com/libretro/common-shaders/tree/master/xbr/super-xbr

It’s like twice as fast.

Hey Hyllian! I’ve created an account to ask a bit of help regarding the cg shaders. So I’m a beginner when it comes to shader programming and I wanted to use the xBR (x2 the native resolution) shader in my Unity game. A very kind member of the community helped me exporting ( actually he did the whole thing, I was just watching) the cg shader into a shader compatible with Unity, here is a link to the post : http://forum.unity3d.com/threads/how-to-copy-paste-a-cg-shader-found-on-the-internet-in-unity.334772/#post-2181555 So the shader compiling is throwing no more errors thanks to Lanre, but I have no idea what to fill these values with : half2 video_size; float2 texture_size; half2 output_size; Lanre said they’ll need to be filled with a Vector4 value ( 4 floats, X, Y, Z, and W), but the screen is always white regardless of the values I set from within the script that controls the shader. I was also doubting about whether the cg shader that was exported works to begin with ( link in my Unity post). HELP! I must say my game looks gorgeous with the xBR filter applied to it ( through an image scaler that uses the algorithm)