I wanted to play with shaders for improving the look of vector games, but after realizing that currently this isn't implemented, I decided on a different approach: work with raster games and develop shaders that should also work on vector games, if their antialiased vectors were rendered into an offscreen buffer. Then, if I'm lucky, someone more familiar with the MAME codebase will like what they see and implement it.
This work is done using "screen bitmap" shaders, which operate on buffers at the final screen output resolution. First, I use shaders/glsl_plain to render to screen resolution with nearest-neighbor sampling:
![[Linked Image from img156.imageshack.us]](http://img156.imageshack.us/img156/2919/gradiusnearest.th.png)
The next part was the trickiest: simulate the look of OpenGL antialiased vectors. Eventually I came up with
this shader, which seems to mostly work. Without gamma correction, it is the closest approximation to antialiased line drawing:
![[Linked Image from img834.imageshack.us]](http://img834.imageshack.us/img834/5764/gradiusbeamnogamma.th.png)
Adding gamma correction eliminates the unevenness of brightness:
![[Linked Image from img135.imageshack.us]](http://img135.imageshack.us/img135/7554/gradiusbeam.th.png)
Next, I do a 9x9 Gaussian blur. Fortunately this can be separated into two 9-tap filters instead of one 81-tap filter. First,
vertically:
![[Linked Image from img833.imageshack.us]](http://img833.imageshack.us/img833/6790/gradiusgaussy.th.png)
Then,
horizontally:
![[Linked Image from img143.imageshack.us]](http://img143.imageshack.us/img143/7091/gradiusgaussxy.th.png)
I should mention that at each stage, blending is done in a linear colour space, which requires applying gamma and inverse gamma functions at each stage to avoid the loss of precision that would result from storing linear color in an 8-bit intermediate texture.
There are a couple more ways of making this more realistic. First, a CRT's video amplifier has limited bandwidth, so I use a
horizontal Lanczos shader as the last "mame bitmap" shader (which takes the image at emulated resolution as its input and outputs at screen resolution) to slightly smooth the pixel transitions:
![[Linked Image from img825.imageshack.us]](http://img825.imageshack.us/img825/1040/gradiuslanczosx.th.png)
Together with the other shaders, this gives:
![[Linked Image from img651.imageshack.us]](http://img651.imageshack.us/img651/9325/gradiusgaussxyl.th.png)
Finally, since this is in colour, I apply a slot mask overlay with -effect aperture2x4rb:
![[Linked Image from img64.imageshack.us]](http://img64.imageshack.us/img64/3937/gradiusfinal.th.png)
For a vector game, simulating limited bandwidth of the video amplifier probably couldn't be done with just shaders, although this is relatively unimportant.