Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How do I access Post Processing at runtime?

Discussion in 'High Definition Render Pipeline' started by Nubaa, May 3, 2021.

  1. Nubaa

    Nubaa

    Joined:
    Apr 30, 2013
    Posts:
    18
    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:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering.HighDefinition;
    5.  
    6.  
    7. public class UserSettings : MonoBehaviour
    8. {
    9.     private UnityEngine.Rendering.VolumeProfile volumeProfile;
    10.     private UnityEngine.Rendering.HighDefinition.LiftGammaGain gamma;
    11.  
    12.     private void Start()
    13.     {
    14.         volumeProfile = GetComponent<UnityEngine.Rendering.Volume>()?.profile;
    15.         if (!volumeProfile) throw new System.NullReferenceException(nameof(UnityEngine.Rendering.VolumeProfile));
    16.         if (!volumeProfile.TryGet(out gamma)) throw new System.NullReferenceException(nameof(gamma));
    17.     }
    18.  
    19.     public void AdjustGamma(float value)
    20.     {
    21.         gamma.gamma.value = new Vector4(value, value, value, 0);
    22.     }
    23. }
    Any suggestions? For reference, I'm using HDRp 7.3.1 and Unity 2019.4
     
  2. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    Y-Hello there,

    is working like this:

    Code (CSharp):
    1.  
    2. public float gammaValue;
    3. void Update()
    4. {
    5.       gamma.gamma.value = new Vector4(gammaValue, gammaValue, gammaValue, gammaValue);
    6. }
    7.  
     
    Nubaa likes this.
  3. Nubaa

    Nubaa

    Joined:
    Apr 30, 2013
    Posts:
    18
    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:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.Rendering.HighDefinition;
    6.  
    7.  
    8. public class UserSettings : MonoBehaviour
    9. {
    10.     private LiftGammaGain gamma;
    11.     private Volume volume;
    12.    
    13.     private void Start()
    14.     {
    15.         volume = GetComponent<Volume>();
    16.         volume.profile.TryGet<LiftGammaGain>(out gamma);
    17.     }
    18.  
    19.     public void AdjustGamma(float value)
    20.     {
    21.         gamma.gamma.value = new Vector4(1f, 1f, 1f, value);
    22.      
    23.     }
    24. }
     
  4. M4dR0b

    M4dR0b

    Joined:
    Feb 1, 2019
    Posts:
    108
    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.
     
  5. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,866
    Yes, it is correct...
    R,G,B,Intensity