GLSL Shaders in .vsh format?

Your Blog brought me to Retroarch or good shaders in general.

To be honest, I was the one, who supported mamesick (creator of MAMEUIFX) to implement Lotte´s shader into MAMEUIFX. He did the coding and I did the permissions and beta-testings. In the next UIFX release, there will be also a new HLSL version included (done by Jezze), that has many bugfixes from official HLSL (better bloom with no offset, better defocus and better post.fx) and two new parameters like vignette and reflection.

is your linked shader this one: http://www.mameau.com/mame-glsl-shaders-setup/ because I allready have it. my aim is to collect some more opengl shaders for UIFX, just to give the users more options to choose from. Big thanks for the explanation, on how to create those vsh and fsh files. at least a starting point.

From what I understand, I can handle up to 10 shaders with OpenGL in mame now, so my guess is that this will not be the problem. If I understand you correctly, the allready converted shaders are unusable and I should better use the original Cg files… right?

At the end, I will show you, how far UIFX has come:

Lotte´s shader (OpenGL):

Jezze´s shader (new HLSL):

Sega Turbo Example:

OpenGL:

HLSL:

Real CRT Sega Turbo:

Yeah, that’s the same one I linked.

Another resource for you: https://github.com/hizzlekizzle/quark-shaders. These are shaders that Hyllian, aliaspider and I already ported from Cg to Higan’s somewhat odd flavor of GLSL with the files already separated into individual vertex and fragment shaders. Between these and the Cg versions, it shouldn’t be too hard to figure out what’s going on and port them over to MAME’s format.

I’ve never understood why MAMEdev went with HLSL in the first place. Of the 3 major shader languages, HLSL is the only one that’s unabashedly single-platform…

Oh, nice… I will look at those too. I converted your linked shader allready, however i dont know how it looks in original form. In my conversion, there are only curvature and scanlines and the shader looks like this:

It seems that this shader doesnt use a shadowmask :frowning: .

The reason why they went HLSL is MooglyGuy, cause he created it. But since 2 years nothing is happening and the code is basically a mess. Due to the nature how it is composed, someone who wants to contribute needed to reverse engineer many stuff in c+ inside of the HLSL. Now they realized, that if something new should happen, only MooglyGuy can do, they decided

a.) to include SDL into the windows source (or official build) and b.) it is planned to include BGFX (whatever language this is), but they have to start from scratch.

As MooglyGuy is a really annoying personality, no one did anything usefull to HLSL over the years. He quitted now the further development of HLSL and maybe things will change now.

Jezze and myself even offered help, but the response was 20x fuck in a post with 7 sentences, so you maybe can imagine that our intentions to coorporate with the mame devs went to zero. At that point i found mamesick… he is the opposite of the mamedevs and a really nice person. Together we try to open new possibilities to the mame community with his GUI version of MAME and the main aim to LCDs. Yeah thats it, thats why i am in search to collect more shaders, for UIFX.

I am happy, that you all here, are way more friendly and a project can only be better through synergy… something that the mamedevs need to learn.

greets, u-man

It looks like a few things are missing, actually. The corners should be rounded (unless you turned that down/off) and the oversampling function should help with the moire pattern caused by the screen curvature. The shadowmask part is right at the end:

                // dot-mask emulation:
                // Output pixels are alternately tinted green and magenta.
                vec3 dotMaskWeights = mix(
                        vec3(1.0, 0.7, 1.0),
                        vec3(0.7, 1.0, 0.7),
                        floor(mod(mod_factor, 2.0))
                    );

                mul_res *= dotMaskWeights;

It just breaks the pixels into 3 parts and tints one part pink and part green.

As for MooglyGuy, I’ve never had any interaction with him, but I know some other folks who have had a similar experience as yours :wink:

The only stuff, I turned off, was the tilt (useless and wrong in vertical games) and the overscan (games got cropped). I dont have a moire pattern, maybe you didnt see the picture at full size? I guess, the oversampling works. I would like to have rounded corners, but I just dont know how I could get them working.

I attached you my files, maybe you see something that is wrong, what I dont see. I am really new into this and I wish I could do more.

As for the mamedevs, I am really done with them. Some of the guys are cool, but most of them, are not worth to mention. I really didnt understand the team, how they can keep such a toxic person into their forums. In any other forum, a person like MooglyGuy would be kicked and banned permanently.

cheers, u-man

PS EDIT: I got rounded corners, it was just a issue with wonderboy… dont know why, but in other games i have rounded corners :wink:

Ok, i got everything working, thanks to your nice tutorial here: http://filthypants.blogspot.de/2012/07/customizing-cgwgs-crt-pixel-shader.html

it looks like this now: http://i60.tinypic.com/2aaawrd.jpg

but the slotmask is still missing :frowning: I bag you, please help me with this…

That code looks right to me. Not sure what could be going wrong. Does anything happen if you comment out the ‘mul_res *= dotMaskWeights;’ line? If not, try changing it to: mul_res = mul(mul_res, dotMaskWeights);

You might also try breaking that dotmask stuff into its own pass.

The process is not invoked… i tried it and left out semicolon or changed the names to whatever sounds ridicilous… nothing happened, not even a error popped out. So i guess, the whole process is not invoked or recognized by MAME… there is something that must defined prior this lines i guess. I am really new to it and just dont know it better. How would I do that “own pass”? I am so close and would be really happy, if this puzzle could be solved :slight_smile: .

Are you sure you’re editing/loading the correct file? There’s not really any way that it could be skipping that line and still loading the last couple of lines to the extent that it wouldn’t error out without a semicolon.

For separating into its own pass, you can look at our dotmask.cg shader, which is exactly that.

I am sure that I am loading the right file :smiley: … The shadowmask lines are the last lines in the fsh code. So it could be possible that everything prior this lines is loaded, but those last lines not… still strange that there is no error prompt.

If I make a second pass, with the dotmask.cg shader, there is a error prompt. By second pass, I am assuming to create a second .vsh and .fsh file and use a “glsl_shader_mame1 D:\GAMESTATION\MAME\MAME_0160_64\glsl\dotmask” (only example) inside the mame.ini.

It is really difficult, if you dont know what error is there other than “GLSL loading mame bitmap shader 1 failed”… really miss some debugging tool :frowning:

Yeah, it’s pretty much impossible to work on shaders (or any code, really) without meaningful debug info. Surely it prints the real error somewhere…

There’s no way it’s stopping before that line because the very last line is the one that actually tells the shader what to do (‘return’ in the main fragment function of a Cg shader and 'gl_fragCoord = ’ in GLSL).

If that line won’t cause an error, can you make it error elsewhere in the file? I’m still suspicious that you’re working on a different file from the one it’s loading, which is nothing to be ashamed of. I’ve done it a million times. “wtf? why is it still giving that error?? oh wait…”

ok… i found out the error… trivial off course :smiley: … my first attempt, was a linux derivant of the crt-geom shader. The linux version missed the slotmask in the code, but i didnt notice it. Because the linux version contained way more than just two files, i.e. additional idx16_lut.fsh and rgb32_lut.fsh files, i wanted to start from scratch. After you told me how to do the vsh and fsh files, i renamed the linux-version with a underscore at the end of the name ( crt-geom_rgb32_dir_.fsh ) , but off course this wasnt enough and MAME used always this version, instead of the one, i was currently working :smiley: .

ok, so far so good… we can adress the problem straight to these two lines:

vec3 dotMaskWeights = mix( vec3(1.0, 0.7, 1.0), vec3(0.7, 1.0, 0.7), floor(mod(mod_factor, 2.0)) );

mul_res *= dotMaskWeights;

I guess, thats why they where removed in the linux-version :smiley:

I tried changing: mul_res *= dotMaskWeights; to: mul_res = mul(mul_res, dotMaskWeights); Or just using one line at a time… all with no luck. The error lies in those two lines, thats for sure. By removing them, all went fine.

Ok, I’m guessing it’s choking on the mod_factor variable, which is supposed to be defined in the vertex. Try replacing it with whatever the MAME equiv of this is: texCoord.x * IN.texture_size.x * IN.output_size.x / IN.video_size.x That is, maybe it’s not pulling it from the vertex properly, so just put it directly into the fragment.

If that doesn’t get it working, I don’t think we can get any further without proper error messages.

I need some good source for MAME equivalents… I cant find any useful docs regarding MAME and OpenGL.

of this line: mod_factor = texCoord.x * rubyTextureSize.x * rubyOutputSize.x / rubyInputSize.x;

the only NOT knowing equivalent (at least for me) would be the “rubyOutputSize” …

All other parameters, are also used elsewhere in the code, so if they would be wrong, the shader wouldnt work. The conversion of that line, would be like this at the moment:

mod_factor = texCoord.x * color_texture_pow2_sz.x * rubyOutputSize.x / color_texture_sz.x;

Still missing, would be the “rubyOutputSize.x” and its only used in that line. I dont know where to search for this. So yeah, you are right with “it’s choking on the mod_factor variable” , Really desperate here :frowning: .

I really dont know, why they even changed stuff like this… I always thought OpenGL is multiplatform and same across the different OS´s. How can someone convert something, if stuff is missing or not the same?? WTF… Even the splitting of the vsh and fsh files is really annoying… MAME should be renamed to NTSC (N.ever T.he S.ame C.ode). It could be easy, but no, we make it complicated and undocumented :frowning: .

Alright, one more thing to try: replace mod_factor in the fragment with gl_FragCoord.x

It all hangs only on this “rubyOutputSize.x” thingy… code works now (but with no difference) , even with mod_factor and dotmask, as long as I keep out “rubyOutputSize.x” .

so i need a replacement for this:

uniform vec2 rubyOutputSize;

and this:

mod_factor = texCoord.x * color_texture_pow2_sz.x * rubyOutputSize.x / color_texture_sz.x;

these are the only places, where “rubyOutputSize.x” stuff is placed and both lines are in the vertex part (or vsh file)

PS: Just tried, with leaving those “rubyOutputSize” as is… no error prompt, but no slotmask either :frowning:

Ok, if I get rid of the mod_factor stuff (and, thus, all of the OutputSize, etc. stuff, too) entirely and replace it with gl_FragCoord.x, it works fine here (not in MAME, but in a GLSL shader IDE).

Ok, shall I delete everything mod_factor related ??? Because I have two lines in the vertex part, where mod_factor is included:

varying float mod_factor;

and

mod_factor = texCoord.x * color_texture_pow2_sz.x * rubyOutputSize.x / color_texture_sz.x;

And in the fragment part, there are also two lines:

varying float mod_factor;

and

vec3 dotMaskWeights = mix( vec3(1.0, 0.7, 1.0), vec3(0.7, 1.0, 0.7), floor(mod(mod_factor, 2.0)) );

So i replace the whole lines with gl_FragCoord.x or only the term mod_factor ???

Dude, you are awesome… it worked. So I only kept the line:

vec3 dotMaskWeights = mix( vec3(1.0, 0.7, 1.0), vec3(0.7, 1.0, 0.7), floor(mod(gl_FragCoord.x, 2.0)) );

It works now, but the dotmask is barely visible… how I can make the mask more visible?

And it doesnt work on vertical games, so I guess it needs to be rotated for them. How would I do this?

Anyway, first a very BIIIIIGGG THANNNKS … You made one person in the world really happy now :slight_smile:

PS: I got that solved with the vertical alignment… and I am ashamed that I even asked… off course it is “gl_FragCoord.y”