DEV Community

m2048
m2048

Posted on

[Unity] Access to the PostProcess from script

[Built-in render pipeline]

1st of all, import UnityEngine.Rendering.PostProcessing,
and get the PostProcessVolume.

using UnityEngine.Rendering.PostProcessing;
Enter fullscreen mode Exit fullscreen mode
    [SerializeField] PostProcessVolume m_vol;
Enter fullscreen mode Exit fullscreen mode

2nd of all, get the PostProcessProfile and get the effect you want.

    PostProcessProfile profile = m_vol.profile;
    m_colorGrading = profile.GetSetting<ColorGrading>();
Enter fullscreen mode Exit fullscreen mode

3.
and edit parameters.

using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

namespace PostProcessBuiltinChangerDemo
{
    public class PostProcessBuiltinChanger : MonoBehaviour
    {
        [SerializeField] PostProcessVolume m_vol;
        ColorGrading m_colorGrading;

        // Start is called once before the first execution of Update after the MonoBehaviour is created
        void Start()
        {
            PostProcessProfile profile = m_vol.profile;
            m_colorGrading = profile.GetSetting<ColorGrading>();
        }

        // Update is called once per frame
        void Update()
        {
        }

        public void OnSetGamma(float _value)
        {
            Vector4Parameter gamma = m_colorGrading.gamma;
            gamma.value = new Vector4(1f, 1f, 1f, _value);
            m_colorGrading.gamma = gamma;
            Debug.Log("gamma: " + gamma.value);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
image.png image.png

[Universal render pipeline(URP)]

1st of all, import UnityEngine.Rendering.Universal,
and get the UnityEngine.Rendering.Volume.

using UnityEngine.Rendering.Universal;
Enter fullscreen mode Exit fullscreen mode
    [SerializeField] UnityEngine.Rendering.Volume m_vol;
Enter fullscreen mode Exit fullscreen mode

2nd of all, TryGet() the effect.

    LiftGammaGain m_liftGammaGain
Enter fullscreen mode Exit fullscreen mode
        m_liftGammaGain = null;
        m_vol.profile.TryGet(out m_liftGammaGain);
Enter fullscreen mode Exit fullscreen mode

3.
and edit parameters.

using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace PostProcessURPChangerDemo
{
    public class PostProcessURPChanger : MonoBehaviour
    {
        [SerializeField] UnityEngine.Rendering.Volume m_vol;
        LiftGammaGain m_liftGammaGain;

        // Start is called once before the first execution of Update after the MonoBehaviour is created
        void Start()
        {
            m_liftGammaGain = null;
            m_vol.profile.TryGet(out m_liftGammaGain);
        }

        // Update is called once per frame
        void Update()
        {
        }

        public void OnSetGamma(float _value)
        {
            m_liftGammaGain.gamma.value = new Vector4(1f, 1f, 1f, _value);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
image.png image.png

Top comments (0)