MiSTer-devel / Filters_MiSTer

Custom Filters for MiSTer's HDMI Scaler
36 stars 12 forks source link

Introduction

If you use MiSTer you should be using a custom filter for upscaling if you want high quality without uneven scaling and shimmering during scrolling.

The MiSTer Filters and Gamma Github repository is here: MiSTer Filters and Gamma Github

As of November 2018, MiSTer can use custom filter coefficients to define the interpolation used for scaling over the HDMI output (and VGA too with a mister.ini option). This allows MiSTer to scale images using well-known image scaling algorithms such as bicubic or lanczos scaling as well as other scaling methods better suited to scaling pixel graphics. Special effects such as scanlines and lcd effects are also possible.

This github repository houses all of the Interpolation Filters that have been created so far for MiSTer: MiSTer Filters/Gamma Github Repository

As of November 2019 this github also contains Gamma Lookup Tables to allow MiSTer apply a gamma curves to cores with an updated framework. James-F has created a number of curves that are included in the Gamma folder of this repository.

How to use filter coefficients and gamma tables

To use any of the pre-made filter coefficients (or your own) you need:

Filter Releases are here: MiSTer Filters/Gamma Release Folder

Once you have updated MiSTer and Cores and your filter/gamma coefficients in the right place you simply

Frequently Asked Questions

Q: What filters should I use?

A: Use "Interpolation (Sharp)" and "SNES Interpolation (Sharp)" if you don't care for scanlines and just want good interpolation.

But all of the filters Filters root are "Recommended Filters". So Interpolation (Sharp), Scanlines (Sharp), Scanlines (Soft), Vertical Scanlines (Sharp), Vertical Scanlines (Soft), LCD (Monochrome), and LCD (Color) are good defaults for most MiSTer cores.

Q: Why would I want to use custom filter coefficients?

A: The default scaling algorithm of MiSTer is Nearest Neighbor/Lanczos and is not ideal for upscaling pixel graphics. The filters allow much better looking scaling and special effects such as scanlines.

Q: Doesn't MiSTer already have scanlines through the "Scandoubler FX" option in the OSD?

A: Yes, but the scanlines available with "Scandoubler FX" are aligned to the scandoubled image and the scanlines through the filter coefficients are aligned to the original pixels in the scanline. So you achieve better scanlines with filter coefficients in most cases.

Q: Where do I get sets of Filter Coefficients or Gamma LUTs?

A: Here. Or the update script which will get them from here. This is the official place to get these filters as of Dec 03, 2018

Q: Why are some filters labeled "SNES"?

A: MiSTer's SNES core outputs a 512 pixel wide image even when the SNES is in it's 256 pixel wide mode. This makes the horizontal interpolation too sharp. The SNES specific filters take this into account.

Q: What do some filters have "NN" appended to the name?

A: Some people set MiSTer to scale to do integer scaling for the vertical upscaling (by setting vscale_mode=1 in mister.ini). If you do this you can use the "NN" filters that only enable interpolation for horizontal scaling.

Q: Where is a filter that does XXXXX?

A: Check the subfolders for many filters. Only a few are in the Filters root folder to make choosing a filter easier for newbies and non-technical people. But there are many more to choose from.

What do some filters look like?

The Filters folder contains a set of recommended filters for general use. There are samples in the Samples folder of this repository. View these images at full size to make a proper evaluation.

All screenshots below are from the Polyphase Previewer App that copies MiSTer's algorithm for scaling. You can try it out with emulator screenshots to see what ouput MiSTer will produce: Polyphase Previewer Github and Polyphase Previewer Releases

Interpolation (Sharp):

Interpolation (Sharp)

Scanlines (Sharp):

Scanlines (Sharp)

Scanlines (Soft):

Scanlines (Soft)

LCD Effect (Monochrome):

LCD Effect (Mono)

LCD Effect (Color):

LCD Effect (Color)

Vertical Scanlines (Soft):

Vertical Scanlines (Soft)

Technial Information

The commercial VIP scaler implements a generic 4 tap, 16 phase polyphase filter. The open source ASCAL scaler that MiSTer uses now implements the same type of filter for scaling. Details are on page 189 of the VIP scaler docs here: Intel VIP Scaler Doc

The Zipcores Application Notes pdf explains the workings of the filter much better than the ALtera/Intel docs: Zipcores Application Notes

Most of the currently available filter coefficients were generated with the Matlab code here: https://github.com/ghogan42/Filter-Coefficients-For-MiSTer

Tips for understanding the MiSTer filter coefficient text files:

Sample Coefficient Set. Note the following:

# range -128..128
# sum of line must not exceed the range!

# Sharp Bilinear on x-axis and y-axis
# 40% Scanlines on y-axis

# horizontal coefficients
   0, 128,   0,   0
   0, 128,   0,   0
   0, 127,   1,   0
   0, 125,   3,   0
   0, 120,   8,   0
   0, 112,  16,   0
   0, 101,  27,   0
   0,  85,  43,   0
   0,  64,  64,   0
   0,  43,  85,   0
   0,  27, 101,   0
   0,  16, 112,   0
   0,   8, 120,   0
   0,   3, 125,   0
   0,   1, 127,   0
   0,   0, 128,   0

# vertical coefficients
   0, 128,   0,   0
   0, 126,   1,   0
   0, 116,   5,   0
   0, 102,  10,   0
   0,  86,  16,   0
   0,  71,  21,   0
   0,  57,  26,   0
   0,  46,  31,   0
   0,  38,  38,   0
   0,  31,  46,   0
   0,  26,  57,   0
   0,  21,  71,   0
   0,  16,  86,   0
   0,  10, 102,   0
   0,   5, 116,   0
   0,   1, 126,   0