SDL linear filtering

Discussion of development and patch submission.
Post Reply
Nightblair
Posts: 4
Joined: Tue 24 Jul, 2018 2:51 pm

SDL linear filtering

Post by Nightblair »

When emulating proper 4:3 aspect ratio, I use filtering to prevent oddly shaped pixels. In dosbox this looks fine with normal3x scaler. However in pcem the image is sligtly more blurry which unfortunately gives me a headache after a while.
So I've digged into the code and found that pcem is using SDL library linear filtering to do the job from the base input (if I read the code correctly). Then I've got this idea if the image is integer scaled first to higher resolution with nearest filtering with SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0") and then rescaled to 4:3 format, would the result be better, less blurry?

I've tried to do it myself, however I'm completely unfamiliar with c and SDL2, so I failed.

Do you think the theory is reasonable, though?
Last edited by Nightblair on Mon 30 Jul, 2018 5:45 am, edited 1 time in total.
User avatar
leilei
Posts: 1039
Joined: Fri 25 Apr, 2014 4:47 pm

Re: SDL linear filtering

Post by leilei »

If you were to have actual normal3x in PCem, you'd see this applied as normal6x as PCem properly emulates double-scanned VGA.

Your best bet is a OpenGL 3.0 shader preset of some kind...
Nightblair
Posts: 4
Joined: Tue 24 Jul, 2018 2:51 pm

Re: SDL linear filtering

Post by Nightblair »

It does not neccesarily be like normal3x, but good point with the double scanned mode. If I use the scale function with SDL hinting off, then it might be set correctly.

I've tried some shaders from retroarch but so far no luck with any. Also, for some reason the OpenGL3 mode takes a toll on my processor a lot more than normal opengl mode.
Nightblair
Posts: 4
Joined: Tue 24 Jul, 2018 2:51 pm

Re: SDL linear filtering

Post by Nightblair »

I've just randomly found description of the approach which I wanted to take in pcem: https://www.reddit.com/r/dosgaming/comm ... ng/d6epios

Maybe it will be better described than in my broken English. Now that I know that this is sound approach, I might try again to code this in pcem (but again, with no knowledge in C and SDL).
RealNC
Posts: 16
Joined: Tue 06 Nov, 2018 3:01 am

Re: SDL linear filtering

Post by RealNC »

Can't you switch from linear to nearest? I get that choice in the right-click context menu. Now I don't actually use that, I use an OpenGL 3 CRT shader instead from here:

https://github.com/leilei-/someshaders

But in the "normal" OpenGL mode, I can switch from linear to nearest by right-clicking, then selecting "Video" and then "Scale filtering."

But an OpenGL 3 CRT shader is much better at this, at least if you have a 1440p display. I'm not sure if it works that well at 1080p or lower though. I find that the scanline emulation in the CRT shader actually makes the upscaling and aspect ratio correction look much better, it's not just an aesthetic thing. The shader can also adds slight blur to make it look more similar to how "upscaling" would look on a CRT, but that's optional.

This is how it looks like here, standard VGA text mode upscaled to 1440p, 4:3 aspect corrected:

https://i.imgur.com/7xyw3Es.png

The shader I'm using is "monitor-crt-sxga99.glslp" from the Git repo I linked to above, and I configured it with these values:

Code: Select all

GAMMA_INPUT = 2.300000
RETRO_PIXEL_SIZE = 0.260000
GAMMA_OUTPUT = 1.000000
SHARPNESS_H = 0.600000
SHARPNESS_V = 0.850000
MASK_TYPE = 6.000000
MASK_STRENGTH_MIN = 0.020000
MASK_STRENGTH_MAX = 0.040000
MASK_SIZE = 1.000000
SCANLINE_STRENGTH_MIN = 0.100000
SCANLINE_STRENGTH_MAX = 0.450000
SCANLINE_BEAM_MIN = 0.600000
SCANLINE_BEAM_MAX = 2.000000
GEOM_CURVATURE = 0.000000
GEOM_WARP = 0.000000
GEOM_CORNER_SIZE = 0.000000
GEOM_CORNER_SMOOTH = 500.000000
INTERLACING_TOGGLE = 0.000000
HALATION = 0.040000
DIFFUSION = 0.050000
BRIGHTNESS = 1.050000
MONITORMEASURES = 0.000000
SCANBIAS = 3.280000
VIRTUAL_INCHES = 9.000000
TARGET_INCHES = 12.500000
TARGET_NATIVERES = 8000.000000
However, again, it seems that it doesn't work correctly if you have a 1080p display or lower. It seems anything below 1200 pixels high will not produce the correct result.
Nightblair
Posts: 4
Joined: Tue 24 Jul, 2018 2:51 pm

Re: SDL linear filtering

Post by Nightblair »

I don't have 1440p display, but lower resolution. Nearest is great, but when you want 4:3 aspect correction then it looks like trash on my setup with 1680x1050 resolution: http://i.imgur.com/r1pwra0.png
There is not enough pixels to look good, so this just needs some filtering, sadly the default pcem bilinear filter is giving me headaches because of the blurriness.

But at least now I know why this is not a problem for anyone else when higher resolution is available.
Post Reply