1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Unity] Access to the PostProcess from script

Last updated at Posted at 2024-10-28

[Built-in render pipeline]

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

using UnityEngine.Rendering.PostProcessing;
    [SerializeField] PostProcessVolume m_vol;

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

    PostProcessProfile profile = m_vol.profile;
    m_colorGrading = profile.GetSetting<ColorGrading>();

3.
and edit parameters.

PostProcessBuiltinChanger.cs
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);
        }
    }
}
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;
    [SerializeField] UnityEngine.Rendering.Volume m_vol;

2nd of all, TryGet() the effect.

    LiftGammaGain m_liftGammaGain
        m_liftGammaGain = null;
        m_vol.profile.TryGet(out m_liftGammaGain);

3.
and edit parameters.

PostProcessURPChanger.cs
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);
        }
    }
}
image.png image.png
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?