I am trying to fade a chromatic aberration effect in and out triggered by a keypress, though I don’t know where to start. There seems to be little documentation on controlling post processing via code.
I need it to fade in/out over time period x, and if you take your finger off the key while it is in the middle of the fade, it just fades back out from there.
In terms of controlling a post processing volume, first you need using UnityEngine.Rendering.PostProcessing; at the top. you can then make a public PostProcessVolume variable - you can assign this in the inspector or set it manually. you can also create a ChromaticAberration variable. To get a reference to it, you could do something like if(vol.profile.TryGetSettings(out chromaticAberration)) // run update code
Does that help? you might want to explain the whole fade in/out process a bit clearer if you also want direct help with that. but this is how I would go about updating the post process.
EDIT: you can then edit the ChromaticAberration variable through dot notation - chromaticAberration.intensity.value for example.
I am quite new to scripting, so a more in-depth explanation might help :). I’m really not sure on how to even go about creating a post process variable
I was trying to get it to work with DOTween, however it seems more fiddly than what you are proposing.
Also, do you need to set a post process layer on the camera/volume on an empty gameObject?
I must admit I’ve never used DOTween, and so I have no idea how that works. As for the post process layer, That I think should go on the gameobject with the camera component. You then want to make a separate gameobject with the post process volume on it. I would then advise creating a new layer (probably called postprocess) and set the volume gameobject to the new layer and the volume blending layer on the post process layer to it as well.
Have you actually got the post process to a point where it is working and you can see it in the game?
Yes, I’m ok with settings up post effects normally, through the inspector. I was just asking that because you mentioned a post process volume variable. I don’t really know much about it on the scripting side of things
EDIT:
I’ve had a look and a mess about. I know how to turn the effect on and off with a keypress, however, I’m still at a loss as to how to fade the effect.
Ok so I’ve solved my issue, but I’m going to post it here in case anybody else has the same issue I had.
The variables at the top are there so that I don’t have to hard-code the values one by one when I want to make a change. As well as the chromatic aberration, I also added some vignette. With the ‘upper’ and ‘lower’, suffixes on the intensity varaibles, I wanted to keep some vignette there when I was playing normally. I did the same for the aberration, as I really don’t like having values that are not in easy to access variables. This can basically be extended to any post-processing effect you want; just change the names.
You do not need any effects in the post process volume in the inspector, as you are making your own in this script, though I found it helpful when choosing values to create one, view how it would look in-game, then remove it and add it to the script.
Hi my code wont work also do i need to add any layers? and where do i attach the scripts i attached it to camera and the game object with the Volume script.