Search Unity

FadeIn/FadeOut using Cinemachine !?

Discussion in 'Cinemachine' started by Vagabond_, Apr 17, 2018.

  1. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi, how one could add a black or white FadeIn/FadeOut with Cinemachine ?
    Want to start a cinematic cut with a fade in from black for example.

    I think one way could be adding a world space canvas to the camera with animator and toggle the canvas and animator components in timeline. In fact i just tried it but can not figure out how to toggle the animator component attached to the camera. I only can toggle the camera game object !

    Is there any more generic way of doing FadeIns and FadeOuts ?

    Thanks !
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If you're using CM 2.1.12, you can do it with a Storyboard extension on the vcam. Under the hood it's just a canvas, so it's a quick and easy way of doing what you're doing. To fade in/out, create an animation track for the vcam and animate the StoryboardExtension's alpha.
     
  3. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Thank You !
    That works perfect !
     
    Gregoryl likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Glad to hear it.

    Come to think of it, there's an even easier way: create a dummy vcam with a Storyboard extension on it. Use a black or white image. That vcam will be your "fade out" vcam - use it whenever needed. Make sure you check the "Mute Camera" checkbox, that will ensure that the vcam's transform will be ignored during blends:

    upload_2018-4-17_10-57-23.png

    Now, in the timeline, you can create fades wherever you want by overlapping clips of this vcam with other shot clips. You don't need to create animation tracks for the alpha.
     
  5. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Yes, that should be a bit cleaner as i am having now animator components and a storyboard components on all 3 virtual cameras. This way i will manage a single fade camera !
     
    Gregoryl likes this.
  6. Rob-Meade

    Rob-Meade

    Joined:
    Oct 27, 2016
    Posts:
    56
    Hi Gregory,

    I wonder if you may assist me with this a little. I am fairly new to cinemachine, in fact, just looking at it today.

    The scenario I have is a 2D platformer. Entry/Exit points on the left and right of the screen. I've managed to wire up the fade out based on your instuctions above, the player collides with a boxcollider2d on the right hand side, an animation trigger is set, the camera fades to black. What I can't seem to work out is how to do the reverse, not using Cinemachine anyway.

    I can create the same triggering based on the player arriving in the scene, but I can't seem to find a way to change the alpha from 1 to 0?

    Any help would be really appreciated.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If you're not using timeline, it's simply a matter of setting the "black" vcam to a higher priority, and enabling it when you want to fade to black, and disabling it when you want to fade back in. Let CM's blending handle it.
     
  8. LAKSHAYMAVIA

    LAKSHAYMAVIA

    Joined:
    Aug 28, 2018
    Posts:
    27
    Hey Gregory,
    Thank you for Helping, I want to make fade in and out animation when the camera changes. Right now I am just fading the alpha of an image using script when player collide with cinemachine camera change collider. I want to achieve this.



    Time :- between 2:48 sec to 2:53 sec.

    Is there any way I can do that using cinemachine using storyboard or with anything else?
    Thank you.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes. Do as it says here: https://forum.unity.com/threads/fadein-fadeout-using-cinemachine.527164/#post-3465043

    To fade to black, enable the "black" storyboard vcam. To fade back out, disable it and enable some other vcam.

    You can to the enabling/disabling from script, or by just activating a new vcam for the new shot, and playing a short timeline just before with a CM track that has a clip with the black vcam fading in and out, masking the cut.
     
  10. LAKSHAYMAVIA

    LAKSHAYMAVIA

    Joined:
    Aug 28, 2018
    Posts:
    27

    Thank you so much. Now I think I am able to grasp what you are saying. Sorry I haven't use timeline before so I don't know It's functionality much. Thank you so much for your guidance.
     
  11. Tugatsu_e

    Tugatsu_e

    Joined:
    Oct 17, 2018
    Posts:
    1
    Hey.
    1.On assets store is only CM 2.1.10 version. So I cant add new storyboard script to my camera:( Ant others idea how i can add FadeIn/Out ?
    2. I want smooth blend transition between two camera, is possible? like in this movie
     
    Last edited: Apr 3, 2019
    gilyon01150115 likes this.
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Last edited: Apr 3, 2019
  13. JZYKrystal

    JZYKrystal

    Joined:
    Dec 24, 2018
    Posts:
    3
    hi, i am using cnimachine version 2.3.4 and i can not find storyboard script in CM package. why is that??
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I don't know. Where are you looking? It's here:

    upload_2019-10-15_10-0-12.png
     
    profitdefiant and javi_unity402 like this.
  15. JZYKrystal

    JZYKrystal

    Joined:
    Dec 24, 2018
    Posts:
    3
    found it
    thank you so much
     
  16. FoxProject

    FoxProject

    Joined:
    Aug 30, 2015
    Posts:
    2
    Edit: Okay when I play it in the editor it blends. It just didn't do it when playing the timeline.

    I've read post #2 and #4 a couple of times but can't figure it out. I have a vcam with a timeline. I have added another vcam to the timeline and want to fade between these two. I've created a third vcam with a Storyboard with alpha 1. I then add it to the timeline (by activating and deactivating it) overlapping the other ones but it just makes a clean cut without blend. What do I miss?
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I don't really understand. Are you just trying to get vcam A to blend to vcam B? If so, just create a CM clip for each, and overlap them. It will blend when the timeline runs. In this case, blend means that the position/orientation of the camera will lerp.

    If you want a cross-dissolve, that's another story. CM isn't designed to handle cross-dissolves, as that requires a separate render texture. However. it's possible to set it up. Look here: https://forum.unity.com/threads/is-...ages-instead-of-position.541865/#post-3573211
     
  18. javi_unity402

    javi_unity402

    Joined:
    Nov 29, 2018
    Posts:
    33
    Simple and effective. Thank you @Gregoryl
     
    Gregoryl likes this.
  19. Augis1980

    Augis1980

    Joined:
    Sep 23, 2014
    Posts:
    48
    If you are using UWRP Put this script On the Main Camera, and add Signal (FadeIn or fadeOut) in your Timeline

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. public class FadeOut : MonoBehaviour
    6. {
    7.  
    8.     Volume volume;
    9.  
    10.     VolumeProfile volprofile;
    11.     UnityEngine.Rendering.Universal.LiftGammaGain gamma;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         volume = GetComponent<Volume>();
    17.         volprofile = volume.profile;
    18.      
    19.         volprofile.TryGet(out gamma);
    20.  
    21.         Debug.Log(gamma);
    22.     }
    23.  
    24.     public void doFadeOut()
    25.     {
    26.         StartCoroutine(doFade(-1));
    27.      
    28.     }
    29.  
    30.     public void doFadeIn()
    31.     {
    32.         StartCoroutine(doFade(0.1f));
    33.     }
    34.  
    35.     IEnumerator doFade(float i)
    36.     {
    37.         for (float a = 0; a <= 1; a += Time.deltaTime*5)
    38.         {
    39.             float b;
    40.             if (i < 0)
    41.             {
    42.                 b = i * a;
    43.                 if (b < -0.85f) { b = i; }
    44.                    }
    45.  
    46.          
    47.             else
    48.             {
    49.                 b = -1+a;
    50.              
    51.                 if (b > -0.05f) { b = 0;}
    52.                 Debug.Log(b);
    53.             }
    54.          
    55.  
    56.             gamma.gain.Override(new Vector4(0, 0, 0, b));
    57.             yield return null;
    58.         }
    59.  
    60.  
    61.      
    62.  
    63.     }
    64. }
     
  20. kai303

    kai303

    Joined:
    Jun 9, 2016
    Posts:
    21
    I tried this trick with HDRP and in general it works, but I have an ugly 1 pixel border that is not covered by the black image of the virtual storyboard camera. I tried different scale modes for the image and also different image resolutions. I don't know, if this is a rounding bug in the boudaries of the image, or intentional, or just a stupid mistake by me ;)
     
    wlwl2 likes this.
  21. kai303

    kai303

    Joined:
    Jun 9, 2016
    Posts:
    21
    This is how it looks like shortly before the crossfade to black is complete. The error is visible on the left and on the right of the game view.
     

    Attached Files:

  22. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    This only happens in the editor, and it is not related to cinemachine. If you build your game and run it, then you won't see those pixel errors.
     
  23. kai303

    kai303

    Joined:
    Jun 9, 2016
    Posts:
    21
    The problem is, that I use Unity Recorder to capture high quality movies from my camera shots. I use the recorder window(!) to capture these movies from the game view and that includes the ugly pixel border.

    So, if I understand you correctly, one way to get rid off the pixels would be to capture the movie not from the recorder window, but from a timeline track instead. This however would mean that I always have to build an executable in order to get a movie without the pixels.
    This is a little bit uncomfortable because it will slow down my workflow - but I will give it a try.

    Thanks a lot for your fast reply!
     
  24. kai303

    kai303

    Joined:
    Jun 9, 2016
    Posts:
    21
    I just tested to build and execute and the pixel border is visible even there!
     
  25. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hmm, sorry, I must have overlooked something then... I could reproduce it now. Looking into it.
     
    Last edited: Jan 13, 2021
  26. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Found and fixed the bug. Thank you for reporting it, kai303. The fix will be available in the next release.
     
    AffectusGames likes this.
  27. kai303

    kai303

    Joined:
    Jun 9, 2016
    Posts:
    21
    Thanks for fixing. I also tried to simulate a fade to black with a quad in front of the camera - but the fade was not as smooth (or let's say "linear") as the fade that you can archieve with this Storyboard trick. And I tried all the settings (blend mode, rendering pass after post-process etc...) for the unlit material I had. I don't know what magic you guys are doing under the hood to blend the Storyboard image in, but for me it's the best solution for a fade to black that I found so far ;)
     
  28. AffectusGames

    AffectusGames

    Joined:
    Jan 6, 2020
    Posts:
    4
    Thanks for the fix! Would you mind telling me when is the next release planned? Thanks in advance
     
  29. DavidLieder

    DavidLieder

    Joined:
    Feb 14, 2016
    Posts:
    84
    @Gregoryl There is a bug in Unity Recorder in 2021.3 LTS. The result of the bug is that the storyboard animation track (or storyboards in general) do not post to the rendered content in Unity Recorder. Thus, this solution does not work. I really wish this basic feature of fade to black would have been added already, considering Cinemachine is years out and has always invited professionals to use it. I should not have to post a feature request to see a basic feature added that professionals absolutely need to consider Unity a professional product for any type of film or even rendering video from games.
     
  30. vladala

    vladala

    Unity Technologies

    Joined:
    Mar 3, 2017
    Posts:
    189
    Hey,

    What inout type are you using for the recorder: GameView or Camera, etc ?
    Would you mind telling me if you are using Legacy, URP or HDRP pipelines ?
    The recorder has different code to capture all of those.
     
    Gregoryl likes this.
  31. urrmurrmur

    urrmurrmur

    Joined:
    Sep 2, 2013
    Posts:
    32
    I I have a related question. I'm using a cinemachine VCam with a storyboard to fade to black in all my scenes, which works pretty well. It has one issue though: it seems to behave fairly inconsistently in whether it fades out UI as well. Sometimes it does, sometimes it doesn't.

    Since Gregoryl mentioned above that the storyboard is essentially just a canvas, this makes sense: it simply depends on whether this canvas is rendered above or below the GUI canvas I have in my scene. What I can't figure out though, is if and how I can determine the render order of the storyboard canvas. There doesn't seem to be a setting for it. I assume I'm missing something obvious though, since the system would be fairly useless if you couldn't determine whether to fade over or under your GUI (you'd be better off with a custom panel to achieve the same effect in pretty much every case).
     
    Gregoryl likes this.
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I think you might be right: there is no setting to control this, and there should be. We have logged a task to fix this. Thank you for bringing it up.
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
  34. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    Is this me doing something wrong here ? When adding a transition cam, the actual transform of the storyboard camera is also applied. I guess it's a normal behaviour, but would there be something like ignore camera transform/keep prev camera transform offset (the way it can be done for root animation for instance)

    This would be great as you could transition from cams to other "standardized" effect cams without having to worry about the positionning (Ex : FoV modification, Post processing, Noise, and ofc what is of subject that is the storyboard extension)

    The current usecase is a looping timeline for which I'd like a blackin blackout transition, I'd like to use a single black storyboard cam, but the in/out cam are different so it does not work here.
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes, this:
    upload_2023-3-14_10-51-17.png
     
    Whatever560 likes this.
  36. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513