Fractional Bilinear Interpolation
Moderator: Moderators
Re: Fractional Bilinear Interpolation
I spent a few minutes trying to fix it, but didn't have much luck. I'll try again later. In the meantime, here's a comparison of the two shaders in scale mode:
pixellate
fbi
pixellate
fbi
get nemulator
http://nemulator.com
http://nemulator.com
Re: Fractional Bilinear Interpolation
According to that screenshot, pixellate is equivalent to FBI with an interp_adjust_y equal to 0.5, that is, full nearest-neighbor vertically.
Some level of blurring is unavoidable unless you redraw everything as vector graphics.
Some level of blurring is unavoidable unless you redraw everything as vector graphics.
Re: Fractional Bilinear Interpolation
Yeah, I believe the reason pixellate works that way is that higan tries to maintain even multiples in scaling by default.
It is primarily meant to help ease the pain of aspect ratio correction, which is done by changing only the width of the image.
If I recall, SNES Mega Man's energy bar was always the most extreme example of the downside of vertical interpolation. Damn near impossible to make that thing look nice at arbitrary scale factors. And yes I'm aware you could rotate that energy bar 90 degrees and have the same issue with horizontal interpolation (and you could correct aspect by stretching only the height by an uneven multiple.)
It is primarily meant to help ease the pain of aspect ratio correction, which is done by changing only the width of the image.
If I recall, SNES Mega Man's energy bar was always the most extreme example of the downside of vertical interpolation. Damn near impossible to make that thing look nice at arbitrary scale factors. And yes I'm aware you could rotate that energy bar 90 degrees and have the same issue with horizontal interpolation (and you could correct aspect by stretching only the height by an uneven multiple.)
- mikejmoffitt
- Posts: 1353
- Joined: Sun May 27, 2012 8:43 pm
Re: Fractional Bilinear Interpolation
One thing doesn't look right in both; it gets dark between the left edge of mario's hat and the background green.
Re: Fractional Bilinear Interpolation
Hah, I wonder if that's due to not converting to a linear RGB space before mixing.
Re: Fractional Bilinear Interpolation
The TVs of the time didn't convert to a linear RGB space either.
Re: Fractional Bilinear Interpolation
I didn't think we were simulating TVs here. I thought we were trying to expand a hard-edged pixel image to a non-integer scaling without some pixels being one unit wider/taller than others. When two different-color pixel edges fall next to each other and there's no mixing, it should look similar to when two fall half way across an output pixel such that they are mixed half and half. If this mixing is done in sRGB, the mixed version will look overly dark, which I think is what is happening here.
EDIT: indeed, that was the cause of that unexplained darkness (darker is naive mixing, lighter is correct mixing):
EDIT: indeed, that was the cause of that unexplained darkness (darker is naive mixing, lighter is correct mixing):
Re: Fractional Bilinear Interpolation
mikejmoffitt wrote:One thing doesn't look right in both; it gets dark between the left edge of mario's hat and the background green.
Thanks, guys. Fixed in the WIP version of nemulator.blargg wrote:If this mixing is done in sRGB, the mixed version will look overly dark...EDIT: indeed, that was the cause of that unexplained darkness (darker is naive mixing, lighter is correct mixing):
get nemulator
http://nemulator.com
http://nemulator.com
- mikejmoffitt
- Posts: 1353
- Joined: Sun May 27, 2012 8:43 pm
Re: Fractional Bilinear Interpolation
Fortunately, we're discussing scaling and filtering algorithms, not how televisions displayed. What a television does is absolutely irrelevant here.tepples wrote:The TVs of the time didn't convert to a linear RGB space either.
As long as we're mentioning TVs, though, it should be pointed out that a lot of televisions do seem to implement this incorrect edge mixing that produces dark borders when any upscaling is being performed.
Re: Fractional Bilinear Interpolation
Hey James, thanks for this!James wrote:Thanks, guys. Fixed in the WIP version of nemulator.
Would you be kind enough to open source your shader + the latest fixes so that I can see it gets ported to Cg and other formats for cross-platform use in OpenEmu or RetroArch?
There's a pretty good community built around the Cg format (https://github.com/libretro/common-shaders) and your shader looks very nice.
Re: Fractional Bilinear Interpolation
Hi clobber,
re: sRGB stuff -- that fix is implementation dependent. You can specify that your texture and back buffer are in sRGB color space and let DirectX/OpenGL handle the conversion to/from linear color space. I don't think you can fix this within the shader itself unless you write your own texture sampler.
Thanks!clobber wrote:your shader looks very nice.
Sure. I've updated the code in the first post of this thread. Have at it.clobber wrote:Would you be kind enough to open source your shader
re: sRGB stuff -- that fix is implementation dependent. You can specify that your texture and back buffer are in sRGB color space and let DirectX/OpenGL handle the conversion to/from linear color space. I don't think you can fix this within the shader itself unless you write your own texture sampler.
get nemulator
http://nemulator.com
http://nemulator.com
Re: Fractional Bilinear Interpolation
I know nothing about shaders, but if you can apply a power function (gamma), do 2.2, mix, then 1/2.2. This will work for sRGB. If things are calculated in more than 8 bits per component, this won't cause any banding.
Re: Fractional Bilinear Interpolation
Yeah, this is what I was referring to when I said you'd need to write your own texture sampler. If you wanted to do this, you wouldn't be able to use the built-in linear sampler because you can't modify the pre-interpolation values. You'd have to point sample the texture, apply gamma corrections, and manually interpolate.blargg wrote:if you can apply a power function (gamma), do 2.2, mix, then 1/2.2.
get nemulator
http://nemulator.com
http://nemulator.com