Tuesday, December 20, 2011

Cg Pixel Shaders for SSNES


Update (11/08/2012): New shaders added to the end of the post.

In addition to XML/GLSL pixel shaders, SSNES also supports pixel shaders written in Nvidia's proprietary Cg shader language, which is similar in syntax to Microsoft's HLSL language. While Cg hasn't been a very popular language for shaders, historically, many new shaders have been written for use with PS3 homebrew, where Cg is the only supported shader language. In fact, these shaders were downloaded from TwinAphex's SNES9x Next source code repository.

Another benefit to the Cg shaders is that they work with both OpenGL and Direct3D drivers in SSNES, which makes many of the more modern shaders to available to people with poor OpenGL performance for the first time.

As with my previous shader posts, these images were captured at a 3x scale factor, then enlarged using nearest neighbor to 400% for the detail shot. Click the thumbnails to embiggen.

5xBR+CRT

This shader combines Hyllian's 5xBR algorithm with the phosphor-derived scanline shader from Caligari with great results. This shader is designed for use with square, non-aspect-corrected pixels, so be sure to use an 8:7 aspect ratio on SNES to avoid any nasty artifacting. It also expects at least a 5x scale factor, which looks like this:

Here are a few more pictures from the GBA version of Final Fantasy 6 and Street Fighter 3: Third Strike on FBA:

I find the scanlines make text easier to read than with 5xBR alone, for whatever reason.
Download the xBR pack from Hyllian here.

Retro

This shader accentuates the individual pixels by adding a cool, beveled look along with some color-tweaking mojo to give them a feeling of depth. Again, it expects non-aspect-corrected images, or else subpixel aliasing effects will make a mess of things.

Here's another picture at 20x (5x scale factor, enlarged 4x with nearest neighbor; see it full size to get the full effect):


Notable ports from the XML shader family include cgwg's CRT shader, Themaister's dot-n-bloom (listed as 'dots.cg') and Waterpaint shaders and an extremely fast implementation of bicubic filtering (bicubic-fast.cg) from Hyllian, as well as all the classics, such as HQ2x, SuperEagle and so on.

Update (11/08/2012)

CRT-ReverseAA

Hyllian has been working on some interesting shaders lately, including an implementation of Christoph Feck's "reverse anti-aliasing" algorithm, which allows for some very sharp, smooth upscaling. It works on any image but really shines on digitized images with lots of gradients (think: SNES games with digitized sprites or games with prerendered backgrounds, like Resident Evil or Final Fantasy 7). It's also particularly good at rendering legible text, so it's great for RPGs, as well. Here are some images of this shader paired with some scanlines:
 As you can see, Clay Fighter looks really great with this shader. Too bad the game is godawful.

bsnes-gamma-ramp

As with pretty much everything else, bsnes has taken some sophisticated steps to achieve an authentic gamma ramp that reflects the actual appearance of games. Themaister was kind enough to reproduce the relevant code in Cg form. This is how it looks:
He also wrote a cgp file (just a simple file that tells RetroArch how to deal with multiple Cg shaders) that will enable pixel blending used in pseudo-hires transparency, which bsnes-derived emulation cores typically render as a series of vertical stripes instead of the intended translucent color. You can download the bsnes-gamma-ramp+hires blending bundle here.

LCD3x

A simple, fast scanline shader from Gigaherz, LCD3x is intended to evoke the look of handheld console LCD displays:
It's also a very easy shader to customize, if you want darker scanlines or to brighten the overall image. These variables are located on lines 12 and 13 of the shader, respectively.

I'll add more shaders and more pics in the near future.

12 comments:

Anonymous said...

where did you get sf3 third strike
for the pc?

Hunter K. said...

It's a ROM being played through an emulator, specifically Retroarch's FBA core.

Anonymous said...

Where can I find thsi "Retro" filter? Is that the correct name? Thanks

Hunter K. said...

Yep, that's what it's called.

I think you can get it from the "common-shaders" archive on github:
https://github.com/libretro/common-shaders

but I also have it in my mediafire repo:
http://www.mediafire.com/?jdu3z112k5rp66h

Anonymous said...

Thanks a lot. I tried to google it but failed.
Now I realise that there are more articles in your blog about filters and shaders. I could have just read them but I was too stupid.

Hunter K. said...

No worries, dude. I'm happy to answer questions. :)

Anonymous said...

Sorry to ask this again, I realize now this was the specific post that caused me to wonder...

In your 5xbr + CRT example (5xBR%252BCRT.png), the scanlines are much lighter than what I see on my rig from 5xbr shaders ouf of the box. Are these really the original unaltered shaders?

I downloaded the xbr pack from your mediafire space, and my scanlines are pitch black.

Hunter K. said...

Yeah, those were the raw, unmodified shaders. However, when I load them up now, they look a lot darker, so something may have changed in the way they're rendered or something. Nevertheless, those xBR+CRT shaders should have a #define for SPOT_HEIGHT that you can use to lighten the scanlines. A value of 0.6 or 0.7 should get you close to my screenshots.

Anonymous said...

It seems my mistake was using standalone Bsnes instead of Retroarch. I finally got Retroarch this afternoon, and while it took a ton of tinkering to figure it all out, it was well worth it.

Basically I discovered I could get the soft scanline effect I wanted by running 5xbr-4.0 with NTSC Gauss Pass over top. I never would have figured this out using raw Bsnes, since you can only run 1 shader at a time that way. Glad I got my head out of the sand!

Anyway, thanks for posting so much info about these shaders. Were it not for your blog I never would have discovered their wonderful potential.

Hunter K. said...

Hey, I'm glad to hear you got it going :)

Higan (bsnes) v093 has support for multipass shaders now, but the selection is smaller and the process for combining them is significantly different.

RetroArch definitely has a learning curve, but I totally agree that it's the program of choice for emulator power users.

Gnalvl said...

Ok, so new question...How do you get 3rd Strike running on RetroArch? It took a lot of digging for all the right files, but I finally got it running on standalone Fireburn, so it really makes no sense to have Retroarch crash when I try to load it (using the Fireburn core, obviously).

Hunter K. said...

@Gnalvl
Using the latest "megapack" fba core, I'm able to load sfiii3.zip with this sha1 checksum:
38f5b00f3b13322307b4c7a65ce4b90fa7089ed1

Analytics Tracking Footer