Friday, July 18, 2014

CRT-Royale and 3dfx Shaders

Two fairly new shaders have popped up that are worth mentioning: TroggleMonkey's CRT-Royale and leilei's 3dfx. They're both available in Cg format in libretro's common-shaders github repo, though CRT-Royale utilizes some advanced features that aren't available in RetroArch v1.0.0.2 (the most recent release at the time of this writing).

CRT-Royale is particularly exciting for me because TroggleMonkey managed to overcome some issues with shadow-mask emulation that I thought were totally intractable at current common resolutions (i.e., 1080p). The result is some really great phosphor emulation at reasonable scale factors, along with all of the bells and whistles users have come to expect from CRT shaders, including "halation"/glow, bob-deinterlacing support and curvature, along with a ton of options that are unique to this shader.

I'm not going to cover many of them here because it would take forever to get screenshots and there's not much point when TroggleMonkey has included a very informative README with the code, along with support for RetroArch's new runtime parameter support (so you can see the effect of your changes in real-time). However, I thought the shadow mask stuff was super-cool and deserved some closeups. Here's a shot of the shader with default settings (as always, click to embiggen):

First, we'll look at my favorite effect, the in-line shadow mask (called slot-mask in the code):
This is the same configuration I was shooting for with my PhosphorLUT shader, and you can see that the configuration of the phosphors has that familiar vertical, staggered orientation:
Next, we have the very similar aperture grille:
The main difference between this and the in-line slot mask is that it doesn't have the slight staggering (only really visible in the closeups and at super-huge resolutions). In closeup of the LUT, you can see that it just removes the crossbars between triads:
Last, we have the dot-triad shadow mask (called "shadow-mask-EDP" in the code), which was common on CRT computer monitors:
 As you can see, it looks very similar to the high-res shots I took of my Compaq CRT monitor (from my emulation/TV post). And here's the dot-triad blown up:

The other shader I wanted to show is leilei's 3dfx shader, which tries to mimic the effects of a 3dfx GPU, known for some distinctive dithering among other things. In addition to obvious applications like RetroArch's Quake core, Nintendo's N64 also used a GPU that was very similar to a 3dfx, which makes it appropriate for RA's Mupen64plus core. When run at low-ish internal resolutions and paired with RetroArch's per-texture 3-point filtering, you can get a pretty good approximation of what N64s looked like.

Here are some shots of the shader at 320x240 and 640x480 (i.e., native and double res, respectively):
Native res:
Double internal res:
 As you can see, the doubled res looks significantly sharper, but the scanlines are thinner and less pronounced (and twice as many of them) relative to the native res. I also like native res because it makes HUD/menu items look a little less "pasted-on":
Native res:
Doubled internal res:


Anonymous said...

Maybe a dumb question but how do you remove the curve effect in CRT Royale so it appears flat? I'm not sure what settings to change in the user-settings.h file. Thanks for any help!

Hunter K. said...

It's this bit, starting at line 301:
// Geometry mode:
// 0: Off (default), 1: Spherical mapping (like cgwg's),
// 2: Alt. spherical mapping (more bulbous), 3: Cylindrical/Trinitron
static const float geom_mode_static = 0.0; // range [0, 3]
Setting a value of 0.0 should make it flat.

Anonymous said...


First of all, I like your blog because you mix emulators and image processing, two things that I really like for several years.

Despite the time, only this week I decided to leave the classics like 2xSaL filters, which are very good but end up blurring the image.

I would like something more real, so this week I started using the CRT through the HLSL in MAME. After much work, I think I got good results.

I would then apply good CRT filters on all my emulators.
I found two options: SweetFX and Retroarch.

In SweetFX could also very good and easier results. The problem is that I have to keep adjusting the Resolution X and Resolution Y on every game to be good (according to the author).

But with everything I have read, it seems to me that CRT-Royale in Retroarch is the best choice, so I started using Retroarch today.

But I'm totaly lost! I'm not getting even know where to start, despite having already read the readme and user-defined author!

Could you plz help me?!

Sorry for poor english!
Its not my natural language!

Thx for any help!

Hunter K. said...

First off, you'll have to either compile RetroArch from the git repo or download a newer build that supports the latest shader features. I think lordashram's builds from the libretro forums will do it:

Then, you'll need to download the shader from the common-shaders repo (just download the whole thing using the 'download zip' button on the right-hand side of the page; it's easier than downloading the files one at a time):

Copy the crt/crt-royale folder into the 'shaders' folder in your RetroArch folder. Then, start RetroArch, go to settings > shader settings and then 'select shader preset.' Navigate to the crt-royale folder and choose the crt-royale.cgp there.

Beware: it's a heavy-duty shader and requires a powerful GPU. If you have an intel IGP, be sure to use the crt-royale-intel.cgp instead.

Anonymous said...

thanks for the reply.

I have already installed the latest build of Retroarch and it don't have the crt-royale.

So, I downloaded the complete package from github you linked and unziped the entire crt-royle in shaders folder.
The loaded cert-royale.cgp in Retroarch and nothing happens ...

What I need to do?

Thx in advice.

Hunter K. said...

If nothing happens and no shaders are loaded at all, then it failed to compile the shader. You can see exactly what failed by running retroarch from a terminal using the -v (verbose) switch. I would recommend trying the crt-royale-intel.cgp first, though.

Anonymous said...

Thanks for replies.

If you allow me, I will bother you again.

The problem I had here was that I had not unziped all the common file-shaders, only the crt-royale folder.
So I had some missing files.

Now that this was fixed, I have a new error:
RetroArch [ERROR] :: 8-bit and 16-bit image support are not implemented.
RetroArch [ERROR] Failed to load picture :: ...
RetroArch [ERROR] Failed to load :: lookup textures ...
RetroArch [WARN] :: [GL]: Failed to September multipass shader. Falling back to stock.

RetroArch [ERROR] :: Setting Rgui CGP failed.

I have a core i7 with a Nvidia 660Ti, and trying to use the user-settings-default-nvidia, renamed user-defined.h.

Considering the beginning of this file (about compiling), do I need to install DirectX SDK (2010) and Cg Toolkit 3.1 (with FP40)?
I do not understand when files are compiled using the Retroarch.

I appreciate if you can help me this once.

Hunter K. said...

I guess that build is too old for some of the requirements. Try this one (just replace your current retroarch.exe with this one):

For shaders to compile, you need the cg.dll library in the same directory as RetroArch, which should be the case with any official builds (and lordashram's builds, too).

Anonymous said...

I downloaded and ran. Exe you posted but it did not work because missing dlls.

Then downloaded the latest build of lordashram's ( and
and also updated to the latest versions of all shaders (

Now everything worked perfectly :-)
Thank you very much.

For SweetFX, the user Boulotaur2024 made ​​CGWG port of his CRT algorithm, and improve it to the user can set the resolution X and Y of the input image.
For each game the user may set those resolutions to get pixel perfect, which bothering me a bit.

"That way the CRT shader Should be pixel perfect and not applying the rough and imprecise resolution multiplying coefficient anymore."

This is something that should be done in CRT-Royale, or not to worry about it?

Moreover, if the CRT-Royale is regarded as the best CRT shader, why have not come in the RetroArch builds? It is due to its complexity?

Now I'm playing a bit with the user-settings.h the crt-royale :-)
Thx for your great help! :-)

Hunter K. said...

I'm pretty sure that is only necessary in situations where the shader doesn't have direct access to the actual texture size as a uniform. This isn't a problem with RetroArch, since the shaders have access to that information directly.

It will be included with future releases, it's just very new. I assume lordashram hasn't included it in his (unofficial) builds because he isn't aware of it.

Admin said...

Hi, thanks for sharing about shader.
I saw many of them is very nice to see. Unfortunately, those are only implemented in video game emulator.

Do you know if there are some shader "interpreter" outside the emulator for processing common image format, such as jpg, png, or gif?

If they are present, it will be nice.

Hunter K. said...

Hi Ryan Bram :)
I think the closest you'll get is RetroArch's Image Display core (, which will let you load a static png image as your content/"ROM" and then apply shaders to it. You can then use RA's built-in screenshotting to save the processed image.

It's not perfect, obviously, but it's something.

Admin said...

Thanks for informing me about RetroArch's Image Display.

I look the website and it seems that the software was in source code form. Can you tell me how to use that?

Should I compile it by myself or can I use it inside RetroArch GUI?


Hunter K. said...

You'll have to compile it, but it's very easy. I don't think it has any dependencies at all.

Monroe88 said...

If you're using 64-bit Windows, I made a build of that core for it a while back:

Admin said...

Thanks for your effort.

Sadly, currently I'm using 32 bit OS. I don't have any idea how to compiling the source code by myself.
Maybe I just need to wait for RetroArch developers to release it themselves.


Hunter K. said...

Here's a 32-bit build you can try:

Admin said...

@Hunter K
Wow. Nice!
It will be very useful for me.
Thank you very much for your effort.

Anonymous said...

Is there any way to use these in bsnes ?

Hunter K. said...

3dfx shader could probably be ported to bsnes' shader format without too much trouble, but CRT-Royale uses some features that bsnes/higan doesn't support. The easiest thing to do would be to use the bsnes core in RetroArch.

Anonymous said...


Thanks for informing us about the great crt-royale shader. My question is, if I would like to have thicker scanlines as in a Sony BVM, which settings should I go for in the user-settings.h file? Or is it not possible with this shader?

Hunter K. said...

I would look into user-settings.h, lines 186/187 and 199/200. Dunno if those will do what you want, but I think it's a good place to start.

Anonymous said...


Anonymous said...

It seems like the crt geom shader
is much more suitable for what I'm looking for. I just wish it had a similar shadow mask emulation to crt royale's instead of the dot mask emulation it has.

Analytics Tracking Footer