118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
namespace Beyond
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class AnimatedDof : MonoBehaviour
|
|
{
|
|
[Header("Mode")]
|
|
public DepthOfFieldMode mode = DepthOfFieldMode.Off;
|
|
public bool overrideMode;
|
|
|
|
[Header("Gaussian")]
|
|
public float start = 0f;
|
|
public bool overrideStart;
|
|
[Space]
|
|
public float end = 0f;
|
|
public bool overrideEnd;
|
|
[Space]
|
|
[Range(0.5f, 1.5f)]
|
|
public float maxRadius = 0.5f;
|
|
public bool overrideMaxRadius;
|
|
[Space]
|
|
public bool highQualitySampling;
|
|
public bool overrideHighQualitySampling;
|
|
|
|
[Header("Bokeh")]
|
|
[Min(0.1f)]
|
|
public float focusDistance = 0.1f;
|
|
public bool overrideFocusDistance;
|
|
[Space]
|
|
[Range(1f, 300f)]
|
|
public float focalLength = 1f;
|
|
public bool overrideFocalLength;
|
|
[Space]
|
|
[Range(1f, 32f)]
|
|
public float aperture = 1f;
|
|
public bool overrideAperture;
|
|
[Space]
|
|
[Range(3, 9)]
|
|
public int bladeCount = 3;
|
|
public bool overrideBladeCount;
|
|
[Space]
|
|
[Range(0f, 1f)]
|
|
public float bladeCurvature = 0f;
|
|
public bool overrideBladeCurvature;
|
|
[Space]
|
|
[Range(-180f, 180f)]
|
|
public float bladeRotation = -180f;
|
|
public bool overrideBladeRotation;
|
|
|
|
private Volume volume;
|
|
private DepthOfField testDoF;
|
|
|
|
private void UpdateDof()
|
|
{
|
|
if (volume == null)
|
|
{
|
|
volume = gameObject.GetComponent<Volume>();
|
|
}
|
|
if (volume != null && testDoF == null)
|
|
{
|
|
volume.profile.TryGet(out testDoF);
|
|
}
|
|
|
|
if (testDoF != null && overrideMode)
|
|
{
|
|
testDoF.active = true;
|
|
testDoF.mode.overrideState = overrideMode;
|
|
testDoF.mode.value = this.mode;
|
|
|
|
if (mode == DepthOfFieldMode.Gaussian)
|
|
{
|
|
testDoF.gaussianStart.overrideState = overrideStart;
|
|
testDoF.gaussianStart.value = start;
|
|
|
|
testDoF.gaussianEnd.overrideState = overrideEnd;
|
|
testDoF.gaussianEnd.value = end;
|
|
|
|
testDoF.gaussianMaxRadius.overrideState = overrideMaxRadius;
|
|
testDoF.gaussianMaxRadius.value = maxRadius;
|
|
|
|
testDoF.highQualitySampling.overrideState = overrideHighQualitySampling;
|
|
testDoF.highQualitySampling.value = highQualitySampling;
|
|
}
|
|
else if (mode == DepthOfFieldMode.Bokeh)
|
|
{
|
|
testDoF.focusDistance.overrideState = overrideFocusDistance;
|
|
testDoF.focusDistance.value = focusDistance;
|
|
|
|
testDoF.focalLength.overrideState = overrideFocalLength;
|
|
testDoF.focalLength.value = focalLength;
|
|
|
|
testDoF.aperture.overrideState = overrideAperture;
|
|
testDoF.aperture.value = aperture;
|
|
|
|
testDoF.bladeCount.overrideState = overrideBladeCount;
|
|
testDoF.bladeCount.value = bladeCount;
|
|
|
|
testDoF.bladeCurvature.overrideState = overrideBladeCurvature;
|
|
testDoF.bladeCurvature.value = bladeCurvature;
|
|
|
|
testDoF.bladeRotation.overrideState = overrideBladeRotation;
|
|
testDoF.bladeRotation.value = bladeRotation;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
UpdateDof();
|
|
}
|
|
}
|
|
}
|
|
|