Woohyun-Kang / Sharp-Shimmerless-Shader

A Sharp, Shimmering-free Shader for RetroArch
49 stars 1 forks source link

Sharp-Shimmerless-Shader

A Sharp, Shimmering-free Shader for RetroArch

The Sharp-Shimmerless shader is a shader which guarantees minimum number of interpolated pixels, i.e., the sharpest rectangular pixels possible, while inducing NO aliasing/shimmering.

Existing Solutions and Their Limitations

There already exist some attempts at achieving both sharp pixels and anti-aliasing, one of them being sharp-bilinear shaders. While they produce reasonably good image on modern high resolution screens, they fall apart on low-resolution screens often found in open-source handhelds.

Below is Cave Story, a 240p game, played on a 320p screen.

Sharp-Bilinear Sharp-Shimmerless Sharp-Bilinear-2x-Prescale

Sharp-Bilinear shader on the left side results in a very blurry image. It is an expected behavior, since what sharp-bilinear shader does is integer pre-scaling followed by bilinear upscaling to screen - when scaling factor is less than 2, integer prescaling would do nothing. Sharp-Bilinear shader becomes a regular bilinear filter.

Sharp-Bilinear-2x-Prescale shader on the right side, at first glance, produces a nice-looking, sharp image. However, when the screen starts to scroll, you can notice vertical lines on the wall are badly shimmering. (Shimmering is also there on Sharp-Bilinear shader, but less noticeable due to the blurriness.)

It is a fundamental limitation for any kind of point sampling approach that it treats each pixel as a point with position but no area, whereas in retro gaming we want rectangular pixels.

Interpolating Pixels as Rectangles

Sharp-Shimmerless shader does not do any kind of point sampling, and instead treats input and output pixels as ideal rectangles, occupying each of their area on the grid that is screen.

It interpolates pixels based on how much area an input pixel would occupy on an output pixel.

Hence, it achieves both minimal number of interpolated pixels and ideal anti aliasing, i.e. NO SHIMMERING!

Subpixel Shaders

rgb and bgr shaders are for horizontal subpixel layouts, and vrgb and vbgr shaders are for vertical subpixel layouts. It supports subpixel rendering by offsetting positions of output pixels per each color.