PhosphorLUT ported to Cg

I ported my PhosphorLUT shader to Cg format and I’m really pleased with the results. It now works pretty decently at normal 5x-ish scale factors and runs a lot faster (still not full speed on my Intel HD4000 but whatever). It also avoids creating astronomically large FBOs, so I suppose there’s a chance it could work on PS3…

I also took the opportunity to clean up the code a bit and add some easy-to-edit #define variables where appropriate. I made the gaussian blur passes pretty universal, so hopefully other people can just grab those and drop them into their own shaders in the future instead of each of us reinventing the wheel every time.

Here are some screenshots (these are using the 240pvert LUT; the 480pvert still only looks good at very large resolutions): Super Mario World Super Metroid Chrono Trigger

I also included a LUT based on Morku’s mega-zoomed GBC pictures but it doesn’t look so hot for the reasons Harlequin explained.

EDIT: whoops! forgot to post the download link: https://s3.amazonaws.com/Emulation/Pixel+Shaders/PhosphorLUT-Cg.zip

I’ll get it into the common-shaders repo soon.

Sweet :slight_smile: Welcome to the Cg club.

Great addition to common-shaders!

I’m waiting 0.9.9 version to test it! :stuck_out_tongue:

Thanks!

Beautiful shader hunterk, I lowered the blur just a tad and with ntsc filters added on top, it is truly CRT-like on my wide gamut Dell!

Is there any possible way to add a curved screen feature to make this the ultimate old-school filter?

Sweet, I’m glad you like it :smiley:

I just tried porting the old ‘curvature’ shader to Cg and failed miserably, but perhaps someone else can step in and help us out.

I can definitely see improvements over the previous version. Good to see you’re still working on it.

That said, I do have one minor gripe. I made a couple of LUTs to see if I could replicate the green-and-magenta dot mask emulation of CRT-Geom for use at 4x scale, and I had mixed results.

http://img577.imageshack.us/img577/2722/retroarch20130510054244.png

Brightness issues aside, I think the LUT effect may be too strong or something. I may have brought this up before, actually. It appears the shader basically makes up the image colors from the LUT rather than simply applying a tint like CRT-Geom does, which results in things like green objects having every other pixel much darker, creating essentially a vertical scanline effect which strains my eyes.

My question is, would it be possible to make the shader apply LUTs in a similar way to how CRT-Geom applies its dot mask emulation so as to prevent this?

Also Hunter I wanted to add, not sure if it is a bug or not or something to do with the way it processes the resolution, but the shader runs flawlessly when I use “Auto” aspect ratio but if I change it to say, 4:3, suddenly my frame rate drops to slideshow level.

@solid12345 Interesting. I’m not having that issue here. It runs at the same speed at either aspect ratio. I’ll keep poking around, though, and see if I can figure out what’s up. If anyone else can confirm/disconfirm this behavior, I’d love to hear about it.

@GPDP Yes, the way it works is it subtracts an inverted version of the game image from the LUT, so yeah, that could be an issue if one of the lines is completely un-tinted. You might try making the non-tinted part gray instead of white and then raise the brightness of the entire image using either the ‘brightness’ or ‘wid’ #defines.

Also, for whatever reason, I had to double the number of “pixels” in the LUTs in each direction for this version, as the ones from the GLSL version were rendering at half resolution. This is likely a side-effect of my far-from-competent understanding of Cg.

Nice shader hunterk. You should however use “#”-style comments in the .cgp file, c-style comments are not allowed. Then it also works in s9x w32 :wink:

Ah, okee doke. I’ll get it switched over to #s.

I’ve been revisiting this shader for the past couple of days and I’ve made some good progress getting it to work at 4x (probably works at 5x, as well, but I don’t have a monitor that will fit that res).

You can download the new version here (I’ll get it pushed to common-shaders soon): http://www.mediafire.com/download/gi5yh … LUT-v2.zip

I included 2 cgps. The normal one works well for most things, but things that do doubled horizontal resolution for transparency, etc. will turn purple (bsnes accuracy does this to all games). For those, use the 512 version.

Here’s a gallery of screenshots vs unfiltered: http://imgur.com/a/A2D4s#0

Hey, not bad! Seems like you got the aperture grille-esque look down rather nicely. Last time I tried getting that effect with the earlier version of your shader, I ended up straining the crap out of my eyes.

However, if I may make a suggestion: why not use the oversampling code from CRT-Geom for scaling, as opposed to the gaussian blur? I know it was only used vertically to produce the scanline “blooming” effect, while using Lanczos for horizontal scaling, but if it was applied both ways, I think it might look very nice. Gaussian alone blurs the image a bit too much, I find.

They’re shadow mask LUTs, but the crossbars get obliterated at that small of a scale, so they end up looking like aperture grilles anyway… I tried out just replacing cgwg’s dot mask code with the LUT stuff and it doesn’t look wildly different (vs this). A little sharper, I guess; darker, but I think that’s related to using a different combine method at the end (IIRC).

I’m not really sure what happens to the scanlines, but they’re pretty much invisible. You can see them a bit more on high-res stuff (e.g., anything in bsnes-accuracy) where it gets darker and more grid-y. This was also the case with my shader on its own if I tried to add any scanline shaders into the mix.

Also, even with the oversampling, moire really ruins things with any amount of curvature, unfortunately.

You can download it here if you would like to play around with it: http://www.mediafire.com/download/kegt4 … rLUTv2.zip

Yeah, something odd’s going on for sure with how you have it. As it is, the cgwg portion of the code does essentially nothing unless you mess with the scale settings. Setting both passes at 4x scale, you get vanilla CRT-Geom with scanlines, but with weird discoloration.

Anyway, what I was thinking is somehow isolating the code that cgwg uses for vertical scaling, and applying that to the whole picture, with blooming on bright pixels, but without scanlines. I say the whole picture, because regularly his code uses Lanczos horizontally, and while the ringing isn’t always that visible, sometimes it is, and it’s a bit weird seeing ringing only horizontally, when there is none vertically.

Playing around a bit more with this, it appears the shader does not work as intended when using D3D as the display driver. It does the gaussian passes, but it never actually applies the LUT.

It’s not really a big deal, but I would like to take a super hi-res shot of the 4K LUT applied to a game, and for some reason RetroArch only lets me resize the window past my desktop resolution when using D3D, while OpenGL does not (though it did in older versions of RetroArch). So as it stands, I cannot actually take a proper screenshot of the 4K mark LUT.

I just tried it and it works fine as long as it fits inside my screen, but it gets weird if I try to set it larger than my desktop can hold. However, I also get that behavior with any other shader I’ve tried. Did you check if any others worked for you?

Can you please delete Thumbs.db from here? https://github.com/libretro/common-shad … -v2.2/luts It’s junk created from Windows XP to thumbnail the images. Not important for users at all.

Done. You can reclaim your 24 kb now.

I made a bunch of updates to this shader to make it work better at 1080p and 4K, and I made presets that work in maister’s NTSC and scanlines from my interlacing shader (so, also handles interlaced content). The versions that don’t say ‘noblend’ after them force the frame to a 256 px horizontal size to smooth out SNES pseudo transparency and Genesis jailbar dithering, but they can make high-res text and text on some games (notably CPS1/2/3) look bad, so use the ‘noblend’ versions on those. The 4K versions have more detail on high-res/dpi screens and more “dynamic” scanlines relative to the other 1080p-friendly variants, but they’re a little too demanding for my GPU and don’t get full speed. I left them in anyway for people with better GPUs.

Here are a couple of screenshots (both are from the 4K variants):