ETC1 support

This commit is contained in:
2017-02-12 10:24:32 +07:00
parent 04ddf0d08e
commit 99d4236e13
14 changed files with 94 additions and 26 deletions

View File

@@ -1,3 +1,9 @@
-------------------
-- Version 1.X.X --
-------------------
ETC separated alpha support
------------------- -------------------
-- Version 1.2.0 -- -- Version 1.2.0 --
------------------- -------------------

View File

@@ -135,6 +135,9 @@ inline swf_mask_v2f_t swf_mask_vert(swf_mask_appdata_t IN) {
inline fixed4 swf_frag(swf_v2f_t IN) : SV_Target { inline fixed4 swf_frag(swf_v2f_t IN) : SV_Target {
fixed4 c = tex2D(_MainTex, IN.uv); fixed4 c = tex2D(_MainTex, IN.uv);
if ( _ExternalAlpha ) {
c.a *= tex2D(_AlphaTex, IN.uv).r;
}
if ( c.a > 0.01 ) { if ( c.a > 0.01 ) {
c = c * IN.mulcolor + IN.addcolor; c = c * IN.mulcolor + IN.addcolor;
} }
@@ -144,6 +147,9 @@ inline fixed4 swf_frag(swf_v2f_t IN) : SV_Target {
inline fixed4 swf_grab_frag(swf_grab_v2f_t IN) : SV_Target { inline fixed4 swf_grab_frag(swf_grab_v2f_t IN) : SV_Target {
fixed4 c = tex2D(_MainTex, IN.uv); fixed4 c = tex2D(_MainTex, IN.uv);
if ( _ExternalAlpha ) {
c.a *= tex2D(_AlphaTex, IN.uv).r;
}
if ( c.a > 0.01 ) { if ( c.a > 0.01 ) {
c = c * IN.mulcolor + IN.addcolor; c = c * IN.mulcolor + IN.addcolor;
c = grab_blend(_GrabTexture, IN.screenpos, c); c = grab_blend(_GrabTexture, IN.screenpos, c);
@@ -154,6 +160,9 @@ inline fixed4 swf_grab_frag(swf_grab_v2f_t IN) : SV_Target {
inline fixed4 swf_mask_frag(swf_mask_v2f_t IN) : SV_Target { inline fixed4 swf_mask_frag(swf_mask_v2f_t IN) : SV_Target {
fixed4 c = tex2D(_MainTex, IN.uv); fixed4 c = tex2D(_MainTex, IN.uv);
if ( _ExternalAlpha ) {
c.a *= tex2D(_AlphaTex, IN.uv).r;
}
if ( c.a < 0.01 ) { if ( c.a < 0.01 ) {
discard; discard;
} }

View File

@@ -1,6 +1,8 @@
Shader "FlashTools/SwfDecrMask" { Shader "FlashTools/SwfDecrMask" {
Properties { Properties {
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D) = "white" {}
[PerRendererData] _AlphaTex ("Alpha Texture" , 2D) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
} }
SubShader { SubShader {
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfDecrMask" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#include "UnityCG.cginc" #include "UnityCG.cginc"
#include "SwfBaseCG.cginc" #include "SwfBaseCG.cginc"

View File

@@ -1,6 +1,8 @@
Shader "FlashTools/SwfIncrMask" { Shader "FlashTools/SwfIncrMask" {
Properties { Properties {
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D) = "white" {}
[PerRendererData] _AlphaTex ("Alpha Texture" , 2D) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
} }
SubShader { SubShader {
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfIncrMask" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#include "UnityCG.cginc" #include "UnityCG.cginc"
#include "SwfBaseCG.cginc" #include "SwfBaseCG.cginc"

View File

@@ -1,7 +1,9 @@
Shader "FlashTools/SwfMaskedGrab" { Shader "FlashTools/SwfMaskedGrab" {
Properties { Properties {
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1) [PerRendererData] _AlphaTex ("Alpha Texture" , 2D ) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
_StencilID ("Stencil ID", Int) = 0 _StencilID ("Stencil ID", Int) = 0
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0 [Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
@@ -35,7 +37,9 @@ Shader "FlashTools/SwfMaskedGrab" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND #pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND

View File

@@ -1,7 +1,9 @@
Shader "FlashTools/SwfMasked" { Shader "FlashTools/SwfMasked" {
Properties { Properties {
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1) [PerRendererData] _AlphaTex ("Alpha Texture" , 2D ) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
_StencilID ("Stencil ID", Int) = 0 _StencilID ("Stencil ID", Int) = 0
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0 [Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
@@ -33,7 +35,9 @@ Shader "FlashTools/SwfMasked" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#include "UnityCG.cginc" #include "UnityCG.cginc"
#include "SwfBaseCG.cginc" #include "SwfBaseCG.cginc"

View File

@@ -1,7 +1,9 @@
Shader "FlashTools/SwfSimpleGrab" { Shader "FlashTools/SwfSimpleGrab" {
Properties { Properties {
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1) [PerRendererData] _AlphaTex ("Alpha Texture" , 2D ) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0 [Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1 [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
@@ -30,7 +32,9 @@ Shader "FlashTools/SwfSimpleGrab" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND #pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND

View File

@@ -1,7 +1,9 @@
Shader "FlashTools/SwfSimple" { Shader "FlashTools/SwfSimple" {
Properties { Properties {
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {} [PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1) [PerRendererData] _AlphaTex ("Alpha Texture" , 2D ) = "white" {}
[PerRendererData] _ExternalAlpha ("External Alpha", Float) = 0
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0 [Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1 [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfSimple" {
CGPROGRAM CGPROGRAM
fixed4 _Tint; fixed4 _Tint;
sampler2D _MainTex; sampler2D _MainTex;
sampler2D _AlphaTex;
sampler2D _GrabTexture; sampler2D _GrabTexture;
float _ExternalAlpha;
#include "UnityCG.cginc" #include "UnityCG.cginc"
#include "SwfBaseCG.cginc" #include "SwfBaseCG.cginc"

View File

@@ -12,10 +12,24 @@ namespace FTEditor.Editors {
static MaterialPropertyBlock _matPropBlock = null; static MaterialPropertyBlock _matPropBlock = null;
static PreviewRenderUtility _previewUtils = null; static PreviewRenderUtility _previewUtils = null;
Texture2D targetAtlas { Sprite targetSprite {
get { get {
var clip = target as SwfClipAsset; var clip = target as SwfClipAsset;
return clip.Atlas; return clip ? clip.Sprite : null;
}
}
Texture2D targetAtlas {
get {
var sprite = targetSprite;
return sprite ? sprite.texture : null;
}
}
Texture2D targetAtlasA {
get {
var sprite = targetSprite;
return sprite ? sprite.associatedAlphaSplitTexture : null;
} }
} }
@@ -160,7 +174,15 @@ namespace FTEditor.Editors {
if ( isTargetValidForPreview ) { if ( isTargetValidForPreview ) {
_previewUtils.BeginPreview(r, background); _previewUtils.BeginPreview(r, background);
{ {
_matPropBlock.SetTexture("_MainTex", targetAtlas); if ( targetAtlas ) {
_matPropBlock.SetTexture("_MainTex", targetAtlas);
}
if ( targetAtlasA ) {
_matPropBlock.SetTexture("_AlphaTex", targetAtlasA);
_matPropBlock.SetFloat("_ExternalAlpha", 1.0f);
} else {
_matPropBlock.SetFloat("_ExternalAlpha", 0.0f);
}
ConfigureCameraForSequence(_previewUtils.m_Camera, targetSequence); ConfigureCameraForSequence(_previewUtils.m_Camera, targetSequence);
var frame = targetFrame; var frame = targetFrame;
for ( var i = 0; i < frame.Materials.Length; ++i ) { for ( var i = 0; i < frame.Materials.Length; ++i ) {

View File

@@ -211,9 +211,8 @@ namespace FTEditor.Postprocessors {
static void ConfigureAtlas(SwfAsset asset) { static void ConfigureAtlas(SwfAsset asset) {
var atlas_path = AssetDatabase.GetAssetPath(asset.Atlas); var atlas_path = AssetDatabase.GetAssetPath(asset.Atlas);
var atlas_importer = GetBitmapsAtlasImporter(asset); var atlas_importer = GetBitmapsAtlasImporter(asset);
atlas_importer.spritesheet = new SpriteMetaData[0];
atlas_importer.textureType = TextureImporterType.Sprite; atlas_importer.textureType = TextureImporterType.Sprite;
atlas_importer.spriteImportMode = SpriteImportMode.Multiple; atlas_importer.spriteImportMode = SpriteImportMode.Single;
atlas_importer.spritePixelsPerUnit = asset.Settings.PixelsPerUnit; atlas_importer.spritePixelsPerUnit = asset.Settings.PixelsPerUnit;
atlas_importer.mipmapEnabled = asset.Settings.GenerateMipMaps; atlas_importer.mipmapEnabled = asset.Settings.GenerateMipMaps;
atlas_importer.filterMode = SwfAtlasFilterToImporterFilter(asset.Settings.AtlasTextureFilter); atlas_importer.filterMode = SwfAtlasFilterToImporterFilter(asset.Settings.AtlasTextureFilter);
@@ -306,8 +305,9 @@ namespace FTEditor.Postprocessors {
SwfClipAsset clip_asset, SwfAsset asset, SwfAssetData data, SwfSymbolData symbol) SwfClipAsset clip_asset, SwfAsset asset, SwfAssetData data, SwfSymbolData symbol)
{ {
var asset_guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset)); var asset_guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset));
var asset_atlas = AssetDatabase.LoadAssetAtPath<Sprite>(AssetDatabase.GetAssetPath(asset.Atlas));
clip_asset.Name = symbol.Name; clip_asset.Name = symbol.Name;
clip_asset.Atlas = asset.Atlas; clip_asset.Sprite = asset_atlas;
clip_asset.AssetGUID = asset_guid; clip_asset.AssetGUID = asset_guid;
clip_asset.FrameRate = data.FrameRate; clip_asset.FrameRate = data.FrameRate;
clip_asset.Sequences = LoadClipSequences(asset, data, symbol); clip_asset.Sequences = LoadClipSequences(asset, data, symbol);

View File

@@ -344,12 +344,19 @@ namespace FTRuntime {
_curPropBlock = new MaterialPropertyBlock(); _curPropBlock = new MaterialPropertyBlock();
} }
_meshRenderer.GetPropertyBlock(_curPropBlock); _meshRenderer.GetPropertyBlock(_curPropBlock);
_curPropBlock.SetColor( _curPropBlock.SetColor("_Tint", tint);
"_Tint", var sprite = clip ? clip.Sprite : null;
tint); var atlas = sprite && sprite.texture ? sprite.texture : Texture2D.whiteTexture;
_curPropBlock.SetTexture( var atlasA = sprite ? sprite.associatedAlphaSplitTexture : null;
"_MainTex", if ( atlas ) {
clip && clip.Atlas ? clip.Atlas : Texture2D.whiteTexture); _curPropBlock.SetTexture("_MainTex", atlas);
}
if ( atlasA ) {
_curPropBlock.SetTexture("_AlphaTex", atlasA);
_curPropBlock.SetFloat("_ExternalAlpha", 1.0f);
} else {
_curPropBlock.SetFloat("_ExternalAlpha", 0.0f);
}
_meshRenderer.SetPropertyBlock(_curPropBlock); _meshRenderer.SetPropertyBlock(_curPropBlock);
} }
} }

View File

@@ -61,7 +61,7 @@ namespace FTRuntime {
[SwfReadOnly] [SwfReadOnly]
public string Name; public string Name;
[SwfReadOnly] [SwfReadOnly]
public Texture2D Atlas; public Sprite Sprite;
[SwfReadOnly] [SwfReadOnly]
public float FrameRate; public float FrameRate;
[HideInInspector] [HideInInspector]
@@ -71,7 +71,7 @@ namespace FTRuntime {
void Reset() { void Reset() {
Name = string.Empty; Name = string.Empty;
Atlas = null; Sprite = null;
FrameRate = 1.0f; FrameRate = 1.0f;
AssetGUID = string.Empty; AssetGUID = string.Empty;
Sequences = new List<Sequence>(); Sequences = new List<Sequence>();

View File

@@ -6,4 +6,4 @@ EditorBuildSettings:
serializedVersion: 2 serializedVersion: 2
m_Scenes: m_Scenes:
- enabled: 1 - enabled: 1
path: Assets/FlashTools/Example/Scene.unity path: Assets/DevTests/Scenes/Scene.unity

View File

@@ -93,7 +93,7 @@ PlayerSettings:
16:10: 1 16:10: 1
16:9: 1 16:9: 1
Others: 1 Others: 1
bundleIdentifier: com.Company.ProductName bundleIdentifier: me.matov.ft_demo
bundleVersion: 1.0 bundleVersion: 1.0
preloadedAssets: [] preloadedAssets: []
metroEnableIndependentInputSource: 0 metroEnableIndependentInputSource: 0