Post processing effects

Hello can anyone help me increment the intensity setting on the post processing vignette via script?
I looked at the API and im having a hard time wrapping my head around it

For further context, im making a script that increases the vignette intensity setting by 1 as Time.delta time increases

Are you using either the post-processing in HDRP, or Post Processing Stack V2?

If so, then you should be able to get a handle on the Vignette object. Make sure youā€™ve check the box to allow overrides to the intensity. Then, in code, you can just do something like this:

_postProcessingVignette.intensity.Override(someFloatValue);

That will set the intensity to whatever ā€˜someFloatValueā€™ equals. If you want to do this over time, you can either set this in an Update statement, or in a coroutine.

Iā€™m using post processing stack V2, im not quiet sure how to call it.

i tried making a public vignette
but I canā€™t drag it in

Your script should have a public property for either the VolumeProfile, or the Volume that the profile is on. Then you can call profile.GetComponent<Vignette>() to get the Vignette component.

Hereā€™s a simplified example from my code. This is using HDRPā€™s post processing, but I think itā€™s nearly identical to V2.

public Volume RenderVolume;

private Vignette _postProcessingVignette;

void Start() {
    _postProcessingVignette = RenderVolume.profile.GetComponent<Vignette>();
}

void Update() {
    _postProcessingVignette.intensity.Override(whateverTheIntensityShouldBe);
}

apparently ā€œPost processprofile does not contain a defnition for get componentā€
what should i used instead?

You probably have a typo or something. Show your code, both the code that calls GetComponent, and the code that declares the variable youā€™re calling it on.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

public class PostProcessing : MonoBehaviour
{
    public PostProcessVolume RenderVolume;

    private Vignette _postProcessingVignette;

    void Start()
    {
        _postProcessingVignette = RenderVolume.profile.GetComponent<Vignette>();
    }

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

        _postProcessingVignette.intensity.Override(1);
    }
}

Ah, sorry about that. My fault. I completely forgot I created an extension method (a code shortcut) so I could call GetComponent on a volume. Instead, of GetComponent, youā€™ll need something like this:

(Note: This is for HDRP. For PPv2, change ā€œcomponentsā€ to ā€œsettingsā€.)
_postProcessingVignette = RenderVolume.profile.components.FirstOrDefault(c => c is Vignette) as Vignette;

Be sure to add using System.Linq; to use this.

And hereā€™s that extension method, though, in case you want to use it, since the above code is kind of awkward:

    public static class VolumeProfileUtil
    {

        public static T GetComponent<T>(this VolumeProfile profile) where T : VolumeComponent
        {
            // Note: This is for HDRP. For PPv2, change "components" to "settings".
            return profile.components.FirstOrDefault(s => s is T) as T;
        }

    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using System.Linq;

public class PostProcessing : MonoBehaviour
{
    public PostProcessVolume RenderVolume;

    private Vignette _postProcessingVignette;

    void Start()
    {
        _postProcessingVignette = RenderVolume.profile.components.FirstOrDefault(c => c is Vignette) as Vignette;
    }

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

        _postProcessingVignette.intensity.Override(1);
    }


}

components still seems to be highlighted and saying there is no assembly reference

Looks like in HDRP, itā€™s called ā€œcomponentsā€, while in PPv2 itā€™s called ā€œsettingsā€. Just change ā€œ.componentsā€ to ā€œ.settingsā€ and I think it should work.

1 Like

You are my hero thank you so much