170 lines
5.1 KiB
C#
170 lines
5.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
public class PostProcessChangeValuesAtRuntime : MonoBehaviour
|
|
{
|
|
[SerializeField] private Volume PostProcess;
|
|
public bool IsUpdatingValues;
|
|
private Bloom bloom;
|
|
private LensDistortion lensDistortion;
|
|
private ChromaticAberration chromaticAberration;
|
|
private DepthOfField depthOfField;
|
|
private Vignette vignette;
|
|
private ColorAdjustments colorAdjustments;
|
|
//private ColorGrading colorGrading;
|
|
private float DefaultWeight;
|
|
|
|
[Header("Post Process weight")]
|
|
[SerializeField] private float weight;
|
|
|
|
[Header("Bloom")]
|
|
[SerializeField] private float bloomIntensity;
|
|
|
|
[Header("Lens Distortion")]
|
|
[SerializeField] private float lensDistortionIntensity;
|
|
[SerializeField] private float centerX;
|
|
[SerializeField] private float centerY;
|
|
|
|
[Header("Chromatic Aberration")]
|
|
[SerializeField] private float chromaticAberrationIntensity;
|
|
[SerializeField] private bool chromaticAberrationActive;
|
|
|
|
[Header("Depth Of Field")]
|
|
[SerializeField] private float focusDistance;
|
|
[SerializeField] private float aperature;
|
|
[SerializeField] private float focalLength;
|
|
[SerializeField] private float nearMaxRadiusBlur;
|
|
[SerializeField] private float farMaxRadiusBlur;
|
|
[SerializeField] private bool depthOfFieldActive;
|
|
|
|
[Header("Color Grading")]
|
|
[SerializeField] private float liftRed;
|
|
[SerializeField] private float liftGreen;
|
|
[SerializeField] private float liftBlue;
|
|
[SerializeField] private float Lift;
|
|
|
|
[Header("Vignette")]
|
|
[SerializeField] private Color vignetteColor;
|
|
[SerializeField] private float vignetteIntensity;
|
|
|
|
[Header("Color Adjustments")]
|
|
[SerializeField] private float postExposure;
|
|
|
|
//private static PostProcessChangeValuesAtRuntime _instance;
|
|
//public static PostProcessChangeValuesAtRuntime GetInstance() { return _instance; }
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
//if (!_instance)
|
|
//{
|
|
// _instance = this;
|
|
//}
|
|
if (PostProcess == null)
|
|
{
|
|
PostProcess = GetComponent<Volume>();
|
|
}
|
|
|
|
DefaultWeight = PostProcess.weight;
|
|
|
|
PostProcess.profile.TryGet(out bloom);
|
|
PostProcess.profile.TryGet(out lensDistortion);
|
|
PostProcess.profile.TryGet(out chromaticAberration);
|
|
PostProcess.profile.TryGet(out depthOfField);
|
|
PostProcess.profile.TryGet(out vignette);
|
|
PostProcess.profile.TryGet(out colorAdjustments);
|
|
//PostProcess.profile.TryGetSettings(out colorGrading);
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (IsUpdatingValues)
|
|
{
|
|
PostProcess.weight = weight;
|
|
|
|
#region Bloom
|
|
if (bloom != null)
|
|
{
|
|
bloom.intensity.value = bloomIntensity;
|
|
}
|
|
#endregion
|
|
|
|
#region Lens Distorition
|
|
if (lensDistortion != null)
|
|
{
|
|
lensDistortion.intensity.value = lensDistortionIntensity;
|
|
lensDistortion.xMultiplier.value = centerX;
|
|
lensDistortion.yMultiplier.value = centerY;
|
|
}
|
|
#endregion
|
|
|
|
#region Chromatic Aberration
|
|
if (chromaticAberration != null)
|
|
{
|
|
chromaticAberration.intensity.value = chromaticAberrationIntensity;
|
|
chromaticAberration.active = chromaticAberrationActive;
|
|
}
|
|
#endregion
|
|
|
|
#region Depth Of Field
|
|
//depthOfField.focusDistance.value = focusDistance;
|
|
//depthOfField.aperture.value = aperature;
|
|
//depthOfField.focalLength.value = focalLength;
|
|
depthOfField.active = depthOfFieldActive;
|
|
depthOfField.nearMaxBlur = nearMaxRadiusBlur;
|
|
depthOfField.farMaxBlur = farMaxRadiusBlur;
|
|
#endregion
|
|
|
|
#region Color Grading
|
|
//colorGrading.lift.value = new Vector4(liftRed, liftGreen, liftBlue, Lift);
|
|
//Debug.Log(colorGrading.lift.value);
|
|
#endregion
|
|
|
|
#region Vignette
|
|
if (vignette != null)
|
|
{
|
|
vignette.intensity.value = vignetteIntensity;
|
|
vignette.color.value = vignetteColor;
|
|
}
|
|
#endregion
|
|
|
|
#region Color Adjustments
|
|
if (colorAdjustments != null)
|
|
{
|
|
colorAdjustments.postExposure.value = postExposure;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
public void RestoreValues()
|
|
{
|
|
weight = DefaultWeight;
|
|
|
|
bloomIntensity = 0f;
|
|
lensDistortionIntensity = 0f;
|
|
centerX = 0f;
|
|
centerY = 0f;
|
|
chromaticAberrationIntensity = 0f;
|
|
|
|
focusDistance = 0f;
|
|
aperature = 0.1f;
|
|
focalLength = 0f;
|
|
nearMaxRadiusBlur = 0f;
|
|
farMaxRadiusBlur = 0f;
|
|
depthOfFieldActive = false;
|
|
|
|
vignetteIntensity = 0f;
|
|
|
|
postExposure = 0f;
|
|
}
|
|
}
|