Skip to content

GS: Add gamma control to ShadeBoost #12653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gonzalosilvalde
Copy link
Contributor

Description of Changes

  • Add a Gamma parameter to ShadeBoost shaders (OpenGL & Vulkan).
  • Expose a Gamma slider in the Qt Graphics Settings and the fullscreen in-game menu.

Rationale behind Changes

Gamma control lets users adjust mid-tones independently of brightness/contrast/saturation. Fulfills feature request #12515.

Suggested Testing Steps

  • Open PCSX2.
  • Emulate a game.
  • Open graphics settings.
  • Go to Postprocessing.
  • Adjust Gamma as you see fit.

@RedDevilus
Copy link
Contributor

Don't forget to format your files correctly, there are spaces where there have to be tabs, like for example:

image

(Using refined github extension in my browser to easily detect)

@Gonzalosilvalde
Copy link
Contributor Author

Gonzalosilvalde commented May 12, 2025

I had a doubt about that, I saw those weird spacing in the git diff but in my text editor don't appear. I would see if I can change them.

@JordanTheToaster
Copy link
Member

I had a doubt about that, I saw those weird spacing in the git diff but in my text editor don't appear.

You are using spaces not tabs.

@Gonzalosilvalde
Copy link
Contributor Author

I still have errors...

@@ -30,6 +30,7 @@ vec4 ContrastSaturationBrightness(vec4 color)
float brt = params.x;
float con = params.y;
float sat = params.z;
float gam = params.w;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still using spaces here.

@Gonzalosilvalde
Copy link
Contributor Author

I think it's ok now, sorry for the problems.

@JordanTheToaster
Copy link
Member

Do you plan to add these to Direct3D 11 and 12?

@Gonzalosilvalde
Copy link
Contributor Author

I hadn’t planned on it, but I have no problem doing it if you’d like. At a glance, it should be pretty much the same.

@JordanTheToaster
Copy link
Member

It would be good to have it on all backends if possible.

@Gonzalosilvalde
Copy link
Contributor Author

I believe this change is sufficient for Direct3D 11 and 12, but I have no way to verify that it works. I would appreciate it if someone could test it so I can make any necessary adjustments.

@Mrlinkwii
Copy link
Contributor

Mrlinkwii commented May 12, 2025

idk if the shadercache version needs bumped

@KrossX
Copy link
Contributor

KrossX commented May 12, 2025

Tested on the Windows side, the following changes makes the dx11 shader changes work.

 	float3 satColor = lerp(intensity, brtColor, sat);
 	float3 conColor = lerp(AvgLumin, satColor, con);
 	
-	vec3 csb = conColor;
-	csb = pow(csb, vec3(1.0 / gam));
+	float gam_inv = 1.0/gam;
+	float3 csb = conColor;
+	csb = pow(csb, float3(gam_inv, gam_inv, gam_inv));
 	color.rgb = csb;
 	return color;

Also, the new GUI control does not follow the enable/disable state from the shadeboost checkbox. Other than that, it seems to work. 👍

color.rgb = conColor;

vec3 csb = conColor;
csb = pow(csb, vec3(1.0 / gam));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float3, same for the above.

@@ -4334,6 +4334,8 @@ void FullscreenUI::DrawGraphicsSettingsPage(SettingsInterface* bsi, bool show_ad
"ShadeBoost_Contrast", 50, 1, 100, "%d", shadeboost_active);
DrawIntRangeSetting(bsi, FSUI_CSTR("Shade Boost Saturation"), FSUI_CSTR("Adjusts saturation. 50 is normal."), "EmuCore/GS",
"ShadeBoost_Saturation", 50, 1, 100, "%d", shadeboost_active);
DrawIntRangeSetting(bsi, FSUI_CSTR("Shade Boost Gamma"), FSUI_CSTR("Adjusts gamma. 50 is normal."), "EmuCore/GS",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move it between contrast and saturation to keep alphabetical order, same for other places.

Copy link
Contributor

@lightningterror lightningterror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metal remaining.

@AmandaRoseChaqueta
Copy link

AmandaRoseChaqueta commented May 12, 2025

Minor bug (idk if it's exclusive to linux) but probably would be a good idea to position these buttons better on the blank space we have free. Currently it looks like this on 1080p screen
Screenshot_20250512_164635

Also, you can edit it even without having Shade Boost selected.
image

@KrossX
Copy link
Contributor

KrossX commented May 13, 2025

That might be good for another PR, to make that tab more organized. There's probably enough room for nice sliders too while at it.

@Gonzalosilvalde
Copy link
Contributor Author

In this last commit I have changed:

  • Now you can enable/disable the state from the shade boost box.
  • In dx11/shadeboost.fx use a float3 and not a vec3 (needs test).
  • Added gamma in metal (needs test).
  • All 'shade boost' options are in alphabetical order.

What I didn't do:

  • I don't know what @Mrlinkwii is referring to when he says “shadercache version needs bumped”, if someone explains it to me I do it no problem.
  • I didn't position the buttons better in the white space as @AmyRoxwell suggested. As @KrossX said, I think it should go in another PR.

As is obvious, if any problems are encountered whether in dx11/12 or metal I'll be glad to fix them.

@kamfretoz
Copy link
Contributor

* I don't know what @Mrlinkwii is referring to when he says “shadercache version needs bumped”, if someone explains it to me I do it no problem.

https://github.com/PCSX2/pcsx2/blob/master/pcsx2/ShaderCacheVersion.h#L6

You'll want to increment the shader cache version by one.

Copy link
Member

@TellowKrinkle TellowKrinkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macOS compile is failing because cb in Metal is currently declared as a float3, which has no w. You should change it to a float4.

@@ -417,6 +417,7 @@ fragment float4 ps_shadeboost(float4 p [[position]], DirectReadTextureIn<float>
const float brt = cb.x;
const float con = cb.y;
const float sat = cb.z;
const float gam = cb.w;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const float gam = cb.w;
const float gam = cb.w;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants