crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come)
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
Just to clarify now that you got to the bottom of the issue. Using Dank's script with a tolerance below 25 yields the same results as your script or if the results are different and you do end up using a 4:3 display your script might come in handy.
There's a small difference. My script will always keep the viewport within the bounds of the display, whereas Dank's may in some circumstances allow it to overspill a little in order to use more screenspace.
I don't know if I am over simplifying but I keep thinking modern displays have pretty much a square pixel aspect ratio so really you can only calculate using the DAR and discard the PAR information which will always produce some squishing in one of the dimensions?
For most displays, this is true. For a 1280 x 1024 display that's nominally 4:3, it's not though.
According to Dank, his script does effectively use the DAR, meaning that there shouldn't be squishing. Or to put it a different way, the scaling will be different for each axis as needed to ensure the aspect ratio as displayed matches the game aspect ratio as it would have been displayed.
There are a couple of tests you could do if you want to validate that things are working as expected;
- Check in the resolution_db that the script uses to see what the game resolution and aspect ratio are (pick a game or two that you play)
- Check the game's <name>.cfg file to see what the viewport height and width are set to, and check that they give an aspect ratio close to expected. You can work out the whole number multiples of the game resolution to see whether the next value up or down would give a ratio closer to the game's original.
- You can also measure the game's aspect ratio on your screen (using a ruler or measuring-tape) to validate that it's suitably proportional.
-
the CPS2 fighting games are good examples of this. something like street fighter 2 has a resolution of 384x224, which is a wide image - close to 16:9. however it was on a regular 4:3 CRT just like most other arcade games, so should be 4:3 via the script/emulators.
-
@andrewh said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
Take 1941 for example - its resolution is 384 x 224, which is a ratio of 5.1:3.
How are you calculating the ratio 5.1:3?
Here's the DB entry:
1941, 384, 224,V,R, 810, 1080, 576, 768, 3, 4, 60
Working through your example 1941. 384x224 with a ratio 5.1:3 on a display 1600x1200. Did I miss something or does that look correct? I am just working through an example more for better understanding.
pixelSquareness = (384 / 224) / 1.7 = 1.00 gameHeight = 224 * 1.00 = 224 vScaling = 5.36 hScaling = 4.16 intScaleFactor = 4 viewportWidth = 896 viewportHeight = 1200 viewportx = 704 viewporty = 0
-
@riverstorm I am just following along here, and I think your example looks good to me. For this one, you found the integer scaling of 4 will get you to 896 for the width. At a vertical of 1200, perfect 3:4 would have been 900, so fudging it just four pixels puts this game at a perfect integer in the X dimension. This is about as good as you can get. In other words, you have maximized the use of the display vertically, while preserving integer scale horizontally, all while trying to approximate a 3:4 AR for a game whose PAR is not 1:1. However, wouldn't the viewportx be 352? I thought you would take the display width minus the game width, and split that in half to center the viewport.
-
This game is harder on a 1280x1024 display, since a factor of 4 would be squished too much to fit into 1024 (about 17% distortion), and a 3 factor would stretch too high. It becomes somewhat subjective. In this case, the game would be stretched 128 vertical pixels beyond 3:4. That's 14% vertical distortion. This game is unfortunate because it falls very far from ideal either way. Obviously a 3 factor is better, but it might look too narrow. Still, it might be better than 64 pixel black bars on the top and bottom.
Sometimes, we have to take a subjective look and decide if it makes sense to preserve the look of a shader at the expense of a wonky AR. How much final distortion can you endure to preserve x-axis integer scaling before you simply add some black bars to the bottom and top? I wonder how many of us cared when the CRT was not tuned properly to fill the width and height? I expect we all played the arcade games when this was true and didn't even realize the AR was off!
-
@caver01 said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
However, wouldn't the viewportx be 352? I thought you would take the display width minus the game width, and split that in half to center the viewport.
Ooops....yes I missed the /2! :)
Do you know how the 5.1:3 ratio is derived from the data above for 1941? That's the one piece I am missing.
This game is unfortunate because it falls very far from ideal either way.
Wow, almost smack dab in the middle. That's where you start expanding the script to make exceptions for thresholds beyond a certain percentage or pixel count. Hmmm...black borders or strreeetch!
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
Do you know how the 5.1:3 ratio is derived
I think it is an approximation to simplify the ratio to get 1.7 like you noted. 384/224 is about 1.7, and 5.1/3 is exactly 1.7.
-
@caver01 said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
I think it is an approximation to simplify the ratio to get 1.7 like you noted. 384/224 is about 1.7, and 5.1/3 is exactly 1.7.
Ok, that makes sense. Even rounded out it still carries a zero out to the thousandths.
How does Dank's example work when it's using the same width x height. Is this a really "skewed" PAR to pull off a 16:9?
something like street fighter 2 has a resolution of 384x224, which is a wide image - close to 16:9. however it was on a regular 4:3 CRT just like most other arcade games, so should be 4:3 via the script/emulators.
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
Wow, almost smack dab in the middle. That's where you start expanding the script to make exceptions for thresholds beyond a certain percentage or pixel count. Hmmm...black borders or strreeetch!
Actually, the subjective decision is, black borders, stretch one way, stretch the other way, or simply live with a little bit of rainbow lines.
For me, I might live with some distortion, as I hate the rainbow lines, but I also like curvature which has its own problems with moire patterns and a lot of this careful scaling goes out the window.
Most vertical games for my setup end up in tate mode for me which introduces the same problems, just a different target display. It all becomes subjective on my box.
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
How does Dank's example work when it's using the same width x height. Is this a really "skewed" PAR to pull off a 16:9?
I think the current era of widescreen TVs have done more to confuse people about how a game like Street Fighter II is supposed to look. In his example, this is a game whose PAR is not at all square. It was programmed at a seemingly widescreen AR, yet people forget that the target display for these games was always a 4:3 CRT monitor. That meant that a technician setting up the actual cabinet would probably turn a tuning knob to stretch the game to fit into the 4:3 screen, even though the pixels would change shape. In doing so, however, the character proportions are restored. In other words, the artwork in the game would be put back to "normal", since it was created with distortion to begin with knowing it would be tuned back to 4:3.
Research might reveal why a game like this was created with such a wide AR, but I would expect there are good reasons for doing so. It might be memory limitations, or an opportunity to maximize resolution in at least one dimension over another. Who knows. It's actually not unlike a cinematographer using an anamorphic lens to capture a wide image to the full size of a 35mm negative, even though it will be projected in a different AR. What we have in SF2 is a distorted game as programmed, designed to be stretched back to 4:3. The fact that the programmed distortion is close to a widescreen TV AR is a coincidence.
A game like Blasteroids is even more severe if I remember correctly.
-
my script gets as close as it can to the DAR always. so for sf2 it doesn’t care about the aspect ratio of the pixels (~16:9), only the aspect ratio of the screen (4:3).
check out my zip downloads in original post - the cfgs for sf2 will be as close to 4:3 as it can get. no one wants a fat Ryu.
-
@andrewh said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
In @AndrewH script he has these lines:
pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
pixelSquareness = (384 / 224) / 1.7 = 1.00
I think it is an approximation to simplify the ratio to get 1.7 like you noted. 384/224 is about 1.7, and 5.1/3 is exactly 1.7.
Is it coincidental that this work out to 1? It seems (gamewidth/gameheight) & aspectratio need to be from two different sources or the division will always be 1 which I thought the point was 1941 doesn't use square pixels.
I don't know if I am using incorrect numbers by dividing 5.1/3 but I don't see where the exact ratio 5.1:3 is coming from and the math (probably incorrectly) shows it to be a square pixel if I understand it correctly.
1941, 384, 224,V,R, 810, 1080, 576, 768, 3, 4, 60
no one wants a fat Ryu.
For sure, in the black suit we have Rotund Ryu! :)
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
In @AndrewH script he has these lines:
pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
I don't think
aspectRatio
here is the calculated value you have. It has to be either the target AR which is should be 4:3 or the AR of the scaled viewport that uses x-axis integer scale and Y display height. Otherwise, yeah, it would always be 1. -
@caver01 said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
It has to be either the target AR which is should be 4:3 or the AR of the scaled viewport that uses x-axis integer scale and Y display height.
Maybe @AndrewH can clarify where that value comes from. I don't think it would be the latter as it's needed to calculate gamewidth or gameheight depending on the orientation.
-
How are you calculating the ratio 5.1:3?
So, @Riverstorm sorry about any confusion caused.
384/224 = 1.7143 (or a ratio of 1.7143:1)
That's the same as (1.7143 *3) : (1 *3) , or 5.143:3 (rounded to 5.1 for the sake of the post)
I just wanted to represent it as a <something>:3 ratio, to show how it compared to the screen aspect ratio, which is 4:3Your working through the example is not exactly correct - the aspectRatio value is taken from the DB entry - the 10th and 11th entries respectively are the Game Screen Aspect Ratio (just titled aspectRatio in the script). So, it should be more like this (for 1600 x 1200 screen) ;
1941, 384, 224,V,R, 810, 1080, 576, 768, 3, 4, 60
pixelSquareness = (224 / 384) / (3 / 4) = 0.77778 # We've swapped width and height because it's a vertical game gameHeight = int(384 * 0.77778) = 298 # This is the pixel height if we had a real 4:3 ratio. You can also calculate it just by multiplying 224 by 4/3 vScaling = 1200/298 = 4.02 # How many times taller is the screen than the game (with corrected pixel size)? hScaling = 1600/224 = 7.143 # How many times wider is the screen than the game? intScaleFactor = 4 # Take the integer value of the lower scale value viewportWidth = 224 * 4 = 896 viewportHeight = 1200 viewportX = 352 viewportY = 0
-
@caver01 said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
In @AndrewH script he has these lines:
pixelSquareness = ((gameWidth/gameHeight)/aspectRatio)
I don't think
aspectRatio
here is the calculated value you have. It has to be either the target AR which is should be 4:3 or the AR of the scaled viewport that uses x-axis integer scale and Y display height. Otherwise, yeah, it would always be 1.Yes - it's the Aspect Ratio from the DB file, which is the 10th and 11th entries on the line (they're indexed from 0, which is why it's [9] and [10] in the code.
aspectRatio = int(gameInfo[9]) / int(gameInfo[10])
-
@AndrewH I thought so. It seems you happened to find a few examples where Dank's script overlooked a better viewport because sizing up one more was still within the 25% tolerance. I probably just restated when you wrote originally. There may be some sweet spot tolerance levels to avoid this situation, but I think it will depend on the games and the resolutions of our displays.
-
@AndrewH Ah, thanks for the clarification. One question if I am understanding what you're doing is pixels are added or subtracted depending on the pixelsquareness to compensate for the PAR into the final resolution? To me that's the only way say for example a 16:9 PAR (not resolution) fits a 4:3 DAR and still looks correct? Not sure how to word it.
I'm trying to wrap my head around how modern displays being square pixels but still compensate for odd PAR's and the image still looks correct unless the emulator is somehow making additional "corrections".
-
@riverstorm said in crt-pi shader users - reduce scaling artifacts with these configs in lr-mame2003, lr-fbalpha, lr-nestopia (and more to come):
@AndrewH Ah, thanks for the clarification. One question if I am understanding what you're doing is pixels are added or subtracted depending on the pixelsquareness to compensate for the PAR into the final resolution? To me that's the only way say for example a 16:9 PAR (not resolution) fits a 4:3 DAR and still looks correct? Not sure how to word it.
Yes - pretty much.
For vertical games, the goal is to keep the width unchanged (since this is the one we want integer scaling on), and recalculate the height in order to 'correct' the PAR to fit the DAR of 3:4 )
For horizontal games, the goal is to keep the height unchanged and recalculate the width before proceeding to work out the scale factor to be applied.
I'm trying to wrap my head around how modern displays being square pixels but still compensate for odd PAR's and the image still looks correct unless the emulator is somehow making additional "corrections".
I presume there are some similar calculations going on in the background unless overridden by these .cfg files.
Speaking of modern displays having square pixels - they almost all do, apart from 1280 x 1024. That's a ratio of 5:4, but on a 4:3 screen. -
In case anyone's still interested, here's a worked example for Street Fighter 2, which also has an odd PAR, as noted above:
From resolution_db
sf2,384,224,H,R,1440,1080,1196,896,4,3,60
pixelSquareness = (384 / 224) / (4 / 3) = 1.285714 gameWidth = int(384 / 1.285714) = 298 # This is the pixel width if we had a real 4:3 ratio. You can also calculate it just by multiplying 224 by 4/3 vScaling = 1200/224 = 5.357 # How many times taller is the screen than the game (with corrected pixel size)? hScaling = 1600/298 = 5.369 # How many times wider is the screen than the game? intScaleFactor = 5 # Take the integer value of the lower scale value viewportWidth = int(298 * 5.369) = 1596 =~ 1600 # Round up to 1600, since it's less than 10 pixels smaller than the screen width viewportHeight = 224 * 5 = 1120 viewportX = 0 viewportY = 40
In this example the pixelSquareness works out as the reciprocal of that for 1941. So the recalculated game width ends up the same as the recalculated game height for 1941.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.