Dogway's grading shader (slang)

It boils down to the temperature function, it never converges to pure white as far I could check.

I did more changes to the temperature neutralization of the phosphor gamuts, this time by eye, they all should resemble white now but since they are correlated it might not be pure white.

For phosphor 0.0 I could bypass the temperature function altogether I think that would make most sense (since a CRT should always have a phosphor), what do you think?

https://pastebin.com/hmWWDyaH

3 Likes

This version looks a bit better but still has a noticable green tint to it. I agree that for phospor 0.0 it makes sense to bypass the temperature function altogether. Would be nice if you could make an update for us to compare/test. I assume the only thing not working anymore at phosphor setting 0.0 is the White Point setting, or does that still work and is only the “baked whitepoint” for phosphor 0 removed? Or are other things affected too?

1 Like

Here’s with the bypass, it will skip the white point setting only. You can try the previous version and try to find a white point that resembles white with phosphor 0 but as I said I think there’s no value that converges to pure white so probably this version is a better option.

If the issues with the glcore are fixed I can promote this to the repo.

https://pastebin.com/mVqZxWTn

By the way, on another note I wanted to add that it is the scanlines non-linear dynamics which messes with output gamma, if the beam dynamics follows a linear response it just messes with brightness but not the gamma curve. I do need to revise if the measured CRT gammas take into account scanlines or not, so far the best paper for CRT gamma is this one. An Accurate Characterization of CRT Monitor

4 Likes

Works as intended now. Issues with glcore are fixed also :+1:

Thanks for the link to the paper, I guess we would need more of those kind of analyses of the behaviour and chraracteristics of CRTs to better understand where we could make an advancement in emulation.

EDIT: I was intrigued by the different values for y for R, G and B for the P22 phosphors (in paragraph 2.1). Do you have a take on that? It seems it may be worth experimenting in a shader with separating the gamma for the three primaries in that way, or am I reading that all wrong?

1 Like

I understood the R,G,B separate gamma for the phosphor as simply the color characteristics of the phosphor, which are already emulated (3D LUTs would be an improvement though).

I think the next step for improvement would be on determining if the “standard” 2.50 gamma of CRTs are measured with scanlines, in which case absolute gamma output will heavily depend on scanline and TVL count and their non-linear response. It would be nice for the gamma_out to be aware of this non-linearity.

2 Likes

I gave the above paper a deeper read and finally got to some conclusions.

The mentioned CRT gamma of 2.5 is actually that of the electron gun, which after passing through phosphor’s intrinsic gamma (beam dynamics) yields a gamma of 2.2 or 2.25.

What this means is that I changed the default Game Embedded Gamma to 2.2, and the CRT Electron Gun Gamma to 2.50. (A_review_of_RGB_color_spaces)

I calculated what beam dynamic settings can yield a gamma of 0.88 (for 2.2) and 0.9 (for 2.25) for crt-royale and crt-guest-dr-venom shaders in this post.

Summary:

crt-royale: beam-min-sigma of 0.05 for 0.88 (2.2 absolute gamma output) and 0.10 for 0.9 (2.25 absolute gamma output).

crt-guest-dr-venom2: Scanline shape dark pixels of 1.50 for 0.88 (2.2 absolute gamma output) and 1.70 for 0.9 (2.25 absolute gamma output) (assumes scanline beam shape low of 14.0)

As a side note, brightness also gets affected by scanlines for about 10 or 15% so you have to compensate for that on your monitor settings if you want to reach a desired luminance level.

I updated the shader on my repo so this is prior to updating to master if everything goes well. https://github.com/Dogway/emulation-random/blob/master/RetroArch/Shaders/grade.slang

5 Likes

Small fix (download from repo above), “Sega Luma Fix” was bypassed when phosphor = 0.0. And cosmetics.

By the way I found the reference paper for the NTSC-J phosphor gamut (page 18), so it doesn’t look like I pulled it out of my… imagination lol

https://web.archive.org/web/20130413104152/http://arib.or.jp/english/html/overview/doc/4-TR-B09v1_0.pdf

2 Likes

Hey @dogway & @hunterk!

I’m trying to make sure I have the most up to date Grade,

The version I have is I think from December I think and looks like this:

#pragma parameter g_gamma_in     "Signal Gamma"                                            2.50 1.80 3.0 0.05
#pragma parameter g_gamma_out    "CRT Gamma"                                               2.50 1.80 3.0 0.05
#pragma parameter g_signal_type  "Signal Type (0:RGB 1:Composite)"                         1.0 0.0 1.0 1.0
#pragma parameter g_crtgamut     "Phosphor (1:NTSC-U 2:NTSC-J 3:PAL)"                      2.0 -4.0 3.0 1.0

and the current version in the retroarch repo looks like this:

#pragma parameter g_gamma_in     "Game Embedded Gamma"                                     2.222 1.80 3.0 0.05
    #pragma parameter g_gamma_out    "CRT Electron Gun Gamma"                                  2.50  1.80 3.0 0.05
    #pragma parameter g_signal_type  "Signal Type (0:RGB 1:Composite)"                         1.0 0.0 1.0 1.0
    #pragma parameter g_crtgamut     "Phosphor (1:NTSC-U 2:NTSC-J 3:PAL)"                      2.0 -4.0 3.0 1.0

Just saying but those are identical, just the “flavor” text is different.

Is there any actually changes in code?

If you send the December copy to me, I can go over them I guess lol.

1 Like

Looks like there are a fair amount of changes

Here’s the file: https://1drv.ms/u/s!AlJgyN_LYasyx7c-Jeum189-l9F_2g?e=mBec8M

The diff between the two of them looks like this:

I took a look at dogway’s git and what is in there was updated december 10th and also matches what is in the retroarch repo

1 Like

Ok I think that the one in the libretro repo (and Dogway’s repo) are the latest as they have the most detailed comments.

And it would of course make sense that Dogway’s repo is the latest

6 Likes

Why is grade failing to load again? Something about the LUT?

[ERROR] [slang]: Texture name 'SamplerLUT1' not found in semantic map, Probably the texture name or pass alias is not defined in the preset (Non-semantic textures not supported yet)
[ERROR] [slang]: Failed to reflect SPIR-V. Resource usage is inconsistent with expectations.
[ERROR] [GLCore]: Failed to create preset: "C:\RetroArch-Win64\shaders\retroarch.slangp".
[ERROR] [GLCore]: Failed to create filter chain: "C:\RetroArch-Win64\shaders\retroarch.slangp". Falling back to stock.
1 Like

This is probably because SamplerLUT1 is missing from the textures = line or the SamplerLUT1 = line is missing in your preset

Yeah I don’t get it :stuck_out_tongue:

Do you know what I need to add, specifically, to the preset file? Grade is great, but I’ve only ever been able to get it to work with guest-dr-venom. I tried adding all the samplerlut stuff from GDV’s preset to the preset I’m trying to load, but no dice.

2 Likes

Just straight swap the passes, remove the color profiles or w/e it’s called from guest and swap grade into its place.

Some assembly may be required!

Or are you trying to run grade in a completely none guest related preset/chain?

1 Like

Yeah I’m trying to add grade to geom because reasons

3 Likes

So you just need to add this

4 Likes

Thanks! :smiley: I was just missing the textures = line.

2 Likes

Now I’m getting this, no other errors:

[ERROR] [GLCore]: Failed to load LUT "C:\RetroArch-Win64\shaders\shaders\guest\advanced\lut\trinitron-lut.png".
[ERROR] [GLCore]: Failed to create preset: "C:\RetroArch-Win64\shaders\test.slangp".
[ERROR] [GLCore]: Failed to create filter chain: "C:\RetroArch-Win64\shaders\test.slangp". Falling back to stock.

:thinking:

1 Like

I think it can’t find the texture at that path.

You probably need to adjust the path to an existing texture.

2 Likes