How do I access Post Processing at runtime?

I’m trying to add a brightness/gamma slider. I’ve succeeded in modifying the values, but it doesn’t actually change the game’s brightness. Based on what I’ve read, it sounds like there may be an instance that I’m not actually grabbing? Here’s the code I’m using right now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;


public class UserSettings : MonoBehaviour
{
    private UnityEngine.Rendering.VolumeProfile volumeProfile;
    private UnityEngine.Rendering.HighDefinition.LiftGammaGain gamma;

    private void Start()
    {
        volumeProfile = GetComponent<UnityEngine.Rendering.Volume>()?.profile;
        if (!volumeProfile) throw new System.NullReferenceException(nameof(UnityEngine.Rendering.VolumeProfile));
        if (!volumeProfile.TryGet(out gamma)) throw new System.NullReferenceException(nameof(gamma));
    }

    public void AdjustGamma(float value)
    {
        gamma.gamma.value = new Vector4(value, value, value, 0);
    }
}

Any suggestions? For reference, I’m using HDRp 7.3.1 and Unity 2019.4

Y-Hello there,

is working like this:

public float gammaValue;
void Update()
{
      gamma.gamma.value = new Vector4(gammaValue, gammaValue, gammaValue, gammaValue);
}
1 Like

Oh, I didn’t realize the ‘w’ value had any meaning, since the override in the inspector only shows the x,y,z values. Speaking of that, when you increase the gamma in the inspector, it increases the x,y,z values up to a max of 2. I have no idea why Unity chose to do that, because in code, increasing the w value is what actually increases the overall gamma, and the color values have a max of 1. To shift the color hues, you reduce the x,y,z values, but their max is actually 1.

So essentially, the inspector values don’t actually match the values in code. I haven’t seen 1 iota of documentation on this, so that’s cool. /s

Rant aside, thanks for your help.

Also here’s the final code for anyone that might stumble upon this in the future and need the full solution:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;


public class UserSettings : MonoBehaviour
{
    private LiftGammaGain gamma;
    private Volume volume;
   
    private void Start()
    {
        volume = GetComponent<Volume>();
        volume.profile.TryGet<LiftGammaGain>(out gamma);
    }

    public void AdjustGamma(float value)
    {
        gamma.gamma.value = new Vector4(1f, 1f, 1f, value);
     
    }
}

I’ve not checked that out much in deep either, but I believe (x,y,z,w) would stand for (r,g,b, intensity) where r,g,b is a range 0 to 1.

Yes, it is correct…
R,G,B,Intensity