Does anyone know how to get Vignette in unity C#?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.PostProcessing; public class VignetteController : MonoBehaviour { public PostProcessVolume postProcessVolume; private Vignette vignette; private float startIntensity; public float maxIntensity = 0.7f; // You can change this value to your desired maximum intensity public float decreaseSpeed = 0.5f; // The speed at which the intensity decreases private void Start() { if (postProcessVolume == null) { Debug.LogError("Post-Process Volume is not assigned!"); this.enabled = false; return; } // Try to get the Vignette effect from the volume if (!postProcessVolume.profile.TryGetSettings(out vignette)) { Debug.LogError("Vignette is not found in the Post-Process Volume!"); this.enabled = false; return; } // Cache the initial intensity startIntensity = vignette.intensity; } public void SetVignetteIntensity(float target) { float targetValue = Mathf.Lerp(startIntensity, maxIntensity, target); if (targetValue < vignette.intensity.value) return; vignette.intensity.value = targetValue; } private void Update() { if (vignette.intensity > startIntensity) { // Gradually decrease the intensity over time vignette.intensity.value -= decreaseSpeed * Time.deltaTime; // Make sure the intensity doesn't go below the initial value vignette.intensity.value = Mathf.Max(vignette.intensity, startIntensity); } } }
using UnityEngine.Rendering.PostProcessing;
is the namespace:
public PostProcessVolume postProcessVolume;
private Vignette vignette;
is the volume
if (!postProcessVolume.profile.TryGetSettings(out vignette))
{
Debug.LogError("Vignette is not found in the Post-Process Volume!");
this.enabled = false;
return;
}
gets the vignette settings
then vignette.intensity.value controls it
For URP: using UnityEngine.Rendering.Universal; using UnityEngine.Rendering; using UnityEngine; public class VignetteManager : MonoBehaviour { public Volume volume; private Vignette vignette; private void Start() { if (volume.profile.TryGet(out vignette)) { // The vignette was found and assigned successfully. // You can now use the 'vignette' variable to modify the vignette properties. } } }