mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-15 12:29:49 +07:00
ETC1 support
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
-------------------
|
||||
-- Version 1.X.X --
|
||||
-------------------
|
||||
|
||||
ETC separated alpha support
|
||||
|
||||
-------------------
|
||||
-- Version 1.2.0 --
|
||||
-------------------
|
||||
|
||||
@@ -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 {
|
||||
fixed4 c = tex2D(_MainTex, IN.uv);
|
||||
if ( _ExternalAlpha ) {
|
||||
c.a *= tex2D(_AlphaTex, IN.uv).r;
|
||||
}
|
||||
if ( c.a > 0.01 ) {
|
||||
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 {
|
||||
fixed4 c = tex2D(_MainTex, IN.uv);
|
||||
if ( _ExternalAlpha ) {
|
||||
c.a *= tex2D(_AlphaTex, IN.uv).r;
|
||||
}
|
||||
if ( c.a > 0.01 ) {
|
||||
c = c * IN.mulcolor + IN.addcolor;
|
||||
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 {
|
||||
fixed4 c = tex2D(_MainTex, IN.uv);
|
||||
if ( _ExternalAlpha ) {
|
||||
c.a *= tex2D(_AlphaTex, IN.uv).r;
|
||||
}
|
||||
if ( c.a < 0.01 ) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
Shader "FlashTools/SwfDecrMask" {
|
||||
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 {
|
||||
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfDecrMask" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SwfBaseCG.cginc"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
Shader "FlashTools/SwfIncrMask" {
|
||||
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 {
|
||||
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfIncrMask" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SwfBaseCG.cginc"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
Shader "FlashTools/SwfMaskedGrab" {
|
||||
Properties {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
[PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
|
||||
[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
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
@@ -35,7 +37,9 @@ Shader "FlashTools/SwfMaskedGrab" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
Shader "FlashTools/SwfMasked" {
|
||||
Properties {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
[PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
|
||||
[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
|
||||
[Enum(UnityEngine.Rendering.BlendOp )] _BlendOp ("BlendOp" , Int) = 0
|
||||
@@ -33,7 +35,9 @@ Shader "FlashTools/SwfMasked" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SwfBaseCG.cginc"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
Shader "FlashTools/SwfSimpleGrab" {
|
||||
Properties {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
[PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
|
||||
[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.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
@@ -30,7 +32,9 @@ Shader "FlashTools/SwfSimpleGrab" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
Shader "FlashTools/SwfSimple" {
|
||||
Properties {
|
||||
[PerRendererData] _MainTex ("Main Texture", 2D ) = "white" {}
|
||||
[PerRendererData] _Tint ("Tint" , Color) = (1,1,1,1)
|
||||
[PerRendererData] _MainTex ("Main Texture" , 2D ) = "white" {}
|
||||
[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.BlendMode)] _SrcBlend ("SrcBlend", Int) = 1
|
||||
@@ -28,7 +30,9 @@ Shader "FlashTools/SwfSimple" {
|
||||
CGPROGRAM
|
||||
fixed4 _Tint;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _AlphaTex;
|
||||
sampler2D _GrabTexture;
|
||||
float _ExternalAlpha;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SwfBaseCG.cginc"
|
||||
|
||||
@@ -12,10 +12,24 @@ namespace FTEditor.Editors {
|
||||
static MaterialPropertyBlock _matPropBlock = null;
|
||||
static PreviewRenderUtility _previewUtils = null;
|
||||
|
||||
Texture2D targetAtlas {
|
||||
Sprite targetSprite {
|
||||
get {
|
||||
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 ) {
|
||||
_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);
|
||||
var frame = targetFrame;
|
||||
for ( var i = 0; i < frame.Materials.Length; ++i ) {
|
||||
|
||||
@@ -211,9 +211,8 @@ namespace FTEditor.Postprocessors {
|
||||
static void ConfigureAtlas(SwfAsset asset) {
|
||||
var atlas_path = AssetDatabase.GetAssetPath(asset.Atlas);
|
||||
var atlas_importer = GetBitmapsAtlasImporter(asset);
|
||||
atlas_importer.spritesheet = new SpriteMetaData[0];
|
||||
atlas_importer.textureType = TextureImporterType.Sprite;
|
||||
atlas_importer.spriteImportMode = SpriteImportMode.Multiple;
|
||||
atlas_importer.spriteImportMode = SpriteImportMode.Single;
|
||||
atlas_importer.spritePixelsPerUnit = asset.Settings.PixelsPerUnit;
|
||||
atlas_importer.mipmapEnabled = asset.Settings.GenerateMipMaps;
|
||||
atlas_importer.filterMode = SwfAtlasFilterToImporterFilter(asset.Settings.AtlasTextureFilter);
|
||||
@@ -306,8 +305,9 @@ namespace FTEditor.Postprocessors {
|
||||
SwfClipAsset clip_asset, SwfAsset asset, SwfAssetData data, SwfSymbolData symbol)
|
||||
{
|
||||
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.Atlas = asset.Atlas;
|
||||
clip_asset.Sprite = asset_atlas;
|
||||
clip_asset.AssetGUID = asset_guid;
|
||||
clip_asset.FrameRate = data.FrameRate;
|
||||
clip_asset.Sequences = LoadClipSequences(asset, data, symbol);
|
||||
|
||||
@@ -344,12 +344,19 @@ namespace FTRuntime {
|
||||
_curPropBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
_meshRenderer.GetPropertyBlock(_curPropBlock);
|
||||
_curPropBlock.SetColor(
|
||||
"_Tint",
|
||||
tint);
|
||||
_curPropBlock.SetTexture(
|
||||
"_MainTex",
|
||||
clip && clip.Atlas ? clip.Atlas : Texture2D.whiteTexture);
|
||||
_curPropBlock.SetColor("_Tint", tint);
|
||||
var sprite = clip ? clip.Sprite : null;
|
||||
var atlas = sprite && sprite.texture ? sprite.texture : Texture2D.whiteTexture;
|
||||
var atlasA = sprite ? sprite.associatedAlphaSplitTexture : null;
|
||||
if ( atlas ) {
|
||||
_curPropBlock.SetTexture("_MainTex", atlas);
|
||||
}
|
||||
if ( atlasA ) {
|
||||
_curPropBlock.SetTexture("_AlphaTex", atlasA);
|
||||
_curPropBlock.SetFloat("_ExternalAlpha", 1.0f);
|
||||
} else {
|
||||
_curPropBlock.SetFloat("_ExternalAlpha", 0.0f);
|
||||
}
|
||||
_meshRenderer.SetPropertyBlock(_curPropBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace FTRuntime {
|
||||
[SwfReadOnly]
|
||||
public string Name;
|
||||
[SwfReadOnly]
|
||||
public Texture2D Atlas;
|
||||
public Sprite Sprite;
|
||||
[SwfReadOnly]
|
||||
public float FrameRate;
|
||||
[HideInInspector]
|
||||
@@ -71,7 +71,7 @@ namespace FTRuntime {
|
||||
|
||||
void Reset() {
|
||||
Name = string.Empty;
|
||||
Atlas = null;
|
||||
Sprite = null;
|
||||
FrameRate = 1.0f;
|
||||
AssetGUID = string.Empty;
|
||||
Sequences = new List<Sequence>();
|
||||
|
||||
@@ -6,4 +6,4 @@ EditorBuildSettings:
|
||||
serializedVersion: 2
|
||||
m_Scenes:
|
||||
- enabled: 1
|
||||
path: Assets/FlashTools/Example/Scene.unity
|
||||
path: Assets/DevTests/Scenes/Scene.unity
|
||||
|
||||
@@ -93,7 +93,7 @@ PlayerSettings:
|
||||
16:10: 1
|
||||
16:9: 1
|
||||
Others: 1
|
||||
bundleIdentifier: com.Company.ProductName
|
||||
bundleIdentifier: me.matov.ft_demo
|
||||
bundleVersion: 1.0
|
||||
preloadedAssets: []
|
||||
metroEnableIndependentInputSource: 0
|
||||
|
||||
Reference in New Issue
Block a user