masks wip

This commit is contained in:
2016-07-28 22:19:48 +07:00
parent e24ad6b4d7
commit 3b9030ec24
4 changed files with 14 additions and 10 deletions

View File

@@ -145,7 +145,7 @@ Camera:
far clip plane: 1000 far clip plane: 1000
field of view: 60 field of view: 60
orthographic: 1 orthographic: 1
orthographic size: 5 orthographic size: 3
m_Depth: -1 m_Depth: -1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2

View File

@@ -72,7 +72,7 @@ namespace FlashTools.Internal {
return AddDisplayListToFrame( return AddDisplayListToFrame(
context, context,
context.DisplayList, context.DisplayList,
false, 0,
0, 0,
null, null,
Matrix4x4.identity, Matrix4x4.identity,
@@ -83,7 +83,7 @@ namespace FlashTools.Internal {
static SwfAnimationFrameData AddDisplayListToFrame( static SwfAnimationFrameData AddDisplayListToFrame(
SwfContext ctx, SwfContext ctx,
SwfDisplayList dl, SwfDisplayList dl,
bool parent_masked, ushort parent_masked,
ushort parent_mask, ushort parent_mask,
List<SwfAnimationInstanceData> parent_masks, List<SwfAnimationInstanceData> parent_masks,
Matrix4x4 parent_matrix, Matrix4x4 parent_matrix,
@@ -123,8 +123,8 @@ namespace FlashTools.Internal {
var bitmap_def = ctx.Library.FindDefine<SwfLibraryBitmapDefine>(bitmap_id); var bitmap_def = ctx.Library.FindDefine<SwfLibraryBitmapDefine>(bitmap_id);
if ( bitmap_def != null ) { if ( bitmap_def != null ) {
frame.Instances.Add(new SwfAnimationInstanceData{ frame.Instances.Add(new SwfAnimationInstanceData{
Type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfAnimationInstanceType.Mask : (parent_masked || masks.Count > 0 ? SwfAnimationInstanceType.Masked : SwfAnimationInstanceType.Group), 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 : (ushort)0)), ClipDepth = (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (parent_masked + masks.Count))),
Bitmap = bitmap_id, Bitmap = bitmap_id,
Matrix = parent_matrix * inst.Matrix.ToUnityMatrix() * bitmap_matrix.ToUnityMatrix(), Matrix = parent_matrix * inst.Matrix.ToUnityMatrix() * bitmap_matrix.ToUnityMatrix(),
ColorTransform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform()}); ColorTransform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform()});
@@ -149,7 +149,7 @@ namespace FlashTools.Internal {
AddDisplayListToFrame( AddDisplayListToFrame(
ctx, ctx,
sprite_inst.DisplayList, 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)), (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (ushort)0)),
parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? masks : null), parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? masks : null),
parent_matrix * sprite_inst.Matrix.ToUnityMatrix(), parent_matrix * sprite_inst.Matrix.ToUnityMatrix(),

View File

@@ -30,6 +30,7 @@ namespace FlashTools {
class Group { class Group {
public SwfAnimationInstanceType Type; public SwfAnimationInstanceType Type;
public int ClipDepth;
public List<int> Triangles; public List<int> Triangles;
public Material Material; public Material Material;
} }
@@ -140,9 +141,10 @@ namespace FlashTools {
_addcolors.Add(inst.ColorTransform.Add); _addcolors.Add(inst.ColorTransform.Add);
_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(); var gr = new Group();
gr.Type = inst.Type; gr.Type = inst.Type;
gr.ClipDepth = inst.ClipDepth;
gr.Triangles = new List<int>(); gr.Triangles = new List<int>();
_groups.Add(gr); _groups.Add(gr);
} }
@@ -238,6 +240,7 @@ namespace FlashTools {
case SwfAnimationInstanceType.Masked: case SwfAnimationInstanceType.Masked:
gr.Material = new Material(Shader.Find("FlashTools/FlashMasked")); gr.Material = new Material(Shader.Find("FlashTools/FlashMasked"));
gr.Material.SetTexture("_MainTex", Asset.Atlas); gr.Material.SetTexture("_MainTex", Asset.Atlas);
gr.Material.SetInt("_StencilID", gr.ClipDepth);
break; break;
case SwfAnimationInstanceType.MaskReset: case SwfAnimationInstanceType.MaskReset:
gr.Material = new Material(Shader.Find("FlashTools/FlashMaskReset")); gr.Material = new Material(Shader.Find("FlashTools/FlashMaskReset"));

View File

@@ -1,6 +1,7 @@
Shader "FlashTools/FlashMasked" { Shader "FlashTools/FlashMasked" {
Properties { Properties {
[PerRendererData] _MainTex ("Main Texture", 2D) = "white" {} [PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
[PerRendererData] _StencilID ("Stencil ID" , Int) = 0
} }
SubShader { SubShader {
@@ -19,8 +20,8 @@ Shader "FlashTools/FlashMasked" {
Pass { Pass {
Stencil { Stencil {
Ref 0 Ref [_StencilID]
Comp Less Comp Equal
} }
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert