Hello All,
I’m struggling a bit on this one. I have a cinemachine virtual camera with Volume Settings extension and a chromatic aberration override.
I am just trying to change via code the intensity of the chromatic aberration but can’t seem to be able to find anywhere how to access it.
I can see with
foreach (UnityEngine.Rendering.VolumeComponent volumeComponent in volumeSettings.m_Profile.components) {
Debug.Log(volumeComponent.name);
}
That a component with name “ChromaticAberration” exist. I also think that the class I want to use is
UnityEngine.Rendering.HighDefinition.ChromaticAberration
How can I now convert the VolumeComponent into the ChromaticAberration so I can change its intensity?
Thanks
Is there a reason why the chromatic aberration effect is attached to the vcam’s volume? Can you instead just make a global volume with only that effect and adjust the volume’s weight? That would be the easiest approach.
Thank you very much for your reply. I am using Cinemachine and HDRP, I thought that in this case the global volume does not work. If I try to set up a post processing layer and volume I don’t see any change in the game view.
Is there a way to use the post processing global volume with Cinemachine and HDRP? If not, is there a way to acces the components in the vcam’s volume?
I found a way to do it:
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
public class PostProcessingManager : MonoBehaviour
{
public Cinemachine.PostFX.CinemachineVolumeSettings volumeSettings;
private LensDistortion lensDistortion;
private ChromaticAberration chromaticAberration;
void Start()
{
foreach (VolumeComponent volumeComponent in volumeSettings.m_Profile.components) {
if (volumeComponent.name == "LensDistortion") lensDistortion = volumeComponent as LensDistortion;
if (volumeComponent.name == "ChromaticAberration") chromaticAberration = volumeComponent as ChromaticAberration;
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.M)) {
if (chromaticAberration) {
chromaticAberration.intensity.value = 1f;
chromaticAberration.intensity.overrideState = true;
}
}
if (Input.GetKeyDown(KeyCode.N)) {
if (chromaticAberration) {
chromaticAberration.intensity.value = 0f;
chromaticAberration.intensity.overrideState = true;
}
}
}
}