I am currently creating my own custom settings object for saving custom properties such as gameplay relevant stuff and so on. Additionally I just want to let the user choose the desired gamma level of the entire game (e.g. for ■■■■■■ dark screens). I have found the console command
GAMMA float
does that for me. The default value is about 2.2.
But nor I want to implement my “ApplySettings” method in a much more elegant way and I try to avoid calling console commands in my C++ object (which btw inherits from UGameUserSettings class).
Maybe you guys can help me finding the property or setter that I have to use to trigger the change of the gamma level via C++? Any ideas? I do not have any clue where I should start searching.
You are in luck. Here’s a code snippet for updating a PostProcessVolume’s gamma from C++ code.
This is an actor placed in the world, then given a reference to a PostProcessVolume, which it can control the settings of. It can be used to reasonable simulate dynamic light changes in a baked light map. LightColorType is a custom enum which can be ignored.
The only trick is you have to set the override boolean and change the gamma.
void APPVSettings::UpdatePostProcessVolume(TSoftObjectPtr<APostProcessVolume> ppv, LightColorType type)
{
if (ppv)
{
// time to do some scene color grading and pick what color
// we will subtly tint the scene based on the light color type
FVector4 gammaShadows = FVector4(1, 1, 1, 1);
FVector4 gammaMidtones = FVector4(1, 1, 1, 1);
if (type == LightColorType::OFF) { gammaShadows = FVector4(0.9, 0.9, 0.9, 1.0); gammaMidtones = FVector4(0.9, 0.9, 0.9, 1.0); }
else if (type == LightColorType::WHITE) { gammaShadows = FVector4(1.0, 1.0, 1.0, 1.0); gammaMidtones = FVector4(1.0, 1.0, 1.0, 1.0); }
else if (type == LightColorType::RED) { gammaShadows = FVector4(1.3, 1.0, 1.0, 1.0); gammaMidtones = FVector4(1.1, 1.0, 1.0, 1.0); }
else if (type == LightColorType::BLUE) { gammaShadows = FVector4(1.0, 1.0, 1.3, 1.0); gammaMidtones = FVector4(1.0, 1.0, 1.0, 1.1); }
// overriding shadow and midtones only with the goal
// of leaving the bright spaces outside the minimally affected
ppv->Settings.bOverride_ColorGammaShadows = true;
ppv->Settings.bOverride_ColorGammaMidtones = true;
ppv->Settings.ColorGammaShadows = gammaShadows;
ppv->Settings.ColorGammaMidtones = gammaMidtones;
}
}