Search Unity

Question Setting Lift-Gamma-Gain values from C# script? (URP, Post-Processing v2)

Discussion in 'Universal Render Pipeline' started by FlyingCreator222, Nov 22, 2020.

  1. FlyingCreator222

    FlyingCreator222

    Joined:
    Dec 11, 2019
    Posts:
    1
    So I want to change values of a "Lift Gamma Gain" element located in a volume profile asset.
    There is a major problem though. I have been unable to find code reference for doing that and I am uncertain whether the change from code is even possible.
    The value I'm mostly intereseted in is gain.
    Is there any way to change that from my script? Thanks beforehands :)
     
  2. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    205
    Here is my setup that only changes the "alpha" of the Gamma portion of ListGammaGain (the slider beneath the Gamma section). But it should be enough to figure out the rest, the color wheel is just the x/y/z parts of the Vector4.

    Code (CSharp):
    1. public class LiftGammaGainController : MonoBehaviour
    2. {
    3.  
    4.     public static LiftGammaGainController instance;
    5.  
    6.     [HideInInspector] public Volume renderingVolume;
    7.     LiftGammaGain liftGammaGain;
    8.  
    9.     private void Awake() {
    10.         instance = this;
    11.         renderingVolume = GetComponent<Volume>();
    12.         if (!renderingVolume.profile.TryGet(out liftGammaGain)) throw new System.NullReferenceException(nameof(liftGammaGain));
    13.     }
    14.  
    15.     public void SetGammaAlpha(float gammaAlpha) {
    16.         liftGammaGain.gamma.Override(new Vector4(1f, 1f, 1f, gammaAlpha));
    17.     }
    18.  
    19.     public float GetGammaAlpha() { return liftGammaGain.gamma.value.w; }
    20.  
    21.  
    22. }
    23.  
     
    exitshadow likes this.