pcsx2 icon indicating copy to clipboard operation
pcsx2 copied to clipboard

WIP: Fancy downsampling shaders

Open KrossX opened this issue 2 years ago • 18 comments

At some point when internal resolution is high enough compared to the viewing area, bilinear filter stops being useful and aliasing occurs. For the few people that use such high internal resolutions, these supersampling filters might help.

Included filters are 4x rotated grid (4 fetches), quincunx (5 fetches), jittered stochastic (3x3 fetches) (wiki on patterns). I tried other filters like bicubic and lanczos but while those seem to work well when upsampling, it was quite the opposite when downsampling. There's an approximation for gamma correction, which I have yet to compare. To do so, edit the present_xtra.fx file and change the define.

Also added an antialiased nearest filter for upsampling that can achieve the sharp bilinear effect. This last filter is mostly for comparing performance between the two methods. Should be used with bilinear (smooth) option.

KrossX avatar Dec 21 '22 17:12 KrossX

Tested here and it looks even better than setting your desktop to PCSX2's internal resolution using DSR. Great work!

4x rotated grid and jittered stochastic looked the best to me and almost identical between them.

DonelBueno avatar Dec 21 '22 23:12 DonelBueno

Any reason why we need this in a separate fx/glsl file, and it can't be combined in the main file?

stenzek avatar Dec 22 '22 02:12 stenzek

Any reason why we need this in a separate fx/glsl file, and it can't be combined in the main file?

Bad habit of making forum shaders which were seperated because of plugin system?

RedDevilus avatar Dec 22 '22 03:12 RedDevilus

Any reason why we need this in a separate fx/glsl file, and it can't be combined in the main file?

Just a minor convenience thing. I had already lost some changes due to copy pasting files, this helped mitigate that too. It can certainly be combined later.

KrossX avatar Dec 22 '22 09:12 KrossX

I prefer if it was combined now, also needs Metal implementation btw.

lightningterror avatar Dec 22 '22 09:12 lightningterror

Added heavier shader version up to 9x9 as suggested by Jordan. Test performance and quality difference, folliage might be a good thing to test with.

I prefer if it was combined now, also needs Metal implementation btw.

I'd rather wait until settling what remains and what's gone. As for Metal though... I have no idea how to do that, I'll leave that to last.

KrossX avatar Dec 22 '22 12:12 KrossX

Hi, how do I download this build? I want to use it for screenshots.

HelelSingh avatar May 02 '23 07:05 HelelSingh

You can't download it anymore since all the build artifacts have expired. @KrossX will have to do a rebase or trigger another check to create another build

image

kamfretoz avatar May 02 '23 07:05 kamfretoz

Oh, ok. Do you mind teaching me where to look for those files in the future or in other pull requests?

HelelSingh avatar May 02 '23 07:05 HelelSingh

On top of the PR page you should see the "Checks" Tab, click on it and pick your operating system on the left. Once you're in that page, click on Summary on the top-left. Scroll down and you should see a bunch of build files you can download.

kamfretoz avatar May 02 '23 07:05 kamfretoz

Rebased.

For those that try and find this feature useful, please provide feedback on your results with the different methods and take special notice if the jittered versions show any improvement and/or annoyance during gameplay.

KrossX avatar May 02 '23 09:05 KrossX

Am I doing something wrong? None of the SSAA shaders seem to work for me, other shaders like Scanlines work.

All screenshots are at 3x Internal Res.

No shader :

PCSX2 2023-05-02 21-32-24

Quincunx :

PCSX2 2023-05-02 21-38-12

Scanlines :

PCSX2 2023-05-02 21-42-22

HelelSingh avatar May 02 '23 16:05 HelelSingh

@HelelSingh You need to run the game at a higher internal res than the display resolution. The SSAA shader doesn't run it at 6x res when it is set to 3x res like a game that would support SSAA in the driver control panel.

ps1freak26 avatar May 02 '23 19:05 ps1freak26

Thanks, that works. I assumed it would behave just like in the Dolphin emulator where you select a SSAA value from 2x to 8x and then select the Internal Res (like 3x in my case) to which the SSAA downsamples down to. Something similar is also available in DuckStation.

@KrossX will that be possible here in PCSX2?

HelelSingh avatar May 02 '23 20:05 HelelSingh

No idea, the MSAA or SSAA you're thinking of is making use of multisampled framebuffers that need to be resolved and work with all the trickery with format changes and whatnot. Seems not a trivial task and quite the pain in the bum. It is indeed a feature I use with DuckStation as I quite like the result as opposed to higher IR.

This PR is just for people using an absurdely high internal resolution expecting a smoother image but getting a jagged result instead. If you're using 3x IR to sort of match your screen/window resolution, try multiplying it for the SSAA value you would've expected; 6x IR for 2x SSAA, 24x IR for 8x SSAA, etc...

KrossX avatar May 02 '23 20:05 KrossX

If you're using 3x IR to sort of match your screen/window resolution, try multiplying it for the SSAA value you would've expected; 6x IR for 2x SSAA,

I believe 6× IR in this particular case is 4× SSAA, as the pixel count is quadrupled, not doubled. This should be clarified in the documentation as it's easy to get wrong :slightly_smiling_face:

Calinou avatar May 20 '23 22:05 Calinou

Needs a rebase as the patches have changed so any new builds will fail unless a rebase is done.

refractionpcsx2 avatar May 31 '23 15:05 refractionpcsx2

Added new shader, this one tries to get the number of samples at runtime. Dunno if there's much of a performance impact from having a known loop.

If performance is fine compared to the other methods, maybe this is the method to keep.

KrossX avatar Jun 27 '23 23:06 KrossX

Dunno if there's much of a performance impact from having a known loop.

The loop count not being constant means the compiler can't unroll it, so it will have a performance impact. But since it's uniform across all shader invocations, it shouldn't hurt too much (plus, it's only running once per frame).

Edit: Wonder if we should considering using spirv-cross for this and other post-processing type shaders. Would save writing them multiple times..

stenzek avatar Jun 30 '23 03:06 stenzek

Edit: Wonder if we should considering using spirv-cross for this and other post-processing type shaders. Would save writing them multiple times..

Would that mean auto Metal shaders? Cuz that would be worth it.

KrossX avatar Jul 03 '23 17:07 KrossX

Alright, now that Metal side seems to be working (thanks Macjestic) this is no longer WIP.

KrossX avatar Jul 03 '23 23:07 KrossX