Jump to content
LaunchBox Community Forums
Lordmonkus

Mame BGFX Shaders - Tutorial

Recommended Posts

For those that do not know what BGFX shaders are in Mame, it is a new renderer which works with HLSL. What does this mean ? Well simply put it makes everything much simpler for the end user. Up until the BGFX renderer you had 3 options:
1) no shaders at all which look bad on a modern display
2) GLSL using CRT-Geom or Lottes shaders which required different shaders for vertical and horizontal games
3) HLSL which looked bad out of the box and required manual tweaking to suit personal taste and to suit your display. Straight up standard HLSL is still a very good option for those wanting to get their hands dirty and really customize the look.

What BGFX does though is fixes all the problems above and gives a wide variety of shader options similar to some of the shader types found in Retroarch so if you like those smoothed out shaders you can have those there too.

To take advantage of BGFX I highly recommend getting version 177 of Mame. For those of you that like to use MameUIFX sadly the last version that is available is 175 and has very limited options and not particularly useful. MameUIFX is no longer being officially updated but there are unofficial ways of getting the same UI in Mame and I will cover that further down.

The standard install of Mame 177 has everything we need to get started. Just install it like normal and using the command line run your Mame executable with the following parameter:
Mame64.exe -cc

What this does is it generates a mame.ini file right in your Mame install folder which you will need to edit. Open this ini file in your favourite text editor like notepad or notepad++ and look for the following section:
# OSD VIDEO OPTIONS
#
video                     auto

edit it change the word auto so it is now BGFX, so now it should read:
# OSD VIDEO OPTIONS
#
video                     bgfx

Now we need to look a little further down the ini file for the section titled:
# BGFX POST-PROCESSING OPTIONS

Look for the following line:
bgfx_screen_chains        auto

This is where we are going to set the default shader look. If you look in the folder \bgfx\chains within your Mame folder you will see a bunch of files with the extension .json, these are the actual shader files. You will also see several sub folders with more .json files, those are also shaders so as you see there are several options.

Now if you have previously used some shaders in Retroarch or some other emulators you may recognize some of the names and have a general idea of what some of them will look like out of the box but you will probably want to preview how they look before deciding on which shader you want as your default. To make judging a little easier look in the mame.ini file for the following line:
pause_brightness          0.65
Change the brightness to 1.0 so you can pause the game and scroll through the different shaders and see exactly how they will look at their correct brighness.

Run a game of your choosing and get to a point you want to use as your judging point and press P on the keyboard to pause the game. Now press the tilde key (the key beside the number 1 that has the ` on it). You will see a bar at the bottom of the screen, press the down arrow key until that changes to:
Window 0, Screen 0 Effect: Default

Now you use the left and right arrow keys to scroll through all the different shader effects. Once you find one that you find appealing take note of the name of it because this is the name you are going to put in your mame.ini file. Edit the line:
bgfx_screen_chains        auto
replacing the word auto with the name of the shader you found that you liked, for me this was the shader crt-geom.

You are now done and all you had to do was edit 2 lines in your mame.ini file. The one downside to BGFX for now is that you cannot easily save and load configuration files for these shaders. You can edit them while in game using the "tab" menu within Mame but you cannot save them out, once you close the game those changes are gone. Hopefully in the future this will change.

Note:
For games with multiple displays being played on a single monitor such as Punch-Out or Darius II for example you need to add to the bgfx_screen_chains line. In my mame.ini file since I am using the crt-geom shader mine looks like this:
bgfx_screen_chains        crt-geom,crt-geom,crt-geom

This handles 3 the 3 screen version of Darius II. If it was left with just a single crt-geom one of the screens would have the shader effect but the others would have no effect.

Here is a link to the documentation for all sorts of stuff you can do with BGFX shaders, especially if you have a multi display set up.
http://docs.mamedev.org/advanced/bgfx.html

Now for those of you that do not like to get dirty with editing .ini files by hand and wish they had a new version of MameUIFX which unfortunately is now discontinued there is an option. Head on over to EmuCR and search for a program called Arcade. Download the appropriate version that matches your Mame version and drop the .exe file into your Mame folder and run that as your emulator, it will probably be called arcade64.exe. It will work along side your mame64.exe. When you run it it will look and function identically to the MameUIFX you are accustomed to.

Here is a link to version Arcade 177 over on EmuCR http://www.emucr.com/2016/09/arcade-v0177.html

Here is a screenshot of DoDonPachi in action using the crt-geom preset bgfx shader. It actually looks much better full screen and in motion than the static screenshot.

DDP.png

  • Like 4
  • Thanks 3

Share this post


Link to post
Share on other sites

Thank you very much! with shaders getting better and better support in mame I see no reason to use Retroarch for arcade games anymore. :):)

Share this post


Link to post
Share on other sites

Yeah I don't use Retroarch for arcade systems at all aside from NeoGeo which I think is perfectly fine. It was a system that had a home version and used the same display and resolution for all of its games. Mae had decent enough shaders in the past as it was with its GLSL shaders and then the much improved HLSL with some personal tweaks but BGFX is really shaping up to be great. I will have to dive into a new build like 181 and see if there have been any improvements since 178 which is the last build I have used.

In fact there was never a good reason to use Retroarch for arcade games over stand alone Mame at all. It's only now getting to a point with the bit builds of the newer Mame cores in RA that it is even getting close to competing with stand alone Mame.

Share this post


Link to post
Share on other sites

Thank you for the info!  I was able to make the changes but they don't stick when I leave the game.  Also, is there a way to change the settings globally?  Thanks!

Share this post


Link to post
Share on other sites

Yeah the changes don't stick changing them in game. You need to take note of what shader you like and edit the mame.ini like I described above.

Specifically this line:
bgfx_screen_chains        crt-geom,crt-geom,crt-geom

Share this post


Link to post
Share on other sites

With BGFX and HLSL shaders vertical vs horizontal orientation don't matter. With GLSL shaders they do/

Share this post


Link to post
Share on other sites

Yes. My point is that we can also create shaders for specific categories/drivers/games and not only globally by modifying mame.ini.

I use different shaders for example in my vector.ini for all my vector Mame games.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi ! Linux user here. Thanks a lot for the tutorial, it worked well ! May I ask a few questions though ? :-)

- under Retroarch, I'm used to combining several shaders to get a (IMHO) superb both precise & retro picture : I usually combine an xbr with a crt shaders (for instance, xbrz6 + crt-hyllian or lottes). Is it possible to queue several shaders in sdlmame as well ? I tried to specify two but only the first one was applied.

- on my setup (Archlinux, nvidia) quite a few shaders do not appear correctly (wrong colours) under sdlmame, although the equivalents under RA do work. Any idea ?

- my MAIN concern with emulation is minimizing the input lag !! Did anyone measure if there is less input lag with sdlmame or RA ? (Linux / X11 here). I kinda have the feeling it's a little bitter under plain MAME but I think it's mainly placebo... RA is supposed to give better performance because : 1) Vulkan is supported (and also X-free Vulkan context) 2) KMS is supported (although I do not use it in my case). I guess Vulkan will be supported too soon in sdlmame as SDL with Vulkan support was released a couple of days ago. Any idea about SDLMAME over KMS ?

- BTW, is it possible to force double buffering under SDLMAME/X11 ? RA apparently only allows it in a KMS (or X-free Vulkan context) ?

 

Thanks a lot for your help !!

Cheers

Share this post


Link to post
Share on other sites
6 hours ago, bidinou said:

Is it possible to queue several shaders in sdlmame as well ?

Not to my knowledge but I could be wrong.

6 hours ago, bidinou said:

on my setup (Archlinux, nvidia) quite a few shaders do not appear correctly (wrong colours) under sdlmame, although the equivalents under RA do work. Any idea ?

Sorry, but I have no idea.

6 hours ago, bidinou said:

Did anyone measure if there is less input lag with sdlmame or RA ?

I can only say that Brunnis did some testing and found that shaders had no impact on input lag. Feel free to read over this thread over on the Retroarch forums about his testing and findings.

https://forums.libretro.com/t/an-input-lag-investigation/4407

6 hours ago, bidinou said:

BTW, is it possible to force double buffering under SDLMAME/X11 ? RA apparently only allows it in a KMS (or X-free Vulkan context) ?

Again, I have no idea. These are all Linux based questions and as much as I love Linux and use it on my old laptop my knowledge of it when it comes to all the nitty gritty gaming related stuff I simply don't know. These are the sort of questions best asked on the Retroarch and Mame forums.

Share this post


Link to post
Share on other sites

For those using BGFX I'm pretty happy with my modified hlsl.json. I'll attach it here if anyone wants to try it out.

Here's what's in my mame.ini for BGFX

 

bgfx_path                 bgfx
bgfx_backend              auto
bgfx_debug                0
bgfx_screen_chains        hlsl
bgfx_shadow_mask          slot-mask.png
bgfx_avi_name             auto

 

hlsl.zip

Share this post


Link to post
Share on other sites

Not bad looking at all, though for my tastes the "moire" effect is a bit on the strong side. Not sure if that is due to my monitors resolution or not, I use a 1440 display so maybe on a 1080 it is either not there or it is far less noticeable.

For those wanting to try this out simply drop the hlsl.json file into your mame\bgfx\chains folder replacing the current file but of course you should back up your current one first just in case you don't  like the one from @Replay

Share this post


Link to post
Share on other sites

Heya,

Thanks for the info in here so far, quite useful!

I am now running my arcade with the 191b MAME and romsets, and I wonder if we have any additional video enhancements for it over what was described above. Any hints?

Share this post


Link to post
Share on other sites

I suppose you could layer SweetFX / ReShade over top if you wanted to but that is unnecessary if using HLSL (which is what I use) because you can tweak HLSL a whole lot more than the BGFX shaders.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, Lordmonkus said:

I suppose you could layer SweetFX / ReShade over top if you wanted to but that is unnecessary if using HLSL (which is what I use) because you can tweak HLSL a whole lot more than the BGFX shaders.

Yeah, that wouldn't make a lot of sense.

Another question, please: I have hlsl enabled in the .ini file, and I have downloaded and replaced the raster file at ini/presets, but I still don't have the settings on by default when I load a ROM. Do you know what could be wrong here?

Share this post


Link to post
Share on other sites

No idea, if you enabled it in the ini file it should work, unless for some weird reason your video card doesn't support it.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...