x


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.

more ▼

asked Jul 27 '12 at 09:55 PM

yoyo gravatar image

yoyo
6.4k 25 39 84

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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"
}
more ▼

answered Jul 31 '12 at 03:31 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

@yoyo: thanks for your feedback. If you can remember the bugreport id, you could post it here just for reference ;)

Jul 31 '12 at 12:06 PM Bunny83

link added

Jul 31 '12 at 04:14 PM yoyo

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 ;) )

Jul 31 '12 at 09:51 PM Bunny83

Heh, thanks. I just found a workaround, which I've added to the answer.

Jul 31 '12 at 09:56 PM yoyo
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 27 '12 at 10:29 PM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

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?

Jul 27 '12 at 10:51 PM yoyo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2994
x269
x72

asked: Jul 27 '12 at 09:55 PM

Seen: 553 times

Last Updated: Jul 31 '12 at 10:33 PM