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

Depth Only Clear Flag Camera Issue

Discussion in 'Editor & General Support' started by dnl_decarlo, Jan 16, 2017.

  1. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    Hi everybody,
    I am trying to play the turnaround of my character without viewing the skybox in the player. I found different threads about this issue so I put two camera with different depth, and different clear flag (depth only and skybox). When I play the animation my character leaves a trail and the exported movie (with AVPro Movie Capture) doesn´t get any alpha data.

    I have tried everything I found in the past threads, but the trail is still there. I have tried to put even a third camera to solid color with black alpha, but it didn´t work. The movie is exported with a black background without any alpha information. In unity 4 it worked perfectly, so there is anyone that could help me to understand how can I set the clear flag to depth only without the trail issue?

    Thanks everybody, that´s my first threads, hope to pst it in the right place.
    Cheers,
    Daniele
     
  2. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    523
    I have had lots of problems trying to composite multiple cameras using depth only clearing when using the deferred rendering pipeline - it just doesn't seem to work as expected. Forward rendering seems to work much better. I've filed bug reports with repro projects but have never heard anything back.

    So, perhaps try using forward rendering if you can and aren't already using it.
     
  3. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    Thank you so much for your reply Greg, but unfortunally even with a forward rendering path it doesn´t work. I don ´t know why it doesn´get any alpha information, even with a simple cube. Thank you again for your support.
     
  4. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    523
    If you can't work around it with camera setup alone, you might want to try setting up some RenderTextures and doing some custom material blitting using Graphics.Blit. Some combination of clearing the camera, rendering your scene to a rendertexture, and custom blitting the output might work to preserve the alpha channel you need.
     
  5. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    Thank you again Grag. I am not so good with scripting and actually I do not know where to find the mainCamera scipt to modify. I have tried with a simple render texture but it will render texture at 256x256, if I change the siye of the render texture at 2048x2048 as actually my texture are, the render texture advise me that the resolution is to high. I do not want loose resolution on my texture.
    Do you know if there is any chance to use the graphic blit without a render texture? just applying it to the main camera?
    Thank you again for your support
     
  6. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    523
  7. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    I have started studying how to write a post effect image and a proper shader. Thank you for the support :)
     
  8. roberto-ardila

    roberto-ardila

    Unity Technologies

    Joined:
    Apr 8, 2013
    Posts:
    5
    Hello,

    I did a test using Unity 5.5.1f1, to try to recreate the overpaint behaviour you see, for that I created a scene with a rotating cube and the following 2 cameras:
    • Main Camera:
      • ClearFlags: Depth Only
      • Depth: 1
    • Back Camera:
      • ClearFlags: Solid Color
      • Background: R:0,G:0,B:0,A:0
      • Depth: 0
    With those settings I didn't see the trail generated by the overpaint, I attach the project so you can check if that could help in your case.

    Regards,
    Roberto
     

    Attached Files:

  9. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    Hello Roberto,
    Thank you so much for your reply.

    It is true, the trail doesn´t exist anymore, but when I capture the video it has a black background, I need a transparent background (for composition purpose). If i change the display target of the camera, as i need to capture only the animation of the cube and not the background, tha trail appears again.
    How can I have a camera with transparent background without any trail on the 3D obj animation?

    Thank you so much for your support.
    Daniele
     
  10. roberto-ardila

    roberto-ardila

    Unity Technologies

    Joined:
    Apr 8, 2013
    Posts:
    5
    Hello,

    In your case, do you plan to use the movie you want to capture in your game? (if that's the case it could be possible to use a chroma shader in your video material to remove the background) or do you plan to use the video in an external video editor like Adobe Premiere or After Effects?

    Regards,
    Roberto
     
  11. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    Hi roberto sorry for the delay, but I spent a lot of time in hospital.

    Sorry but it is not professional removing a background while I could export the alpha data of the animation
     
  12. dnl_decarlo

    dnl_decarlo

    Joined:
    Oct 24, 2016
    Posts:
    18
    I do not understand how to export a simple animation without background. With Avmovie pro always worked.
     
  13. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    523
    This doesn't immediately solve your 'export fullscreen with alpha' problem (screenshot or video) but it does cover obtaining images with alpha channels. Check these links for a technique to extract an alpha channel after rendering two passes over a black and white background;

    http://wiki.unity3d.com/index.php/AnimationToPNG
    https://forum.unity3d.com/threads/render-particles-to-animated-texture.45193/

    We use the same technique, along with a render to texture camera stack to composite multiple cameras, to output huge images (up to 16k) with alpha channels.

    We do this for a screenshot though, not a video. You could save this png or perhaps a raw bitmap every frame to make an image sequence, or pipe the frame to an external ffmpeg process to render a video. I built an ffmpeg wrapper to test this ages ago and it does work once you get the correct ffmpeg parameters and image data formats sorted out. I'd share the code but the mighty @Keijiro-UTJ has a github library you can try that does almost exactly the same thing we did: https://github.com/keijiro/FFmpegOut