01 February 2019

BGFX in MAME - Tweaking and In-Depth Look (plus a video) - Update January 2019

BGFX really rocks and after some MAME Updates, it became my standard shader.

Update January 2019: MAME 206 corrects the HLSL shader, so the purple screen is gone.
The 'Scale' values as described below are now in lines 186 and 191. Now I need to head for the new phosphor settings and update the below table for HLSL settings (I still do not like the default settings that much). Below you find the updated table of my current HLSL settings plus the Scale values for the lines 186 and 191.

Update December 2018: Since the October 2018 release, the HLSL shader has been updated by phosphor settings. As a result, BGFX/HLSL produces a purple picture, at least on my Mac in both MacOS and Linux - is this an SDL MAME problem? I am still investigating into that, and for the time being, I stay with BGFX/CRT-GEOM-Deluxe, which still provides very decent results.


HLSL under Windows (Bootcamp)
HLSL under MacOS and Ubuntu
Since both MacOS and Ubuntu is affected, this could point to an SLD problem.




Update December 2016: As explained by Jeeze in a comment to the Performance Test Post, the 'Scale' values in BGFX/HLSL provide for Oversampling. When it comes to modern games, this makes a real difference in quality, while I am unsure about any difference in old games.


CRT-GEOM - click to enlarge
Here are screenshots from Offroad Challenge for comparison. 
CRT-GEOM vs. HLSL vs. HLSL Oversampling

In the enlarged pictures, just look at the shadows to see the huge difference, but overall picture is much smoother. Photos taken by hand.


In the running game, the difference is even more pronounced.





HLSL - click to enlarge
HLSL Oversampling - click to enlarge







CRT-GEOM - click to enlarge
HLSL - click to enlarge



HLSL Oversampling - click to enlarge


















So if you play modern games, you will probably want to leave the 'Scale' value to 2, as long as your machine is able to cope with it.







Update October 2016: Due to a much appreciated comment by Jeeze, the main issue for the HLSL performance seems to be a parameter outside of the preferences. As suggested, I went down with the 'Scale' values in lines 177 and 182 from 2 to 1, and this seems to push performance to CRT-GEOM levels. I could not see any difference in quality on first glance.

I also adapted below tables a bit further and need to look further into this in more detail.

Update September 2016: This post is about the settings of the HLSL Chain. But HLSL is very resource hungry, though it runs very nicely under my specs. As explained by visitor Headrush69, his iMac 2011 fails to run BGFX at an acceptable frame rate. Same applies to a MacBookPro 13'' Mid 2012, which fails to run any game properly under full framerate. 

Since MAME 0.176, CRT-GEOM Shader in BGFX is currently my first choice - see this new rewritten post.

This is what you can do to change BGFX very conveniently to your own wishes - but with the example of the HLSL backend.


Step 1 - have a working MAME bgfx environment as explained here.

Step 2 - locate the hlsl.json file in your MAME directory (should be /MAME Directory/bgfx/chains/hlsl.json) - make a backup copy if something goes wrong.

Step 3 - start editing the file with an editor of your choice; all relevant parameters are conveniently located at the top of the file beginning at line 58

The good news: All changes you apply here are the new default values when you open MAME - no manual changes of the Sliders necessary - this is perfect!


Here is my configuration that I really like - compared to the factory values as provided by MAME (changes marked in red) - version 29 May 2016 - outdated since the October 2018 release

Get the modified file hlsl.json here.

My new HLSL settings as of January 2019:

Slider Name Original Value Modified value
Enable Adjustments 1 0
Enable NTSC 0 0
(all NTSC-related values unchanged for now)

all unchanged
Red Output from R,G,B
1.00, 0.00, 0.00
1.00, 0.00, 0.00
Green Output from R,G,B
0.00, 1.00, 0.00
0.00, 1.00, 0.00
Blue Output from R,G,B
0.00, 0.00, 1.00
0.00, 0.00, 1.00
Signal Offset, 
0.00, 0.00, 0.00
0.00, 0.00, 0.00
Signal Scale,
0.95, 0.95, 0.95
0.95, 0.95, 0.95
Color Saturation 1,20 1,20
Red Linear Convergence, x and y
0.0, 0.0
0.0, 0.0
Green Linear Convergence, x and y
0.0, 0.0
0.0, 0.0
Blue Linear Convergence, x and y
0.0, 0.0
0.0, 0.0
Red Radial Convergence, 
0.0, 0.0
0.0, 0.0
Green Radial Convergence,
0.0, 0.0
0.0, 0.0
Blue Radial Convergence, 
0.0, 0.0
0.0, 0.0
Defocus
0.5, 0.5
1.0, 1.0



Scanline Amount
0.50
0.40
Overall Scanline Scale
1.00
1.00
Individual Scanline Scale
1.00
1.00
Scanline Variation
1.00
1.00
Scanline Brightness Scale
2.00
1.00
Scanline Brightness Offset
4.00
2.00
Scanline Jitter Amount
0.00
0.20
Scanline Variation
1.00
1.00
Shadow Mask Tile Mode 0 0
Shadow Mask Amount
0.50
0.40
Shadow Mask Pixel Count
12,12
12,12
Shadow Mask UV Size
0.500, 0.500
0.500, 0.500
Shadow Mask UV Offset
0.000, 0.000
0.000, 0.000
Hum Bar Amount
0.0
0.02
Hum Bar Frequency 0,001 0,001
Signal Floor
0.03, 0.03, 0.03
0.03, 0.03, 0.03
Signal Exponent
1.00, 1.00, 1.00
1.00, 1.00, 1.00
Color Mode
3
3
Chroma Conversion Gain
0.299, 0.587, 0.114
0.299, 0.587, 0.114
Phosphor A Chromaticity
0.630, 0.340
0.630, 0.340
Phosphor B Chromaticity
0.310, 0.595
0.310, 0.595
Phosphor C Chromaticity
0.155, 0.070
0.155, 0.070
Phosphor Gain
0.2124, 0.7011, 0.0866
0.2124, 0.7011, 0.0866
Phosphor Persistence, 
0.45, 0.45, 0.45
0.50, 0.50, 0.50
Quadric Distortion Amount
0.05
0.05
Cubic Distortion Amount
0.00
0.10
Distorted Corner Amount
0.05
0.12
Rounded Corner Amount
0.05
0.05
Smooth Border Amount
0.03
0.03
Vignetting Amount
0.08
0.08
Reflection Amount
0.05
0.05
Scale (lines 186 and 191)
2
1


Some explanations regarding these changes:
  • First, this is all trial and error, not all values are self-explanatory and very much is a combination of everything. 
  • Defocus seems an important change because otherwise the pictures get too pixelated
  • Many Scanline settings were too agressive and caused a lot of bleeding, also the screen did not have any real black, i.e. everything was too bright. Major change.
  • Shadow Mask Amount - I didn't really know what to change here, but somehow it got better.
  • Hum Bar Amount - I like it a lot, very retro :-), but reduced now.
  • Signal Floor: The new version seems to have lowered this value to 0.03, which is importanat. That one was important for me because lowering these amounts brought more blacks into the picture. If you go down to zero, it's as black as in CRT-GEOM. But I appreciate this effect, but with a bit lower values.
  • New Phosphor Values: See above in orange. I did not mess around with them for the time being. But look into Color Mode - 2 gives you a very geeky Dicrome picture, which is nice from time to time.
  • Phosphor Persistence: lets the moving objects 'smear', which is nice, so I gave this a sightly higher value 
  • Cubic Distortion Amount, Distorted Corner Amount: I applied slightly more agressive values as regards the screen curvature.
  • Go for a higher Reflection  Amount, if you like it very very retro :-). I went back from 0.15 to default.
And here is a small video of how it now looks like:
- look at the Hum Bar that goes through the screen
- look at the reflection spot at the upper right part of the screen


go for fullscreen to get a feeling how this looks like

I will probably continue experimenting with these settings and update this table if needed.





10 comments:

  1. Hum bar is cool, but too distracting/obvious for me at .05 setting. Back in the day I'd avoid monitors that were that bad. I have it at 0.02; there but not ready for the trash heap yet.

    ReplyDelete
    Replies
    1. Stephen yes it's distracting very much, but very often harsh reality back in good old times :-). Since BGFX seems to be very resource hungry (see my update above), may I ask you which machine you are using?

      Delete
  2. Stephen, what Mac are you running on?

    estefan, I tried your HLSL.json file and it's still too slow on my machine.
    I'm good with using the GLSL shaders but to get some of the really good effects for vector games, it seems HLSL is required.

    ReplyDelete
    Replies
    1. Headrush69 you were right, BGFX is very resource hungry. I updated this post with a warning, since even our MacBook Pro 13'' Mid 2012 failed to produce decent results. It has Intel HD 4000 Graphics inside. Otherwise Metal backend under El Capitan. It seems you need a strong GFX chip to run BGFX.

      Delete
    2. I expected it to be more resource heavy, but was surprised by the difference between using BGFX and using a GLSL shader.

      Just to test whether it is hardware related or it is OS X related, I'm installing Windows in Bootcamp and see how it runs there.

      Delete
  3. estefan, how do your vector games looks using BGFX?

    On both OS X & Windows it doesn't seem to work for me. Looks like those really cool looking screenshots I've seen around might be D3D and HLSL only so far.

    Have you noticed any games that became too lagging using BGFX?
    I plan to hack a NVIDIA 780 into my iMac in the future, so curious how well it is for more demanding games.

    ReplyDelete
    Replies
    1. Hi Headrush69, vector games seem to play no effects in BGFX so far, which might be a configuration thing, have to look at it. What puzzles me more is that in Asteroids I suddenly see no shots, they're just gone. Must test further. Up to now no real performance issues, but BGFX is without doubt much more resource hungry. I do see some partial updates issues in Gyruss, need to do further testing. But all in all GLSL seems to be much more effective, probably time to look back into GLSL.

      Delete
  4. It is not a configuration thing. After some research I fond that BGFX and GLSL don't work with vector games. Currently only the D3D/HLSL combination work, which is Windows only.

    I have the same issue with Asteroids, Star Castle, etc with almost invisible shots. The problem occurs when any filtering is used. This means using BGFX, using GLSL, even using the default OS X driver of OpenGL with bilinear or FF filtering.

    It seems the only way (currently) is to switch to the "access" video driver.
    I then adjust the Brightness, Contrast, Gamma, and Flicker options to get the best look.

    ReplyDelete
    Replies
    1. That was the "accel" video driver. Darn autocorrect :-)

      Delete
  5. Grateful for shharing this

    ReplyDelete

Any comments are welcome!