18 December 2016

BGFX in MAME - Tweaking and In-Depth Look (plus a video) - Update December 2016

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

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

Get the modified file hlsl.json here.

Slider Name Original Value Modified value
Enable Adjustments
0
1
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
Phosphor Persistence, 
0.45, 0.45, 0.45
0.45, 0.45, 0.45
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.05
Hum Bar Frequency
0,001
0,001
Signal Floor
0.05, 0.05, 0.05
0.03, 0.03, 0.03
Signal Exponent
1.00, 1.00, 1.00
1.00, 1.00, 1.00
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


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. So this is my first try, and I already like it a lot.
  • Defocus seems important because otherwise the pictures get too pixelated
  • 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.
  • Shadow Mask - I didn't really know what to change here, but somehow it got better.
  • Hum Bar Amount - I like it so much, very retro :-).
  • Signal Floor: 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.
  • 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.





9 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

Any comments are welcome!