- Home /
Does Flash Export support "Depth Only" camera clear?
We have a multi-layered Unity scene that uses several different cameras -- a 2D background GUI layer, a 3D viewport containing a model, and then a viewport overlay containing labels with 3D lines pointing into the 3D model.
The background layer uses a camera that does a solid colour clear, then the viewport cameras each use CameraClearFlags.Depth, to clear and reuse the depth buffer.
This works great in the Editor, but when we export to Flash it seems that camera depth clear is not supported -- it appears to do a solid colour clear. The result is that when we turn on the labels, the 3D model disappears and is covered up by the background colour of the label camera.
I can think of some possible workarounds, but first of all, should CameraClearFlags.Depth work in Flash?
EDIT: I created a simple test case for this and it does not show the problem. Continuing to investigate, will update this question if I learn anything new.
Answer by yoyo · Jul 31, 2012 at 03:31 AM
After some investigation with a simple test scene, it seems CameraClearFlags.Depth does work in Flash -- but only if the viewport of the camera fills the entire screen. If the viewport fills a portion of the screen then setting depth-only clear will clear the camera to the background colour (wiping out everything rendered to that region by previously rendered cameras).
This is in Unity 3.5.2. I haven't tested other versions. I filed a bug report.
EDIT: Until this bug is fixed, here's a workaround ...
Add the following shader to your project. It will set the depth buffer without touching the colour of any pixels. Create a material using this shader and attach it to a plane behind all the geometry viewed by your overlay camera. This plane will be drawn first, filling the depth buffer and allowing the contents of the overlay camera to be drawn with a "fresh" depth buffer.
Shader "Custom/DepthClear"
{
SubShader
{
Tags {"Queue"="Background-1"}
Pass
{
ZWrite On
ZTest Always
AlphaTest Off
Cull Off
Blend Zero One
ColorMask 0
}
}
FallBack "Diffuse"
}
@yoyo: thanks for your feedback. If you can remember the bugreport id, you could post it here just for reference ;)
I took the liberty and mark your answer ;)
(it's funny, when you mark your own answer you don't get karma, but when i mark yours you get karma ;) )
Heh, thanks. I just found a workaround, which I've added to the answer.
Answer by Bunny83 · Jul 27, 2012 at 10:29 PM
I don't see a good reason why it shouldn't work. Are you sure you have the correct camera-depth (order) setup?
If it really doesn't work, i would call it a bug.
The depth stacking order seems correct in the inspector and works properly in the editor. Only in the Flash build is there a problem. Guess I should file a bug?
Your answer
![](https://koobas.hobune.stream/wayback/20220613074814im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Culling Mask with Depth Occlusion 1 Answer
Camera --> get Depth as Texture (Best Gray) 2 Answers
How to make a FLASH 4 Answers