Gamma correction

https://github.com/MiSTer-devel/Main_MiSTer/wiki

Moderators: Mug UK, Zorro 2, Greenious, spiny, Sorgelig, Moderator Team

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Gamma correction

Postby paulbnl » Fri Sep 27, 2019 10:51 pm

Back in the day graphic designers were making content that was viewed on a CRT. A CRT has a very different gamma curve compared to an LCD display. Low and mid-tones are much darker on a CRT.

So the designers compensated for this by brightening the darker parts. If the content is viewed on an LCD then the gamma needs to be corrected.

Here is an album with pictures comparing SNES original and gamma corrected screenshots to photos of a CRT.
https://imgur.com/a/sEOsvMm

I propose adding an option to Mister.ini that enables gamma correction for HDMI. The analog output does not need it because a CRT will most likely be connected to that output anyway.

Here is a build of the SNES core with always-on gamma correction on HDMI if someone wants to try it.
https://drive.google.com/file/d/12FrBLfYS4wFAs95T9qJdAtH-goV8lmGT/view?usp=sharing

ghogan42
Atari maniac
Atari maniac
Posts: 97
Joined: Wed Oct 17, 2018 7:27 pm

Re: Gamma correction

Postby ghogan42 » Sat Sep 28, 2019 12:09 am

paulbnl wrote:Back in the day graphic designers were making content that was viewed on a CRT. A CRT has a very different gamma curve compared to an LCD display. Low and mid-tones are much darker on a CRT.

So the designers compensated for this by brightening the darker parts. If the content is viewed on an LCD then the gamma needs to be corrected.

Here is an album with pictures comparing SNES original and gamma corrected screenshots to photos of a CRT.
https://imgur.com/a/sEOsvMm

I propose adding an option to Mister.ini that enables gamma correction for HDMI. The analog output does not need it because a CRT will most likely be connected to that output anyway.

Here is a build of the SNES core with always-on gamma correction on HDMI if someone wants to try it.
https://drive.google.com/file/d/12FrBLfYS4wFAs95T9qJdAtH-goV8lmGT/view?usp=sharing


Those screenshots look good. Is that just a normal gamma correction of (RGB)^(2.5/2.2) or so?

I did that to the Genesis core a while back and nobody seemed interested then.

Btw, Grabulosaure indicated in the past that ACAL's support for paletted color could be used for gamma correction without adding new hardware to ASCAL. Presumably because the palette LUT could be a gamma LUT table instead.

Presonally I'd like to have: gamma 2.5 to linear gamma 1.0, then interpolated/scaled in the ACAL, and then finally converted to the output gamma 2.2. That would be best for quality but I understand that that is more work for little gain.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Sat Sep 28, 2019 8:05 am

paulbnl wrote:Here is an album with pictures comparing SNES original and gamma corrected screenshots to photos of a CRT.
https://imgur.com/a/sEOsvMm

I propose adding an option to Mister.ini that enables gamma correction for HDMI.


Your gamma corrected version looks so much better. I am always for color accuracy, so that is a definitive "yes, please do it" from me.

PS: The day we can have an accurate simulation of CRT on TFT it will be a giant breakthrough for emulation. CRTs are dying out after all.

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sat Sep 28, 2019 9:14 am

ghogan42 wrote:
Those screenshots look good. Is that just a normal gamma correction of (RGB)^(2.5/2.2) or so?

I did that to the Genesis core a while back and nobody seemed interested then.

Btw, Grabulosaure indicated in the past that ACAL's support for paletted color could be used for gamma correction without adding new hardware to ASCAL. Presumably because the palette LUT could be a gamma LUT table instead.

Presonally I'd like to have: gamma 2.5 to linear gamma 1.0, then interpolated/scaled in the ACAL, and then finally converted to the output gamma 2.2. That would be best for quality but I understand that that is more work for little gain.


I chose a correction of 1.35. A CRT seems to be darker than that but I don't want to lose too much detail in the darker areas.

It is implemented as a simple 8bit lookup table before going into the scaler. You really only want to do gamma correction one time only because you lose some color steps every time.

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5372
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Gamma correction

Postby Sorgelig » Sat Sep 28, 2019 9:24 am

paulbnl wrote:Here is an album with pictures comparing SNES original and gamma corrected screenshots to photos of a CRT.
https://imgur.com/a/sEOsvMm

Gamma corrected looks like cheap monitor with weird colors ;)

SegaMan
Atari maniac
Atari maniac
Posts: 83
Joined: Sat Oct 27, 2018 12:59 pm

Re: Gamma correction

Postby SegaMan » Sat Sep 28, 2019 9:35 am

paulbnl wrote:
Here is an album with pictures comparing SNES original and gamma corrected screenshots to photos of a CRT.
https://imgur.com/a/sEOsvMm



I like the idea!

It may be because of the camera but the CRT images in the link are awful and in no way representative of a good CRT image.

Was the CRT and LCD screen calibrated? Or how did you determine the gamma value?
On my benq gaming monitor the gamma core looks too dark and many details are lost.

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sat Sep 28, 2019 9:38 am

Sorgelig wrote:Gamma corrected looks like cheap monitor with weird colors ;)


If you say cheap monitor then I think about washed out colors which describes the screenshots with original colors. Imgur doesn't show the descriptions clearly but the darker screenshots are the corrected ones.

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sat Sep 28, 2019 10:01 am

SegaMan wrote:
I like the idea!

It may be because of the camera but the CRT images in the link are awful and in no way representative of a good CRT image.

Was the CRT and LCD screen calibrated? Or how did you determine the gamma value?
On my benq gaming monitor the gamma core looks too dark and many details are lost.


Yea the photos of the CRT are awful but it shows colors are much darker on CRT. Although the camera exaggerates it.

I determined the gamma value by comparing the CRT to my LCD monitor and adjusting the gamma in a photo editor. I made sure the darkest values were not clipping.

With SNES the darkest colors gamma corrected are 0, 2, 6, 11 instead of 0, 8, 16, 24 so if you are losing details on your monitor then you should check its settings.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Sat Sep 28, 2019 10:13 am

SegaMan wrote:I like the idea!

It may be because of the camera but the CRT images in the link are awful and in no way representative of a good CRT image.

Was the CRT and LCD screen calibrated? Or how did you determine the gamma value?
On my benq gaming monitor the gamma core looks too dark and many details are lost.


Because of this issue of calibration there will be no reliable feedback from users unless they have calibrated screens that can at least do 100% sRGB (my BenQ gaming monitor has only about 90% and it shows). Thus I looked at the gamma corrected images on a hardware calibrated Eizo in sRGB mode and the changes paulbnl made are much better than the original image.

@paulbnl @sorgelig do you think it would be possible to have a customizable gamma setting that could be tweaked in the .ini, or a menu option in the cores' OSD?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5372
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Gamma correction

Postby Sorgelig » Sat Sep 28, 2019 10:36 am

I think gamma correction can be added on core side and add OSD option for different gamma corrections.
It can be done on slow clock areas. Doing it on system level where video clock is high, will add more instabilities.
It's just can be a pass-through module where you can enable/disable the gamma corrections.

As for screenshots - it highly depends on display. On my monitor video looks perfect without any additional corrections. Not like that washed out overbrighted screenshots.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Sat Sep 28, 2019 11:13 am

Sorgelig wrote:On my monitor video looks perfect without any additional corrections. Not like that washed out overbrighted screenshots.


Are you sure? The first image is the original, which is brighter and "washed out" on my end. The darker images with crisper colors are the gamma corrected ones, judging by the image descriptions.

But yes, you are definetly right, every monitor looks different unless they are calibrated. I only comment on which gamma looks better to me here, because I have such a monitor that I calibrate with a colorimeter on a regular note. Calibrated is the only possible reference value but, because monitors usually are not calibrated, it would be super helpful if the gamma curve could be individually set up.

Sorgelig wrote:I think gamma correction can be added on core side and add OSD option for different gamma corrections.
It can be done on slow clock areas. Doing it on system level where video clock is high, will add more instabilities.
It's just can be a pass-through module where you can enable/disable the gamma corrections.


That would be absolutely great if you found the time to implement such an option!

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sat Sep 28, 2019 9:27 pm

Threepwood wrote:
Because of this issue of calibration there will be no reliable feedback from users unless they have calibrated screens that can at least do 100% sRGB (my BenQ gaming monitor has only about 90% and it shows). Thus I looked at the gamma corrected images on a hardware calibrated Eizo in sRGB mode and the changes paulbnl made are much better than the original image.

@paulbnl @sorgelig do you think it would be possible to have a customizable gamma setting that could be tweaked in the .ini, or a menu option in the cores' OSD?


I just always make sure my displays show the grayramp of the 240p test correctly without clipping.

My Samsung monitor by default on the HDMI input has terrible overscan, sharpening and contrast clipping the darker shades. Luckily this garbage can be disabled.

I'm thinking about making gamma correction switchable between Off, 1.2, 1.3 and 1.4.

Sorgelig wrote:I think gamma correction can be added on core side and add OSD option for different gamma corrections.
It can be done on slow clock areas. Doing it on system level where video clock is high, will add more instabilities.
It's just can be a pass-through module where you can enable/disable the gamma corrections.


The problem with adding it at the core side is that the gamma correction will be applied at both the HDMI and analog output.

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 5372
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Gamma correction

Postby Sorgelig » Sat Sep 28, 2019 10:17 pm

paulbnl wrote:The problem with adding it at the core side is that the gamma correction will be applied at both the HDMI and analog output.

User will be able to switch it off if not required.

JamesF
Captain Atari
Captain Atari
Posts: 155
Joined: Sat Dec 15, 2018 6:46 am

Re: Gamma correction

Postby JamesF » Sun Sep 29, 2019 7:25 am

CRT gamma ranged from 2.1 to 2.5, depending on where you set your 'brightness' control.
A well behaving studio CRT is standard 2.2 with clearly visible black shades, just like well behaved IPS LCD panel.
Those 'gamma corrected' images in the first post are way too dark, actually, my sony trinitron looks remarkably similar to what I see on my calibrated Dell IPS panel, and I calibrate all my displays with the i1 Display Pro.

Start calibration by clearly seeing all the black and white steps in this test pattern on the CRT using the 'brightness' control.
More likely the final image will be much brighter (and closer to 2.1-2.2 gamma) than using the black only test pattern.
Image
All shades should be clearly visible on your LCD too, (16 is complete black, 235 is complete white).

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sun Sep 29, 2019 10:10 am

JamesF wrote:CRT gamma ranged from 2.1 to 2.5, depending on where you set your 'brightness' control.
A well behaving studio CRT is standard 2.2 with clearly visible black shades, just like well behaved IPS LCD panel.
Those 'gamma corrected' images in the first post are way too dark, actually, my sony trinitron looks remarkably similar to what I see on my calibrated Dell IPS panel, and I calibrate all my displays with the i1 Display Pro.


Unless your CRT has a gamma adjust you can't change the curve because adjusting brightness just offsets the curve. So when viewing identical content on an LCD the CRT must be darker.

The games in the album that I posted are obviously designed for a display with a darker gamma than an LCD.

The pillars in the far background of the first Mortal Kombat screenshot should be dark, not grey.

The dark shadow parts just above and below the sand in the donkey Kong country screenshot should not have easily visible details.

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Sun Sep 29, 2019 7:29 pm

I have added a new build to the link which has a selectable gamma correction. Unfortunately because the correction now happens at the core side the analog output is also affected by the gamma correction so directly comparing a CRT with an LCD is not possible.

https://drive.google.com/file/d/12FrBLfYS4wFAs95T9qJdAtH-goV8lmGT/view?usp=sharing

JamesF
Captain Atari
Captain Atari
Posts: 155
Joined: Sat Dec 15, 2018 6:46 am

Re: Gamma correction

Postby JamesF » Mon Sep 30, 2019 5:47 am

It works.
The jump from Off to 1.2 is too big, maybe add 1.1 instead of 1.4?
1.4 is much darker than any real display I've seen and I still believe that no gamma correction is needed on any properly calibrated display.

If I understood gamma power calculation correctly (1.1*2.2=2.42), and typical gamma ranges from 2.2 to say 2.6. (very dark) then;
Maybe even 8 options ranging from 0.95 to 1.30 with 0.05 jumps ranging from 2.1 to 2.86 gamma would be more useful?
The 1.3 value is too dark and equals to 2.86 gamma which no display even had,, as most CRT and LCD displays gamma range from 2.1 to 2.4.

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Mon Sep 30, 2019 3:44 pm

Ok I have added another build that goes from 1.1 to 1.3. Although I find the difference between 1.0 and 1.1 to be very small.

I prefer the 1.3 setting myself. It looks similar to my CRT.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Mon Sep 30, 2019 6:34 pm

paulbnl wrote:Ok I have added another build that goes from 1.1 to 1.3. Although I find the difference between 1.0 and 1.1 to be very small.

I prefer the 1.3 setting myself. It looks similar to my CRT.


I tried your cores with Mortal Kombat and Super Mario World on my TV and I use at least gamma 1.3, sometimes 1.4. Gamma off looks way too bright and washed out once I tried it and not like it was intended that way.

Personally I prefer your second core that goes from 1.2 to 1.4.

JamesF
Captain Atari
Captain Atari
Posts: 155
Joined: Sat Dec 15, 2018 6:46 am

Re: Gamma correction

Postby JamesF » Tue Oct 01, 2019 6:43 am

1.3 and 1.4 equals to a gamma (transfer function) of 2.86 and 3.08 which no display has/had, CRT or otherwise, regardless how good it looks to you.

I think the problem here is most LCD displays start deviating from 2.2 for the black shades and become closer to a gamma of 1 (brighter) as the shades become darker,, the reason for this is CRTs have more contrast ratio and can follow closer to ideal power curve further down the darker shades where LCD can't.
As said, most LCD screens (TVs, PC monitors) would have a sRGB gamma curve instead of true true 2.2 to 2.4 power curve, where above 0.5 (128) input it will have a gamma of 2.2, and gradually lower gamma below 0.5 input,, sometimes called "black compensated gamma curve" for LCD screens.
https://commons.wikimedia.org/wiki/File:SRGB_gamma.svg

I believe the true problem here is the darker shades simply appear darker on a CRT because of the above, and raising the gamma curve to 2.8-3.0 for the entire image on a LCD is a (very) wrong solution as it makes the middle and brighter shades completely off.

Plus, this is a cosmetic fix for the very last part of the chain and not a part of the core/console in any way, the core should not be responsible for fixing a mediocre/poor LCD display.
An idea on discord by Kitrinx was to use DSP for LUTs for each gamma curve using shaders/filters.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Tue Oct 01, 2019 9:37 am

@JamesF, out of curiosity what exact Dell IPS and what CRT are you using?

paulbnl
Atari maniac
Atari maniac
Posts: 75
Joined: Wed Oct 24, 2018 9:43 am

Re: Gamma correction

Postby paulbnl » Tue Oct 01, 2019 10:31 am

JamesF wrote:1.3 and 1.4 equals to a gamma (transfer function) of 2.86 and 3.08 which no display has/had, CRT or otherwise, regardless how good it looks to you.

I think the problem here is most LCD displays start deviating from 2.2 for the black shades and become closer to a gamma of 1 (brighter) as the shades become darker,, the reason for this is CRTs have more contrast ratio and can follow closer to ideal power curve further down the darker shades where LCD can't.
As said, most LCD screens (TVs, PC monitors) would have a sRGB gamma curve instead of true true 2.2 to 2.4 power curve, where above 0.5 (128) input it will have a gamma of 2.2, and gradually lower gamma below 0.5 input,, sometimes called "black compensated gamma curve" for LCD screens.
https://commons.wikimedia.org/wiki/File:SRGB_gamma.svg

I believe the true problem here is the darker shades simply appear darker on a CRT because of the above, and raising the gamma curve to 2.8-3.0 for the entire image on a LCD is a (very) wrong solution as it makes the middle and brighter shades completely off.

Plus, this is a cosmetic fix for the very last part of the chain and not a part of the core/console in any way, the core should not be responsible for fixing a mediocre/poor LCD display.
An idea on discord by Kitrinx was to use DSP for LUTs for each gamma curve using shaders/filters.


All LCD displays (should) use the sRGB color space and that's whats this gamma adjustment is for. CRTs simply have a different gamma curve as you said and if you want to calibrate your CRT to be the same as an LCD that's up to your but consoles meant for CRT will look too bright.

I don't know if you know how a gamma curve works but the brighter shades are almost not affected by gamma correction.

In practice a gamma adjustment of 1.3 looks just right. That's on my LCD TV and monitor and my TV is definitely not a poor display.

In fact Byuu even recommends a darker correction of 1.5 on his page: https://byuu.net/video/color-emulation

A good example is Super Metroid. The backgrounds are supposed to be quite dark so they look more distant but on an sRGB LCD their brightness is closer to the brightness of the foreground most of the time.

There are only 2 bits left for options in the core so I can only add 3 gamma levels. I am leaning towards 1.2-1.4 because 1.1 is such a small change from 1.0.

JamesF
Captain Atari
Captain Atari
Posts: 155
Joined: Sat Dec 15, 2018 6:46 am

Re: Gamma correction

Postby JamesF » Tue Oct 01, 2019 10:46 am

Yes, I know how gamma works, proper display calibration is one of my main hobbies. :)

So I figured a polynomial gamma with 2.8 up to 0-30% input, and gradually returning to 2.2 above that should be good enough to 'reverse' the native sRGB curve of LCDs.
The problematic part is that 0-30% input region and is where we should concentrate,, a whole gamma curve of 2.8 to 3.0 is not what you want to do regardless of what bsnes does, and no, it doesn't look good on a properly calibrated LCD display.

Can you make a test build with that function:: Out=2(in)^3.15 - (in)^4.4 ?
Should look natural and closer to a CRT.

https://i.imgur.com/GlIeIXj.png
Image
Last edited by JamesF on Tue Oct 01, 2019 11:24 am, edited 1 time in total.

Threepwood
Atari maniac
Atari maniac
Posts: 79
Joined: Thu Jan 10, 2019 10:06 am

Re: Gamma correction

Postby Threepwood » Tue Oct 01, 2019 11:22 am

Since JameF did not reply to my question let me explain why, in my opinion, many arguments here are moot:

As long as a monitor has no hardware LUT the calibration is gone when using a different device, like the MiSTer. Without a hardware LUT inside the display, calibration is a software LUT in the OS of your PC. Once disconnected all that is left on your LCD/CRT is a calibrated white point and brightness, but these throw off the colors when no LUT is used.

It also makes no sense to blame "poor/mediocre" LCD displays (in professional graphics where color accuracy counts Dell is the mediocre cheapo, by the way). The consoles and computers emulated here were setup for CRT or really old LCD and expecting the user to setup their display to match this (which is usually not even possible) would throw off all other modern applications and is thus unreasonable. Additionally professional displays are usually slower than normal consumer displays without hardware LUT and latency (input lag) is more important than color accuracy when actually playing a game.

Thus it only makes sense to have the individual cores offer a correction. They were meant for long out of production displays so it is indeed their responsibility to offer a correction suitable for their tech used (CRT and old LCD).

I agree to paulbnl. 1.1 is not a useful gamma setting in this scenario. @paulbnl: Would it be possible to integrate a reference image, like many games use them to roughly calibrate gamma (e.g. The Mark of the Ninja and many horror games) that says "adjust gamma till [object] is barely visible"?

JamesF
Captain Atari
Captain Atari
Posts: 155
Joined: Sat Dec 15, 2018 6:46 am

Re: Gamma correction

Postby JamesF » Tue Oct 01, 2019 11:26 am

Dell U2410 IPS with wide gamut CCFL backlight calibrated with i1 Display Pro in srgb color space, ICC in windows, 3DLUT in MadVR.
2002 Sony Trinitron KV-29FX30, also calibrated.

Again, these 1.2-1.4 number which result in 2.64 to 3.08 gamma is a ridiculously wrong thing to do,, especially if it is baked into the core.
I understand you advocate for this because for some reason it looks good on your display to your eyes (very subjective), but we don't want something like this permanent in a core especially if it is a purely cosmetic feature and done wrong (imo).


Return to “MiSTer”

Who is online

Users browsing this forum: No registered users and 3 guests