Retroarch Shaders and MAME HLSL

I’m so completely spoiled by the shaders in RetroArch that I’m pretty much unable to use standalone MAME anymore. I cannot seem to get HLSL in MAME to look anywhere near as good as plain old ‘scanlines.cg’ in RetroArch…

HLSL looks to be pretty powerful, but even though I can get even, pixel matching scanlines, I can’t get a uniform, consistent brightness.

Can someone explain to me why the scanline shader in RetroArch works so well and looks so good across a variety of systems, different games and resolutions, and why it’s so difficult to achieve this using HLSL?

Thanks

Shitty shaders perhaps. HLSL/Cg/GLSL are basically the same thing, just different syntax.

scanline.cg is like the most trivial shader ever, just applies a sine wave pattern vertically. :stuck_out_tongue: The continous sine wave + bilinear ensures it’ll always look decent at any scale.

I agree it’s a lot easier with some shaders than Mame hlsl to get a good result (always some strange moiré with scanlines). But scanline.cg is not the best: the scanlines aren’t precise and end up in between pixels.

I have a better result with that file attached I took from… I don’t remember. =| Think it was in a pass from one of the cgp in the shader repo, can’t remember which one.

That’s the blurred scanline pass from maister’s NTSC shader, IIRC. It does look quite nice :smiley:

http://forums.guru3d.com/showpost.php?p … tcount=226

I’m sorry if this is a little off topic, but can any of these RetroArch shaders be easily inserted into Sweet FX? The above post has Boulotaur getting cgwg’s CRT Pixel Shader working, but the link is down. I’d love to get your scanlines.cg working, Tatsuya79

hunterK, I saw this brought up on your blog a while ago…

http://filthypants.blogspot.com/2013/02 … sphor.html

Basically, I’m trying to get scanlines into Demul using SweetFX…

I wonder if that’s possible. Does sweetfx works with demul?

I tried using it with XM6 for X68K emulation without success. It worked in Mame though with certain issues I don’t remember.

But Demul has its own shader system now. It seems you can add some judging from this post.

edit: lol just saw you’re already in this thread

SweetFX has its own uniforms and whatnot, but it shouldn’t be too hard to make many of the Cg shaders work with it, I wouldn’t think, since Cg’s syntax is extremely close to HLSL.

Skimming through that demul thread, I thought I’d clarify that RetroArch can load Cg and GLSL shaders directly, though the ones you’ll find in the ‘common shaders’ repo are only in Cg format, which–as I said–is very similar to HLSL. Demul seems to use crummy old fixed-function GLSL similar to what is used by epsxe (and not too different from the old bsnes/XML shaders that RetroArch used to support). SweetFX wants HLSL, so tweaking the existing Cg shaders would probably be the path of least resistance in this case, assuming you can get it working without too much trouble.

I used SweetFX to add scanlines to Borderlands 2 and SSF4-AE for a while and may still have a copy of it laying around. If so, I’ll post a link in this thread.

Please do… That would be awesome!

So, this shader works pretty well with Demul


   /*-----------------------------------------------------------.   
  /                        SweetCRT                            /
  '-----------------------------------------------------------*/
/*
SweetCRT - a Work in progress.
*/

#define scanline_strength 0.75

float4 SweetCRTPass( float4 colorInput, float2 tex )
{
   //
   float scanlines = frac(tex.y * (screen_size.y * 0.5)) - 0.49; //
   scanlines = 1.0 + scanlines * scanline_strength;
   
   colorInput.rgb = saturate(colorInput.rgb * scanlines);
   //colorInput.rgb = saturate(scanlines).xxx;
  
   return colorInput;
}


But not as nice as yours, which unfortunately, isn’t compatible with Demul


struct data
{
   float2 tex;
   float2 pix_no;
   float2 one;
};

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float frame_count;
};

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,
   float2 tex : TEXCOORD,
   uniform input IN,
   out data oData
)
{
   oPosition = mul(modelViewProj, position);
   oData.tex = tex;
   oData.pix_no = tex * IN.texture_size;
   oData.one = 1.0 / IN.texture_size;
}


float4 main_fragment (uniform input IN, in data vertex, uniform sampler2D s0 : TEXUNIT0) : COLOR
{
#define DISPLAY_GAMMA 2.2
#define CRT_GAMMA 2.4
#define TEX(off) pow(tex2D(s0, vertex.tex + float2(0.0, (off) * vertex.one.y)).rgb, float3(CRT_GAMMA))

   float3 frame0 = TEX(0.0);
   float3 frame1 = TEX(0.0);
   float3 frame2 = TEX(0.0);
   float3 frame3 = TEX(0.0);
   float3 frame4 = TEX(0.0);

   float offset_dist = frac(vertex.pix_no.y) - 0.5;
   float dist0 =  2.0 + offset_dist;
   float dist1 =  1.0 + offset_dist;
   float dist2 =  0.0 + offset_dist;
   float dist3 = -1.0 + offset_dist;
   float dist4 = -2.0 + offset_dist;

   float3 scanline = frame0 * exp(-5.0 * dist0 * dist0);
   scanline += frame1 * exp(-5.0 * dist1 * dist1);
   scanline += frame2 * exp(-10.0 * dist2 * dist2);		//scanline darkness
   scanline += frame3 * exp(-5.0 * dist3 * dist3);
   scanline += frame4 * exp(-5.0 * dist4 * dist4);

 //return float4(pow(1.15 * scanline, float3(1.0 / DISPLAY_GAMMA)), 1.0); default
   return float4(pow(1.2 * scanline, float3(1.0 / DISPLAY_GAMMA)), 1.0);
}


I am not very knowledgeable when it comes to converting shaders… Can any of you shader experts improve the original, or if it’s simple, can you modify/port the other scanline shader so it’ll work? I know a few guys that’ll be extremely happy, myself included.

Thanks!

I found my copy of that SweetFX port of cgwg’s CRT: http://www.mediafire.com/download/bt71f … wg-CRT.zip

I fiddled with the settings quite a bit to make it flat and less pixellated, among other things, so it’s not the default settings anymore, but at least it’s something.

Thanks a bunch… I’m looking forward to trying it out later. You rule!

EDIT

So after trying that shader out with SweetFX/ Demul, I see it’s pretty much an early version of what became the AdvanceCRT shader, which is already included with SweetFX.

The problem with that shader is it doesn’t scale correctly, (probably a Demul issue) meaning the scanlines are HUGE and far apart, even using the config and turning them up (increasing resolution) it’s still not right. The best way to describe it would be 640x480 scanlines on a 1920x1080 image. When you turn up the internal resolution in Demul, the scanlines start to look better, but then Demul starts to crawl… In the shader, you can define the resolution from like 1-8, but it needs to go to like 24 for it to look right. Is there any way to edit/max out the resolution in the shader? The SweetCRT shader I posted above DOES scale correctly, if that’s any help…It just doesn’t look as good as any of the CRT shaders inRetroArch (although close)…

Thanks for everyone’s help with this