Hi I'm using Unity 2019.1.1f1 and the LWRP.
I want to change the Focus Distance of the Depth of Field Effect using Post Processing.
I've read all of the numerous posts on here and still don't have an answer.
With the following code and a properly setup Profile on a PostProcessingVolume on my camera I can get the Focus Distance to update and change in the inspector properly during run time, but the actual depth of field does not change from it's original setting when the game began?
[SerializeField]
private PostProcessVolume postProcessVolume;
[SerializeField]
private DepthOfField DOF;
void Awake ()
{
postProcessVolume = camera.gameObject.GetComponent();
postProcessVolume.profile.TryGetSettings(out DOF);
}
void Update ()
{
RaycastHit hitInfo;
Ray rayDOF = new Ray(camera.transform.position, camera.transform.forward);
if (Physics.Raycast(rayDOF, out hitInfo))
{
FloatParameter newFocusDistance = new FloatParameter { value = Vector3.Distance(camera.transform.position, hitInfo.point) };
DOF.enabled.value = true;
DOF.focusDistance.value = newFocusDistance;
}
else
{
DOF.enabled.value = true;
DOF.focusDistance.value = 200f;
}
}
Do I have to apply this effect after making changes?
Is there some method to call?
What am I missing here?
I've searched everywhere and can't find the answer.
Thanks all! :)
Gaff
↧