Welcome!

Final Burn Neo => FBN Development => Topic started by: gausen on November 16, 2015, 01:58:47 PM

Title: New stretch option for FBA!
Post by: gausen on November 16, 2015, 01:58:47 PM
Hi all. I've added a new stretch option in FBA. As you know regular stretch options are:
Normal stretch (no aspect correction).
Full stretch (no aspect correction, fullscreen coverage).
Correct aspect ratio (obviously is aspect corrected but only produces integer scaled graphics [great quality]).

The new stretch option is:
Correct aspect ratio stretched (which is aspect corrected but stretched so only horizontal or vertical black bars are visible. Never both).

Modified source code is attached. I've tested a few games with different blitters in two pc's and seems to work ok, though more testing is needed. Use at your own risk.

Best regards.
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 02:03:32 PM
Thanks for your contribution, I will check it out soon :)
Title: Re: New stretch option for FBA!
Post by: iq_132 on November 16, 2015, 02:25:54 PM
Ooooh! That's cool!
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 02:42:17 PM
Thanks for your contribution, I will check it out soon :)
Ooooh! That's cool!

Thanks for dropping by guys!  :biggrin:
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 03:16:46 PM
*after compiling* This is friggin' great!! :D
good job buddy :)
it shall be merged.

best regards,
- dink
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 03:28:23 PM
an idea I want to implement, or try as a slight modification to your excellent enhanced stretching code - to preserve the scanlines.  When scanlines are enabled, it looks horrible in fullscreen mode or at some sizes, because some pixels are different sizes than others (guessing) - and it creates somewhat of a moire effect.  Ideas?  :S 
Title: Re: New stretch option for FBA!
Post by: iq_132 on November 16, 2015, 03:36:09 PM
Would you mind posting some screenshots for me?
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 03:48:27 PM
I have noted this too. Right now I can think of two routes, one is to read FBA source to learn how scanlines are passed (so something could be made at scanlines level). The other route is to make some new scanline algorithm more suited for dealing with pixel distorsion.

I don't know if this is completely solvable for sharp pixels. Perhaps some new scanline algorithm applied on a bi linear filtered image (or any other scaling that produces even pixels for that mater) could be a better solution.

I will start looking into this. May take me some time to have something to show you.

EDIT: It's possible to take screenshots from FBA with effects applied? (F12 is capturing an unaltered raw image).
Title: Re: New stretch option for FBA!
Post by: iq_132 on November 16, 2015, 04:29:34 PM
ALT+PRINT SCREEN. Though a screenshot w/filters option would be nice.
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 04:41:41 PM
Some screenshots here. From what I'm reading FBA have a different scanlines implementation for each blitter.

EDIT: Added a few shots with 2xPMHQ and w/o scanlines.
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 06:39:58 PM
Some new screenshots. Changed the way ZoomFactors are calculated.
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 07:39:01 PM
nice! :)  ...code pls! :)
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 08:14:52 PM
nice! :)  ...code pls! :)

Sure thing! Here it is. It's only a modified D3D blitter. Should improve scanlines look for full stretch as well. I'm sure this can be further tweaked. For completeness similar changes should be made to all blitters.
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 08:16:21 PM
Thanks, luckily the d3d blitter is the one I use :D
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 08:30:42 PM
I tried the updated code, but I'm still getting a bit of a moire effect in windowed, in fullscreen its not as noticable, but you can tell its there.  Is there any way around this?
(click the images to make them bigger first)
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 08:32:47 PM
On second thought, is there any way to force the scaling engine to make sure every pixel is the same width?
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 09:54:03 PM
On second thought, is there any way to force the scaling engine to make sure every pixel is the same width?

Not possible really. Non-integer stretching does produce inaccurate data. It's posible to use some softfx filters with scanlines for a quick palliation, haven't tried that though. It should be possible to upscale to a bigger integer resolution and then downscale from that. This way should produce better sized pixels.

On the other hand I believe that changing the way the scanlines are generated is still a viable option.

Your pictures really show a lot of moire. I have attached a similar picture, try disabling both pre-scaling options for the blitter.
Title: Re: New stretch option for FBA!
Post by: dink on November 16, 2015, 10:38:59 PM
While improved, I still couldn't imagine scanlines looking like that.  hmm, I've been wanting to come up with a good idea for a long time now.  maybe, apply the scanlines after resizing? hmmm.. well, I don't mean to derail your thread, what you've done is really nice.  my quest, otoh, is sort of a personal one.

best regards,
- dink
Title: Re: New stretch option for FBA!
Post by: gausen on November 16, 2015, 10:48:10 PM
There a lot of ways of sorting this up. But I will avoid those that take lots of work (like writing a new blitter). Don't lose hope just yet, while the non integer scaler could do fine I never thought of this scanlines as a final product. I'm working on something, if it comes to fruition you will be the first to know  :wink:.

EDIT: I might have found something, it's far from usable but eventually it will work (screenshots attached). Made the scanlines few and fat to make them more noticeable. Going to bed now, it's 1:10 am here.
Title: Re: New stretch option for FBA!
Post by: gausen on November 17, 2015, 05:32:56 AM
Updated D3D blitter. Still WIP. Vertical scanlines don't look so good.
Title: Re: New stretch option for FBA!
Post by: dink on November 17, 2015, 07:23:05 AM
That's quite an improvement, nice! :)
Title: Re: New stretch option for FBA!
Post by: Romhack on November 17, 2015, 07:25:15 AM
Really nice.
Title: Re: New stretch option for FBA!
Post by: gausen on November 17, 2015, 07:34:26 AM
Thanks! You can give it a shot if you like. All you need is the source from the first post and the updated blitter from my latest post with screenshots.
Title: Re: New stretch option for FBA!
Post by: gausen on November 17, 2015, 11:45:09 PM
Ok, after some more reading I now know a few important things (please forgive my previous and present ignorance).

FBA does have proper non-integer scaling code (it just don't work with scanlines). This changes everything, I'm now working on making this code work with scanlines.

Non-integer scaling w/scanlines doesn't look nice on windows. It's a feature more suited for fullscreen gaming.

So far the issue is related to the texture coordinates passed for scanline textures. I know this because fixing it in the D3D and DX9 blitters greatly improved things (so far all the games tested looked great in fullscreen as long as scanlines are horizontal). Fullstretch also suffered from the same moire when using scanlines. With this partial fix fullstretch is also looking good. Vertical scanlines still looking bad though.

Some screenshots and fresh code attached.




Title: Re: New stretch option for FBA!
Post by: dink on November 18, 2015, 09:19:11 AM
Nice, Looking good :)  I was playing around with MAME earlier, and it seems no matter how the window is resized, the scanlines(H or V) stay perfect.  I was meaning to check out how they do it, but kept getting side tracked.. hehe..

Title: Re: New stretch option for FBA!
Post by: gausen on November 18, 2015, 06:55:03 PM
Nice, Looking good :)  I was playing around with MAME earlier, and it seems no matter how the window is resized, the scanlines(H or V) stay perfect.  I was meaning to check out how they do it, but kept getting side tracked.. hehe..

I'm sure they have a proper solution. They have been rolling for a long time. No surprise you are getting side tracked, you are producing an insanely big amount of fixes and new systems support!  :biggrin:

In the mean time here I have a some new code  ;p. I've added a scanline multiplier in the ini to control the effect. I'm not seeing moire or hatching on any of my screens and scanlines remain solid independently of re sizing.

The default is set to 16x (It works ok and looks nice on my screens). The sweet spot though should be tweaked for each screen I supposed. I've seen moire by setting this number to some crazy value like 512. This time only the D3D blitter was fixed. Give it a try if you like. I'm sure there must be plenty of cases where it doesn't work.
Title: Re: New stretch option for FBA!
Post by: gausen on November 23, 2015, 03:56:36 PM
Posting some progress. First whats on this update:

*Updated DX9Alt blitter (now have proper scanlines with all stretching modes).
*The non integer stretching option.

How does this work?
FBA sets scanlines to the same amount of the limiting dimension. For example in SteetFighterAlpha2 224 scanlines are going to be needed, this requires at least 2x arcade resolution. On lcd/led screens the maximum amount of presentable scanlines is half of the biggest resolution. Exactly fitting scanlines for the screen will be halfMaxMonitorRes / N (with N being an even number). The modified blitter calculates exactly monitor fitting scanlines closest to the emu required scanlines. 

For this blitter you have inaccurate MAME style scanlines for zoom factors smaller than 2. For zoom factors bigger than 2 you have closest to FBA scalines. Obviously for resolutions that are integer multiples of arcade res you have perfect FBA scanlines. Also for zoom factors between 2 and 4 thin FBA scanlines are used while for zoom factors bigger than 4 fat FBA scanlines are used.

Which are the issues?
*I can see slight aliasing/moire/hatching when rezising a window. Somehow fitting the window so that there are no black borders at the sides of the game screen reduces or remove the effect.
* I've seen two fat vertical lines in dig dug on a 1080p fullscreen resolution. Changing the fullscreen resolution completely removes this issue.

EDIT: Attached a bug free d3d blitter. As far as I can test no moire, hatching or aliasing here. Works nice with the new stretch option.

EDIT2: A few more screenshots from the D3D blitter.
Title: Re: New stretch option for FBA!
Post by: gausen on May 08, 2016, 03:26:46 PM
Hi All. I've been working a little more on this. Since I can't find a way to pull an arbitrary stretch while keeping proper scanlines aligned I'm trying a different approach. The option now is an integer overscan, that is incrementing the fitting scaling by one. The aspect ratio and scanlines alignment are conserved at the expense of loosing some lines. The amount of lines lost depends on the monitor and game resolutions. Screenshots are attached for a 1080p resolution.

To use the option it has to be selected in video->stretch and only the Enhanced blitter have been modified to accept it in fullscreen (other blitters will show a blackscreen).

Title: Scanlines are harder than it seems at first blush...
Post by: jan_klaassen on January 16, 2017, 04:21:37 PM
Because apparently I like digging up and flogging dead horses.

There's a reason streching scanlines to arbitrary ratios looks bad -- it's simple math. And you can't make the problem go away, you can only try to mitigate the artifacts. The mitigation strategies you can apply use tend to have tradeoffs. The easiest is to just use higher display resolutions, as that by itself minimises the artifacts.

So that's why FBA enforces integer stretching ratios when using scanlines. It also allows for the use of point filtering when stretching vertically, which makes for even betterer looking scanlines. That said, there are  several new ways of displaying scanlines coming to FBA's DX9 blitter that let you scale them to any ratio you wish. And although they were designed to minimise aliasing, they do still alias. Sometimes clearly so, even at 1080p. You can't beat math...
Title: Re: New stretch option for FBA!
Post by: dink on January 16, 2017, 06:00:08 PM
So true, but I really like this gausen's full screen stretch modes.  I would like to re-add gausen's full screen stretch mode code again sometime when things aren't so busy, and also create an alternate option for chosing it..  gausen - would you please post the latest code?  :)

best regards,
- dink
Title: Re: New stretch option for FBA!
Post by: jan_klaassen on January 16, 2017, 06:49:39 PM
Since pictures speak louder than words, here are a few screenshots straight from a 1080p screen.
Title: Re: New stretch option for FBA!
Post by: gausen on January 17, 2017, 09:07:43 PM
@jan_klaassen
I totally agree, there is no way of perfect fitting scanlines on non integer stretching. That said for larger resolutions the penalty gets reduced.
Integer overscan offers perfectly fitting scanlines for any resolution but loses some lines. In integer overscan lines lost are reduced as resolution increases.
Finally for non integer stretching there is the MAME solution, thin scanlines. These are not accurate but always perfect fitting (even on badly stretched framebuffers).

@dink
Thank you for caring about this. You can find the latest source attached to this message (it's based on source version 29738). If memory doesn't fail me modified files are:
vid_d3d.cpp
menu.cpp
resource.h
scrn.cpp
cona.cpp
interface.h
vid_interface.cpp
vid_directx_support.cpp
app.rc
app_gnu.rc

Title: Re: New stretch option for FBA!
Post by: riccetto80 on December 30, 2017, 05:38:41 PM
Any news about add this stretch option to final burn ufficial release?  :biggrin: