Search Unity

Post Effects Stack V1 - DOF Focal Point and Lens Distortion

Discussion in 'Image Effects' started by Ikaruga7, Mar 3, 2017.

  1. Ikaruga7

    Ikaruga7

    Joined:
    Jan 16, 2016
    Posts:
    6
    What would the process be if I wanted to animate the focal point of the DOF using the new post stack? Similalry do I need a different profile for every camera that I want a different focal distance?

    Will the lens distrotion (Barrel Distortion), from the latest Standard Assets package be added to the stack at some point?
     
  2. Ikaruga7

    Ikaruga7

    Joined:
    Jan 16, 2016
    Posts:
    6
    In case anyone else is interested, I found the answer here for animating (following a transform) the focal point:

    https://forum.unity3d.com/threads/new-post-processing-stack-pre-release.435581/page-2

    I've taken the code snippet from there, and added a control to focus on a transform. I love these effects, they're fantastic, but I simply don't understand why this isn't simply a component. Every camera is going to need different settings, for the game camera and cutscenes, so the concept of the profiles is flawed. It's added complexity to something so simple as setting a focal distance on a camera?! If I want a pre-set, I can just make prefab, why do I need profiles as well?


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.PostProcessing;
    5.  
    6.  
    7. [RequireComponent(typeof(PostProcessingBehaviour))]
    8. public class PostProcessingController : MonoBehaviour {
    9.  
    10.     public bool m_FocusOnTransform = true;
    11.     public Transform m_LookAt;
    12.  
    13.     PostProcessingProfile m_Profile;
    14.  
    15.     void OnEnable()
    16.     {
    17.         var behaviour = GetComponent<PostProcessingBehaviour>();
    18.        
    19.                 if (behaviour.profile == null)
    20.                     {
    21.                         enabled = false;
    22.                         return;
    23.                     }
    24.        
    25.                 m_Profile = Instantiate(behaviour.profile);
    26.                 behaviour.profile = m_Profile;
    27.     }
    28.  
    29.     // Use this for initialization
    30.     void Start () {
    31.      
    32.     }
    33.  
    34.     // Update is called once per frame
    35.     void Update () {
    36.  
    37.         if (m_FocusOnTransform)
    38.             FocusOnTransform ();
    39.     }
    40.  
    41.     void FocusOnTransform()
    42.     {
    43.         var dof = m_Profile.depthOfField.settings;
    44.  
    45.         dof.focusDistance = Vector3.Magnitude (this.transform.position - m_LookAt.position);
    46.  
    47.         m_Profile.depthOfField.settings = dof;
    48.     }
    49. }
     
    Flurgle likes this.
  3. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Profiles have the benefit of being able to easily tweak graphics settings while in the game, but you raise some good points.