mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-15 04:25:27 +07:00
+ color mode for instances
This commit is contained in:
@@ -4,9 +4,10 @@ Shader "FlashTools/SwfMaskedGrab" {
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
|
||||
_StencilID ("Stencil ID", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("DstBlend", Int) = 10
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _SrcBlend ("SrcBlend" , Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _DstBlend ("DstBlend" , Int) = 10
|
||||
[Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorMask("ColorMask", Int) = 15
|
||||
}
|
||||
|
||||
SubShader {
|
||||
@@ -18,9 +19,10 @@ Shader "FlashTools/SwfMaskedGrab" {
|
||||
"CanUseSpriteAtlas" = "True"
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
BlendOp [_BlendOp]
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
|
||||
@@ -4,9 +4,10 @@ Shader "FlashTools/SwfMasked" {
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
|
||||
_StencilID ("Stencil ID", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("DstBlend", Int) = 10
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _SrcBlend ("SrcBlend" , Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _DstBlend ("DstBlend" , Int) = 10
|
||||
[Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorMask("ColorMask", Int) = 15
|
||||
}
|
||||
|
||||
SubShader {
|
||||
@@ -18,9 +19,10 @@ Shader "FlashTools/SwfMasked" {
|
||||
"CanUseSpriteAtlas" = "True"
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
BlendOp [_BlendOp]
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
|
||||
@@ -3,9 +3,10 @@ Shader "FlashTools/SwfSimpleGrab" {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("DstBlend", Int) = 10
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _SrcBlend ("SrcBlend" , Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _DstBlend ("DstBlend" , Int) = 10
|
||||
[Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorMask("ColorMask", Int) = 15
|
||||
}
|
||||
|
||||
SubShader {
|
||||
@@ -17,9 +18,10 @@ Shader "FlashTools/SwfSimpleGrab" {
|
||||
"CanUseSpriteAtlas" = "True"
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
BlendOp [_BlendOp]
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
|
||||
@@ -3,9 +3,10 @@ Shader "FlashTools/SwfSimple" {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("DstBlend", Int) = 10
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _SrcBlend ("SrcBlend" , Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode )] _DstBlend ("DstBlend" , Int) = 10
|
||||
[Enum(UnityEngine.Rendering.ColorWriteMask)] _ColorMask("ColorMask", Int) = 15
|
||||
}
|
||||
|
||||
SubShader {
|
||||
@@ -17,9 +18,10 @@ Shader "FlashTools/SwfSimple" {
|
||||
"CanUseSpriteAtlas" = "True"
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
BlendOp [_BlendOp]
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
|
||||
@@ -314,6 +314,7 @@ namespace FlashTools.Internal {
|
||||
|
||||
class BakedGroup {
|
||||
public SwfInstanceData.Types Type;
|
||||
public SwfColorModeData.Types ColorMode;
|
||||
public SwfBlendModeData.Types BlendMode;
|
||||
public int ClipDepth;
|
||||
public int StartVertex;
|
||||
@@ -375,11 +376,13 @@ namespace FlashTools.Internal {
|
||||
|
||||
if ( baked_groups.Count == 0 ||
|
||||
baked_groups[baked_groups.Count - 1].Type != inst.Type ||
|
||||
baked_groups[baked_groups.Count - 1].ColorMode != inst.ColorMode.type ||
|
||||
baked_groups[baked_groups.Count - 1].BlendMode != inst.BlendMode.type ||
|
||||
baked_groups[baked_groups.Count - 1].ClipDepth != inst.ClipDepth )
|
||||
{
|
||||
baked_groups.Add(new BakedGroup{
|
||||
Type = inst.Type,
|
||||
ColorMode = inst.ColorMode.type,
|
||||
BlendMode = inst.BlendMode.type,
|
||||
ClipDepth = inst.ClipDepth,
|
||||
StartVertex = baked_vertices.Count - 4,
|
||||
@@ -400,10 +403,10 @@ namespace FlashTools.Internal {
|
||||
group.Material = settings_holder.GetIncrMaskMaterial();
|
||||
break;
|
||||
case SwfInstanceData.Types.Group:
|
||||
group.Material = settings_holder.GetSimpleMaterial(group.BlendMode);
|
||||
group.Material = settings_holder.GetSimpleMaterial(group.ColorMode, group.BlendMode);
|
||||
break;
|
||||
case SwfInstanceData.Types.Masked:
|
||||
group.Material = settings_holder.GetMaskedMaterial(group.BlendMode, group.ClipDepth);
|
||||
group.Material = settings_holder.GetMaskedMaterial(group.ColorMode, group.BlendMode, group.ClipDepth);
|
||||
break;
|
||||
case SwfInstanceData.Types.MaskReset:
|
||||
group.Material = settings_holder.GetDecrMaskMaterial();
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace FlashTools.Internal {
|
||||
library,
|
||||
display_list,
|
||||
Matrix4x4.identity,
|
||||
SwfColorModeData.identity,
|
||||
SwfBlendModeData.identity,
|
||||
SwfColorTransData.identity,
|
||||
0,
|
||||
@@ -109,6 +110,7 @@ namespace FlashTools.Internal {
|
||||
SwfLibrary library,
|
||||
SwfDisplayList display_list,
|
||||
Matrix4x4 parent_matrix,
|
||||
SwfColorModeData parent_color_mode,
|
||||
SwfBlendModeData parent_blend_mode,
|
||||
SwfColorTransData parent_color_transform,
|
||||
ushort parent_masked,
|
||||
@@ -120,6 +122,7 @@ namespace FlashTools.Internal {
|
||||
foreach ( var inst in display_list.Instances.Values.Where(p => p.Visible) ) {
|
||||
CheckSelfMasks(self_masks, inst.Depth, frame);
|
||||
var child_matrix = parent_matrix * inst.Matrix .ToUMatrix();
|
||||
var child_color_mode = parent_color_mode;
|
||||
var child_blend_mode = parent_blend_mode * inst.BlendMode .ToBlendModeData();
|
||||
var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData();
|
||||
switch ( inst.Type ) {
|
||||
@@ -128,6 +131,7 @@ namespace FlashTools.Internal {
|
||||
library,
|
||||
inst as SwfDisplayShapeInstance,
|
||||
child_matrix,
|
||||
child_color_mode,
|
||||
child_blend_mode,
|
||||
child_color_transform,
|
||||
parent_masked,
|
||||
@@ -141,6 +145,7 @@ namespace FlashTools.Internal {
|
||||
library,
|
||||
inst as SwfDisplaySpriteInstance,
|
||||
child_matrix,
|
||||
child_color_mode,
|
||||
child_blend_mode,
|
||||
child_color_transform,
|
||||
parent_masked,
|
||||
@@ -162,6 +167,7 @@ namespace FlashTools.Internal {
|
||||
SwfLibrary library,
|
||||
SwfDisplayShapeInstance inst,
|
||||
Matrix4x4 inst_matrix,
|
||||
SwfColorModeData inst_color_mode,
|
||||
SwfBlendModeData inst_blend_mode,
|
||||
SwfColorTransData inst_color_transform,
|
||||
ushort parent_masked,
|
||||
@@ -194,6 +200,7 @@ namespace FlashTools.Internal {
|
||||
ClipDepth = (ushort)frame_inst_clip_depth,
|
||||
Bitmap = bitmap_id,
|
||||
Matrix = SwfMatrixData.FromUMatrix(inst_matrix * bitmap_matrix.ToUMatrix()),
|
||||
ColorMode = inst_color_mode,
|
||||
BlendMode = inst_blend_mode,
|
||||
ColorTrans = inst_color_transform});
|
||||
if ( parent_mask > 0 ) {
|
||||
@@ -210,6 +217,7 @@ namespace FlashTools.Internal {
|
||||
SwfLibrary library,
|
||||
SwfDisplaySpriteInstance inst,
|
||||
Matrix4x4 inst_matrix,
|
||||
SwfColorModeData inst_color_mode,
|
||||
SwfBlendModeData inst_blend_mode,
|
||||
SwfColorTransData inst_color_transform,
|
||||
ushort parent_masked,
|
||||
@@ -224,6 +232,7 @@ namespace FlashTools.Internal {
|
||||
library,
|
||||
inst.DisplayList,
|
||||
inst_matrix,
|
||||
inst_color_mode,
|
||||
inst_blend_mode,
|
||||
inst_color_transform,
|
||||
(ushort)(parent_masked + self_masks.Count),
|
||||
@@ -253,6 +262,7 @@ namespace FlashTools.Internal {
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorMode = mask.ColorMode,
|
||||
BlendMode = mask.BlendMode,
|
||||
ColorTrans = mask.ColorTrans});
|
||||
}
|
||||
|
||||
@@ -99,11 +99,14 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
void PregenerateMaterials() {
|
||||
var color_modes = System.Enum.GetValues(typeof(SwfColorModeData.Types));
|
||||
var blend_modes = System.Enum.GetValues(typeof(SwfBlendModeData.Types));
|
||||
foreach ( SwfBlendModeData.Types blend_mode in blend_modes ) {
|
||||
GetSimpleMaterial(blend_mode);
|
||||
for ( var i = 0; i < 10; ++i ) {
|
||||
GetMaskedMaterial(blend_mode, i);
|
||||
foreach ( SwfColorModeData.Types color_mode in color_modes ) {
|
||||
foreach ( SwfBlendModeData.Types blend_mode in blend_modes ) {
|
||||
GetSimpleMaterial(color_mode, blend_mode);
|
||||
for ( var i = 0; i < 10; ++i ) {
|
||||
GetMaskedMaterial(color_mode, blend_mode, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
GetIncrMaskMaterial();
|
||||
@@ -156,8 +159,8 @@ namespace FlashTools.Internal {
|
||||
return material;
|
||||
}
|
||||
|
||||
Shader SelectShader(bool masked, SwfBlendModeData.Types blend_type) {
|
||||
switch ( blend_type ) {
|
||||
Shader SelectShader(bool masked, SwfBlendModeData.Types blend_mode) {
|
||||
switch ( blend_mode ) {
|
||||
case SwfBlendModeData.Types.Normal:
|
||||
case SwfBlendModeData.Types.Layer:
|
||||
case SwfBlendModeData.Types.Multiply:
|
||||
@@ -174,8 +177,8 @@ namespace FlashTools.Internal {
|
||||
return CheckAndGetShader(masked ? MaskedGrabShader : SimpleGrabShader);
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"SwfSettings. Incorrect blend type: {0}",
|
||||
blend_type));
|
||||
"SwfSettings. Incorrect blend mode: {0}",
|
||||
blend_mode));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,8 +197,23 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static Material FillMaterial(
|
||||
Material material, SwfBlendModeData.Types blend_mode, int stencil_id)
|
||||
Material material,
|
||||
SwfColorModeData.Types color_mode,
|
||||
SwfBlendModeData.Types blend_mode,
|
||||
int stencil_id)
|
||||
{
|
||||
switch ( color_mode ) {
|
||||
case SwfColorModeData.Types.RGBA:
|
||||
material.SetInt("_ColorMask", (int)ColorWriteMask.All);
|
||||
break;
|
||||
case SwfColorModeData.Types.A:
|
||||
material.SetInt("_ColorMask", (int)ColorWriteMask.Alpha);
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"SwfSettings. Incorrect color mode: {0}",
|
||||
color_mode));
|
||||
}
|
||||
switch ( blend_mode ) {
|
||||
case SwfBlendModeData.Types.Normal:
|
||||
material.SetInt("_BlendOp" , (int)BlendOp.Add);
|
||||
@@ -277,26 +295,33 @@ namespace FlashTools.Internal {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public Material GetSimpleMaterial(SwfBlendModeData.Types blend_mode) {
|
||||
public Material GetSimpleMaterial(
|
||||
SwfColorModeData.Types color_mode,
|
||||
SwfBlendModeData.Types blend_mode)
|
||||
{
|
||||
return LoadOrCreateMaterial(
|
||||
CheckAndGetShader(SelectShader(false, blend_mode)),
|
||||
(dir_path, filename) => {
|
||||
return string.Format(
|
||||
"{0}/{1}_{2}.mat",
|
||||
dir_path, filename, blend_mode);
|
||||
"{0}/{1}_{2}_{3}.mat",
|
||||
dir_path, filename, color_mode, blend_mode);
|
||||
},
|
||||
material => FillMaterial(material, blend_mode, 0));
|
||||
material => FillMaterial(material, color_mode, blend_mode, 0));
|
||||
}
|
||||
|
||||
public Material GetMaskedMaterial(SwfBlendModeData.Types blend_mode, int stencil_id) {
|
||||
public Material GetMaskedMaterial(
|
||||
SwfColorModeData.Types color_mode,
|
||||
SwfBlendModeData.Types blend_mode,
|
||||
int stencil_id)
|
||||
{
|
||||
return LoadOrCreateMaterial(
|
||||
CheckAndGetShader(SelectShader(true, blend_mode)),
|
||||
(dir_path, filename) => {
|
||||
return string.Format(
|
||||
"{0}/{1}_{2}_{3}.mat",
|
||||
dir_path, filename, blend_mode, stencil_id);
|
||||
"{0}/{1}_{2}_{3}_{4}.mat",
|
||||
dir_path, filename, color_mode, blend_mode, stencil_id);
|
||||
},
|
||||
material => FillMaterial(material, blend_mode, stencil_id));
|
||||
material => FillMaterial(material, color_mode, blend_mode, stencil_id));
|
||||
}
|
||||
|
||||
public Material GetIncrMaskMaterial() {
|
||||
|
||||
@@ -105,6 +105,26 @@ namespace FlashTools {
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct SwfColorModeData {
|
||||
public enum Types : byte {
|
||||
RGBA,
|
||||
A
|
||||
}
|
||||
public Types type;
|
||||
|
||||
public SwfColorModeData(Types type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static SwfColorModeData identity {
|
||||
get {
|
||||
return new SwfColorModeData{
|
||||
type = Types.RGBA};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct SwfBlendModeData {
|
||||
public enum Types : byte {
|
||||
@@ -191,6 +211,7 @@ namespace FlashTools {
|
||||
public ushort ClipDepth = 0;
|
||||
public ushort Bitmap = 0;
|
||||
public SwfMatrixData Matrix = SwfMatrixData.identity;
|
||||
public SwfColorModeData ColorMode = SwfColorModeData.identity;
|
||||
public SwfBlendModeData BlendMode = SwfBlendModeData.identity;
|
||||
public SwfColorTransData ColorTrans = SwfColorTransData.identity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user