diff --git a/Assets/FlashTools/Examples/Scenes/Scene00.unity b/Assets/FlashTools/Examples/Scenes/Scene00.unity index 674532f..30b4517 100644 --- a/Assets/FlashTools/Examples/Scenes/Scene00.unity +++ b/Assets/FlashTools/Examples/Scenes/Scene00.unity @@ -145,7 +145,7 @@ Camera: far clip plane: 1000 field of view: 60 orthographic: 1 - orthographic size: 5 + orthographic size: 3 m_Depth: -1 m_CullingMask: serializedVersion: 2 diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs index 80b7535..22d88ad 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs @@ -72,7 +72,7 @@ namespace FlashTools.Internal { return AddDisplayListToFrame( context, context.DisplayList, - false, + 0, 0, null, Matrix4x4.identity, @@ -83,7 +83,7 @@ namespace FlashTools.Internal { static SwfAnimationFrameData AddDisplayListToFrame( SwfContext ctx, SwfDisplayList dl, - bool parent_masked, + ushort parent_masked, ushort parent_mask, List parent_masks, Matrix4x4 parent_matrix, @@ -123,8 +123,8 @@ namespace FlashTools.Internal { var bitmap_def = ctx.Library.FindDefine(bitmap_id); if ( bitmap_def != null ) { frame.Instances.Add(new SwfAnimationInstanceData{ - Type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfAnimationInstanceType.Mask : (parent_masked || masks.Count > 0 ? SwfAnimationInstanceType.Masked : SwfAnimationInstanceType.Group), - ClipDepth = (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (ushort)0)), + Type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfAnimationInstanceType.Mask : (parent_masked > 0 || masks.Count > 0 ? SwfAnimationInstanceType.Masked : SwfAnimationInstanceType.Group), + ClipDepth = (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (parent_masked + masks.Count))), Bitmap = bitmap_id, Matrix = parent_matrix * inst.Matrix.ToUnityMatrix() * bitmap_matrix.ToUnityMatrix(), ColorTransform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform()}); @@ -149,7 +149,7 @@ namespace FlashTools.Internal { AddDisplayListToFrame( ctx, sprite_inst.DisplayList, - parent_masked ? parent_masked : (masks.Count > 0), + (ushort)(parent_masked + masks.Count), (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (ushort)0)), parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? masks : null), parent_matrix * sprite_inst.Matrix.ToUnityMatrix(), diff --git a/Assets/FlashTools/Scripts/SwfAnimation.cs b/Assets/FlashTools/Scripts/SwfAnimation.cs index ec69f25..a5012b0 100644 --- a/Assets/FlashTools/Scripts/SwfAnimation.cs +++ b/Assets/FlashTools/Scripts/SwfAnimation.cs @@ -30,6 +30,7 @@ namespace FlashTools { class Group { public SwfAnimationInstanceType Type; + public int ClipDepth; public List Triangles; public Material Material; } @@ -140,9 +141,10 @@ namespace FlashTools { _addcolors.Add(inst.ColorTransform.Add); _addcolors.Add(inst.ColorTransform.Add); - if ( _groups.Count == 0 || _groups[_groups.Count - 1].Type != inst.Type) { + if ( _groups.Count == 0 || _groups[_groups.Count - 1].Type != inst.Type || _groups[_groups.Count - 1].ClipDepth != inst.ClipDepth) { var gr = new Group(); gr.Type = inst.Type; + gr.ClipDepth = inst.ClipDepth; gr.Triangles = new List(); _groups.Add(gr); } @@ -238,6 +240,7 @@ namespace FlashTools { case SwfAnimationInstanceType.Masked: gr.Material = new Material(Shader.Find("FlashTools/FlashMasked")); gr.Material.SetTexture("_MainTex", Asset.Atlas); + gr.Material.SetInt("_StencilID", gr.ClipDepth); break; case SwfAnimationInstanceType.MaskReset: gr.Material = new Material(Shader.Find("FlashTools/FlashMaskReset")); diff --git a/Assets/FlashTools/Shaders/FlashMasked.shader b/Assets/FlashTools/Shaders/FlashMasked.shader index bf1bfcb..77deec2 100644 --- a/Assets/FlashTools/Shaders/FlashMasked.shader +++ b/Assets/FlashTools/Shaders/FlashMasked.shader @@ -1,6 +1,7 @@ Shader "FlashTools/FlashMasked" { Properties { - [PerRendererData] _MainTex ("Main Texture", 2D) = "white" {} + [PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {} + [PerRendererData] _StencilID ("Stencil ID" , Int) = 0 } SubShader { @@ -19,8 +20,8 @@ Shader "FlashTools/FlashMasked" { Pass { Stencil { - Ref 0 - Comp Less + Ref [_StencilID] + Comp Equal } CGPROGRAM #pragma vertex vert