MAMEUIFX

A full-of-features version of MAME designed for LCD monitors
It is currently 22/09/2019, 7:27

All times are UTC+02:00




Forum locked  This topic is locked, you cannot edit posts or make further replies.  [ 26 posts ]  Go to page 1 2 3 Next
Author Message
PostPosted: 01/05/2015, 0:36 
Offline
Moderator
Moderator
User avatar

Joined: 17/10/2014, 12:02
Posts: 108
Location: Germany
Customizing the CRT Geom Shader

This document identifies some of the user-configurable options available in the CRT Geom Shader and provides some screenshots to explain their effects.

For individuals interested in recapturing the look of retro gaming consoles played on a CRT television like the ones we grew up with, the CRT Geom Shader provides the closest approximation available for modern LCD displays. The pixel shader is purely cosmetic--nothing could impart the technical advantages of a CRT, such as negligible input lag and insanely high contrast, to an LCD--but it can go a long way to displaying old games as we remember them. Since memory and nostalgia are important to the way we perceive these games, each person will have different feelings about what looks "right" to them.

We will be using the latest (as of the time of this writing, 7/28/12) and most complete version of the shader, known as CRT-Geom. This shader allows for simulated screen curvature, rounded corners, simulation of a back-tilted screen (for arcade emulation) and many other goodies. All images are captured at 4x scale, click the thumbnails to embiggen.

This is what the shader looks like with all default parameters, also known as the 'curved' variant (cgwg chose sane values for all of the variables by default):

Image

The user-configurable parameters are primarily located in two places in the shader, starting at line 87 in the .vsh section of the shader and line 12 for the .fsh section. You should be able to open and edit the shader in any text editor, but I recommend Notepad++.

In the following examples, we are talking about this portion of the .vsh shader-code:

// START of parameters

// gamma of simulated CRT
CRTgamma = 2.4;
// gamma of display monitor (typically 2.2 is correct)
monitorgamma = 2.2;
// overscan (e.g. 1.02 for 2% overscan)
overscan = vec2(0.90,0.90);
// aspect ratio
aspect = vec2(1.0, 0.75);
// lengths are measured in units of (approximately) the width of the monitor
// simulated distance from viewer to monitor
d = 2.0;
// radius of curvature
R = 3.0;
// tilt angle in radians
// (behavior might be a bit wrong if both components are nonzero)
const vec2 angle = vec2(0.0,0.0);
// size of curved corners
cornersize = 0.03;
// border smoothness parameter
// decrease if borders are too aliased
cornersmooth = 100.0;

// END of parameters


The first parameters, 'gamma of simulated CRT' and 'gamma of display monitor' allow the shader to determine how much gamma correction to apply to the image. CRT displays generally had higher gamma ratings than most LCD displays (2.4 for a typical CRT vs 2.2 for a typical LCD), so the shader adds 0.2 to the gamma to compensate. If you calibrate your LCD to a higher or lower gamma setting, you may wish to change the 'gamma of display monitor' to reflect your individual settings. You can also raise or lower the simulated gamma to make a darker, more saturated look:

Image

or a lighter, desaturated look:

Image

Next, we have 'overscan.' Each CRT showed a slightly different amount of the picture, and the cut-off portion was referred to as overscan. You can modify the amount of over- or underscan by changing this variable. Setting it to (0.00,0.00) will assume you want the picture aligned exactly with the borders of the window. Setting it to a value greater than 1.0 (for example, 1.10,1.10) will cut off a large portion of the screen (approximately 10% in this example):

Image

while setting it to a value less than 1.0 will surround the screen with black bars (i.e., underscan):

Image

Increasing the overscan slightly, say, to 1.02,1.02, can cut off unsightly garbage lines at the top of the screen, which is common on NES games.

Next, we have 'aspect ratio,' which controls how much our screen curvature settings will affect the top/bottom and sides of the image. The default setting of 1.0, 0.75 means the curvature will be more pronounced on the top/bottom than on the sides, to compensate for the standard 4:3 aspect ratio. Setting it to 1.0, 1.0 will make the settings affect both sides of the screen equally, which isn't quite right in that the top/bottom actually appears more curved than the sides:

Image

If for some reason you want only the sides straight, you can set it to 1.0, 0.5:

Image

or 0.5, 1.0 to make only the top/bottom straight:

Image

Next up, we have 'simulated distance from viewer to monitor.' Similar to the 'aspect ratio' setting, this exaggerates the effect of the 'tilt angle' setting that we'll be covering in just a moment. The default value of 2.0 is reasonable.

Increasing the value reduces the effect of the tilt angle:

Image

while lower values magnify it:

Image

Next, we have 'radius of curvature,' which determines how curved our simulated TV tube will be. Setting the value to 2.0 reduces the curvature to something more like what I remember.

Image

'Tilt angle' pincushions one side of the screen. To tilt the screen back, use a negative value for the second number. The default for the 'arcade tilt' variant, (0.0,-0.15), is a sane value:

Image

while increasing the second value tilts it back further, which can be disorienting:

Image

After that, we come to 'cornersize,' which determines the radius of the corner arc. I think a setting of 0.03, as used in the default image, looks appropriate. Increasing the value to 0.10 makes for some silly, super-round corners:

Image

while a value of 0.001 makes for super-pointy corners:

Image

For the last parameter in this section, we have 'cornersmooth,' which determines how sharp (sharp as in sharp/blur, not as in pointy) the corners look. The default value is 1000.0, which looks fine, but I noticed that if you set the value insanely low (i.e., 80), you get a little vignetting around the edges, which reminds me of my crummy old TVs:

Image

On to the next set of parameters.

The second set of options are either enabled or disabled by using 'comments,' which in this case are represented as a double-slash, like this //.

The first option is 'linear processing,' which enables interpolation of linear gamma:

Image

The effect is subtle, but disabling it via commenting it out (//#define LINEAR_PROCESSING) can improve the framerate with some video cards.

Next, we have 'Enable screen curvature.' Pretty self-explanatory, but if you comment this line out, you'll get straight top/bottom/sides of the screen, but with the corner arcs intact (barely visible in this shot):

Image

By commenting this out and setting 'cornersize' to 0.0, you get an idealized flat CRT tube, which is represented by the 'CRT-flat' shader variant:

Image

The next two options work together (that is, if you uncomment one, you should comment the other). By default, the shader uses 3x oversampling of the beam profile, which makes brighter pixels bleed further into the surrounding scanlines. Here it is with the default oversampling, scaled up 400% (look closely; it's most obvious on the bright red of Mario's sleeve):

Image

and here it is with the gaussian beam profile:

Image

The gaussian beam profile may have better performance on some video cards.

Those are all of the options available for the standard CRT shader, but there are a few more things we can add in. The first of which is support for interlaced video. Some games did a sort of fake doubling of their vertical resolution by showing different lines of a progressive signal on alternating frames in a process known as interlacing. If handled incorrectly, you will see a ton of combing artifacts (weird horizontal lines on moving objects), as well as distorted scanlines (first image taken using this older, non-interlace-supported version):

Image
Image

These pictures unfortunately cannot show the jutter in the lower image that occurs from showing different lines on each alternating frame.

The main content and most of the part of this tutorial was done by Hunter K.
Minor correction done by u-man

_________________
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."


Top
   
PostPosted: 01/05/2015, 11:18 
Offline
Admin
Admin
User avatar

Joined: 17/09/2014, 16:04
Posts: 695
Location: Italy
Very good tutorial.

I'll post some screenshots of my personal settings... Finally a shader which is no heavy resources demanding and that perfectly reproduces the look of a CRT monitor.

Very good job! :D


Top
   
PostPosted: 03/05/2015, 7:51 
Offline
Admin
Admin
User avatar

Joined: 17/09/2014, 16:04
Posts: 695
Location: Italy
Here we go with some snapshots of my settings:

Tiger Road:
Image

Ghosts'n'Goblins:
Image

Ghosts'n'Goblins (with Widescreen Stretch enabled):
Image

Blazing Star:
Image

Blazing Star (with Widescreen Stretch enabled):
Image

Knights Of The Round:
Image

Knights Of The Round (with Widescreen Stretch enabled):
Image

My settings:
// overscan (e.g. 1.02 for 2% overscan)
overscan = vec2(0.90,0.90);
// size of curved corners
cornersize = 0.01;


// Comment the next line to disable interpolation in linear gamma (and gain speed).
//#define LINEAR_PROCESSING
// Enable screen curvature.
//#define CURVATURE


Note that the gamma of my LCD is decreased in MAME options from 1.0 to 0.65.


Top
   
PostPosted: 18/05/2015, 10:42 
Offline
Novice
Novice

Joined: 17/05/2015, 18:54
Posts: 14
HI,
your screenshots are fantastic.
but I don't find this settings in the fileCRT-geom.vsh:

// Comment the next line to disable interpolation in linear gamma (and gain speed).
//#define LINEAR_PROCESSING
// Enable screen curvature.
//#define CURVATURE

please can you explain me how to add this or post your entire settings ?
thank you
regards


Top
   
PostPosted: 18/05/2015, 11:53 
Offline
Admin
Admin
User avatar

Joined: 17/09/2014, 16:04
Posts: 695
Location: Italy
austin3.16 wrote:
HI,
your screenshots are fantastic.
but I don't find this settings in the fileCRT-geom.vsh:

// Comment the next line to disable interpolation in linear gamma (and gain speed).
//#define LINEAR_PROCESSING
// Enable screen curvature.
//#define CURVATURE

please can you explain me how to add this or post your entire settings ?
thank you
regards


Hi, other settings are in the related .fsh file: CRT-Geom_rgb32_dir.fsh


Top
   
PostPosted: 18/05/2015, 13:29 
Offline
Novice
Novice

Joined: 17/05/2015, 18:54
Posts: 14
ah ok!
thank you.
I have one more time a problem using glsl crt geom.
I have a little tearing using it.
I have triple buffering active.
my hardware is nuc core i7 with integrted graphics iris 6100. (enough power it seem)
is there some options to do?
thank you.


Top
   
PostPosted: 18/05/2015, 13:56 
Offline
Admin
Admin
User avatar

Joined: 17/09/2014, 16:04
Posts: 695
Location: Italy
To avoid tearings in OpenGL, due to a MAME core bug, you have to enable in the MAMEUIFX interface "Sync to monitor refresh" and "Wait for vertical sync" options. Then, after done this step, go into your video card properties and check something similar to "Vertical sync always enabled" option. You have to enable it. I cannot be more precise because every video card has a different control panel, though it's always related to "3D options" and/or "OpenGL" options.
Let me know if you're ok now.


Top
   
PostPosted: 18/05/2015, 15:05 
Offline
Novice
Novice

Joined: 17/05/2015, 18:54
Posts: 14
it works thank you
I have enable v sync on my integrated graphic card and all is ok.
thank you, you are the man.


Top
   
PostPosted: 18/05/2015, 15:42 
Offline
Novice
Novice

Joined: 17/05/2015, 18:54
Posts: 14
I have a last problem (sorry, i'm perfectionnist)
when I launch mame in windowed mode like your screen, the scalines are perfectly even.
but when I launch in fullscreen on my lcd, the scanlines a little uneven.
is there a trick or specific settings to have the same on fullscreen,
thank you and sorry for all these questions.
regards


Top
   
PostPosted: 18/05/2015, 16:33 
Offline
Admin
Admin
User avatar

Joined: 17/09/2014, 16:04
Posts: 695
Location: Italy
Try with overscan values then. From 0.90 decrease to 0.89 or 0.88...... :?

Also consider that for VERTICAL games you need to use the CRT-Geom-VERT shader...


Top
   
Display posts from previous:  Sort by  
Forum locked  This topic is locked, you cannot edit posts or make further replies.  [ 26 posts ]  Go to page 1 2 3 Next

All times are UTC+02:00


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited