Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CinemachinePostProcessing force first weight to 1

Discussion in 'Cinemachine' started by TimHeijden2, Mar 11, 2022.

  1. TimHeijden2

    TimHeijden2

    Joined:
    Aug 11, 2016
    Posts:
    86
    In working with Cinemachine & PostProcessing package I encountered an issue with using multiple virtual camera's with different post processing overrides. My setup is as follows:

    1. Global Virtual Camera (A)
    2. Camera Zone B (inside building)
    3. Camera Zone C (inside another area inside the building)

    In blending the camera's between B & C, I noticed that most post processing settings were "snapping" instead! I would have expected the weight of volumes to be used so I looked into the CinemachinePostProcessing code, and found this:
    Code (CSharp):
    1.  
    2.            CameraState state = brain.CurrentCameraState;
    3.             int numBlendables = state.NumCustomBlendables;
    4.             List<PostProcessVolume> volumes = GetDynamicBrainVolumes(brain, ppLayer, numBlendables);
    5.             for (int i = 0; i < volumes.Count; ++i)
    6.             {
    7.                 volumes[i].weight = 0;
    8.                 volumes[i].sharedProfile = null;
    9.                 volumes[i].profile = null;
    10.             }
    11.             PostProcessVolume firstVolume = null;
    12.             int numPPblendables = 0;
    13.             for (int i = 0; i < numBlendables; ++i)
    14.             {
    15.                 var b = state.GetCustomBlendable(i);
    16.                 var profile = b.m_Custom as PostProcessProfile;
    17.                 if (!(profile == null)) // in case it was deleted
    18.                 {
    19.                     PostProcessVolume v = volumes[i];
    20.                     if (firstVolume == null)
    21.                         firstVolume = v;
    22.                     v.sharedProfile = profile;
    23.                     v.isGlobal = true;
    24.                     v.priority = s_VolumePriority - (numBlendables - i) - 1;
    25.                     v.weight = b.m_Weight;
    26.                     ++numPPblendables;
    27.                 }
    28. #if true // set this to true to force first weight to 1
    29.                 // If more than one volume, then set the frst one's weight to 1
    30.                 if (numPPblendables > 1)
    31.                     firstVolume.weight = 1;
    32. #endif
    33.  
    At the bottom, note the #if true definition. Once I set this to false the blending seems to work as I would expect it to. However, I'm afraid of any unintended consequences that I may not be aware of. (and why this is "true by default").

    Is there a specific reason for this solution? Are there any known issues as to why this is set to TRUE? Couldn't this just be a setting, what am I missing?
     
  2. TimHeijden2

    TimHeijden2

    Joined:
    Aug 11, 2016
    Posts:
    86
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Sorry for the delayed response.
    If setting it to false fixes the problem for you, then go for it. It's there to address a specific depth-of-field blending issue. Without it, if you have no global depth-of field set, you might get weird DoF blending. If you have a global DoF volume (or no DoF effects), you should be ok either way.
     
  4. TimHeijden2

    TimHeijden2

    Joined:
    Aug 11, 2016
    Posts:
    86
    Thanks for the clarification. I am indeed using global DoF volume so all good!