-2

I am trying to fade a chromatic aberration effect in and out triggered by a keypress, but not sure where to start.

I am using the built-in render pipeline.

There seems to be little documentation on controlling post processing via code. Please suggest any resources.

Malted
  • 76
  • 7
  • https://github.com/brunurd/unity-chromatic-aberration – Mattias May 18 '20 at 11:22
  • @Mattias I too have googled 'Chromatic Aberration'. It is included in Unity's post processing stack. What I am trying to find out is how to manipulate it using code. – Malted May 18 '20 at 11:36
  • Not sure exactly what you wanted so I pointed you to a repo that uses CA and have an example on how to "control" it by code here¬ https://github.com/brunurd/unity-chromatic-aberration/blob/master/Scripts/ChromaticAberration.cs – Mattias May 18 '20 at 11:39

1 Answers1

1

I am guessing you are using the post processing package. Here is a great resource to get some info on how to use it: https://docs.unity3d.com/Packages/com.unity.postprocessing@2.1/manual/Manipulating-the-Stack.html

The simplest way to manipulate an post-processing (pp) effect with this system is to override the settings of the pp profile.

Just reference the profile like every other asset in your scene, grab the ChromaticAberration setting and override the settings. Like this:

public PostProcessProfile profile;
private ChromaticAberration ca;
// Start is called before the first frame update
void Start()
{
    ca = profile.GetSetting<ChromaticAberration>();
}

// Update is called once per frame
void Update()
{
    ca.intensity.Override(Mathf.Sin(Time.frameCount * 0.1f));
}

To do the fading I advise you use a tweening library like they do in the example i linked. DoTween is great. If you don't want to do that you can always create your own coroutines and animate the behaviour.

Witt
  • 51
  • 3