Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

fading out a camera

Discussion in 'Getting Started' started by boolfone, Jun 23, 2016.

  1. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    Anyone know if it is possible to fade out a camera?

    I have a camera on top of the others, and I have it shooting off fireworks when someone gets a right answer. I want to slowly fade off the fireworks camera so the fireworks disappear gradually.

    Screen Shot 2016-06-23 at 5.31.36 PM.png


    It’s sort of like I want the camera to have an opacity property from 0 to 1. But I don’t see such a property.

    Thanks.
     
  2. macorig

    macorig

    Joined:
    Dec 27, 2010
    Posts:
    52
    Hi!
    I haven't done anything like that before, but render textures may work for you:
    • Make sure the camera's clear flags are "Depth Only", but I guess that's already the case!
    • Create a Render Texture and make your fireworks camera render out to it by using it for the camera's Target Texture property.
    • In your UI, create a Raw Image element using your Render Texture and make it fit the entire screen.
    • Deactivate the property "Raycast Target" for the Raw Image, so it does not block any click events, etc.
    • After that you can manipulate its transparency through the Raw Image's color property, changing the alpha
    I hope this helps!
     
  3. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    I did the Raw Image and the Render to Texture.

    However, there seems to be an issue:



    It’s like the image isn’t really blending right.

    Any ideas how to fix this?
     
  4. macorig

    macorig

    Joined:
    Dec 27, 2010
    Posts:
    52
    Ah yeah, I think I understand what's going wrong there... this feels like a job for a custom shader, but my experience with those is very limited.

    So, here is something you can try, but I feel like there has to be a more elegant solution:
    • Create a new Material
    • Apply it to the Raw Image
    • Import the attached shader and set your material to use it
    The shader I actually just copy pasted from Unity's builtin, default UI shader, except I changed the blending to additive.
    Also, you may want to set your firework camera's Clear Flags to "Solid Color" and just set the Background to black at full opacity.

    Hope this is working for you, but if there are any other ideas on this, I too would love to hear them!
     

    Attached Files:

  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    I wouldn't use a render texture (or extra camera) for this, but would instead just fade out the fireworks themselves — using a custom particle shader if necessary. So you adjust the alpha in the shader to make the fireworks disappear.
     
    HuldaGnodima, Ryiah and macorig like this.
  6. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289

    I am trying to carry out your approach.

    I imported the custom shader in Unity.

    However, I’m not sure how to add the shader to the new material?

    Do you know how?

    Thanks.

    Screen Shot 2016-06-25 at 10.59.38 AM.png
     
  7. macorig

    macorig

    Joined:
    Dec 27, 2010
    Posts:
    52
    Oh? It should just show up there under UI > Additive... maybe I've missed something, I'll double-check. Have you tried reimporting it or restarting Unity?

    If this doesn't work out for you, you should try looking into @JoeStrout's idea – it sounds less complicated and better for performance.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Most of the time you don't need a custom shader, not unless you have other weird effects going on. A standard transparent material will do. Just lerp the alpha down to zero.
     
    JoeStrout and Ryiah like this.
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    That's true; the only reason I think a custom shader might be useful in this case is that in a particle system, the color (including alpha) of each particle is usually controlled separately by the particle engine, according to the lifetime of each separate particle. So I don't know that you have any easy way to multiply that by a global alpha value, so as to fade out the whole system.

    But I haven't actually looked into it; I'm only guessing.