diff --git a/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc b/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc index 4bf9a9a..753e99c 100644 --- a/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc +++ b/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc @@ -2,41 +2,60 @@ #define SWF_BASE_CG_INCLUDED // -// +// blending functions // -fixed4 swf_darken(fixed4 a, fixed4 b) { +inline fixed4 swf_darken(fixed4 a, fixed4 b) { fixed4 r = min(a, b); r.a = b.a; return r; } -fixed4 swf_difference(fixed4 a, fixed4 b) { +inline fixed4 swf_difference(fixed4 a, fixed4 b) { fixed4 r = abs(a - b); r.a = b.a; return r; } -fixed4 swf_invert(fixed4 a, fixed4 b) { +inline fixed4 swf_invert(fixed4 a, fixed4 b) { fixed4 r = 1 - a; r.a = b.a; return r; } -fixed4 swf_overlay(fixed4 a, fixed4 b) { +inline fixed4 swf_overlay(fixed4 a, fixed4 b) { fixed4 r = a > 0.5 ? 1.0 - 2.0 * (1.0 - a) * (1.0 - b) : 2.0 * a * b; r.a = b.a; return r; } -fixed4 swf_hardlight(fixed4 a, fixed4 b) { +inline fixed4 swf_hardlight(fixed4 a, fixed4 b) { fixed4 r = b > 0.5 ? 1.0 - (1.0 - a) * (1.0 - 2.0 * (b - 0.5)) : a * (2.0 * b); r.a = b.a; return r; } +inline fixed4 grab_blend(sampler2D grab_tex, float4 screenpos, fixed4 c) { + float2 grab_uv = screenpos.xy / screenpos.w; + grab_uv.x = (grab_uv.x + 1.0) * .5; + grab_uv.y = (grab_uv.y + 1.0) * .5; + fixed4 grab_c = tex2D(grab_tex, grab_uv); + #if SWF_DARKEN_BLEND + c = swf_darken(grab_c, c); + #elif SWF_DIFFERENCE_BLEND + c = swf_difference(grab_c, c); + #elif SWF_INVERT_BLEND + c = swf_invert(grab_c, c); + #elif SWF_OVERLAY_BLEND + c = swf_overlay(grab_c, c); + #elif SWF_HARDLIGHT_BLEND + c = swf_hardlight(grab_c, c); + #endif + return c; +} + // -// +// structs // struct swf_appdata_t { @@ -62,18 +81,8 @@ struct swf_grab_v2f_t { }; // +// vert functions // -// - -inline fixed4 swf_sample_sprite_texture(sampler2D main_tex, float2 uv) { - fixed4 c = tex2D(main_tex, uv); -#if UNITY_TEXTURE_ALPHASPLIT_ALLOWED - if ( _AlphaSplitEnabled ) { - c.a = tex2D(_AlphaTex, uv).r; - } -#endif - return c; -} inline swf_v2f_t swf_vert(swf_appdata_t IN) { swf_v2f_t OUT; @@ -94,8 +103,12 @@ inline swf_grab_v2f_t swf_grab_vert(swf_appdata_t IN) { return OUT; } +// +// frag functions +// + inline fixed4 swf_frag(swf_v2f_t IN) : SV_Target { - fixed4 c = swf_sample_sprite_texture(_MainTex, IN.uv); + fixed4 c = tex2D(_MainTex, IN.uv); if ( c.a > 0.01 ) { c = c * IN.mulcolor + IN.addcolor; } @@ -104,28 +117,11 @@ inline fixed4 swf_frag(swf_v2f_t IN) : SV_Target { } inline fixed4 swf_grab_frag(swf_grab_v2f_t IN) : SV_Target { - fixed4 c = swf_sample_sprite_texture(_MainTex, IN.uv); + fixed4 c = tex2D(_MainTex, IN.uv); if ( c.a > 0.01 ) { c = c * IN.mulcolor + IN.addcolor; } - - float2 grabTexcoord = IN.screenpos.xy / IN.screenpos.w; - grabTexcoord.x = (grabTexcoord.x + 1.0) * .5; - grabTexcoord.y = (grabTexcoord.y + 1.0) * .5; - fixed4 grabColor = tex2D(_GrabTexture, grabTexcoord); - - #if FT_DARKEN_BLEND - c = swf_darken(grabColor, c); - #elif FT_DIFFERENCE_BLEND - c = swf_difference(grabColor, c); - #elif FT_INVERT_BLEND - c = swf_invert(grabColor, c); - #elif FT_OVERLAY_BLEND - c = swf_overlay(grabColor, c); - #elif FT_HARDLIGHT_BLEND - c = swf_hardlight(grabColor, c); - #endif - + c = grab_blend(_GrabTexture, IN.screenpos, c); c.rgb *= c.a; return c; } diff --git a/Assets/FlashTools/Resources/Materials/SwfMaskedGrabShader.shader b/Assets/FlashTools/Resources/Materials/SwfMaskedGrabShader.shader index 74c1f77..e4dae1e 100644 --- a/Assets/FlashTools/Resources/Materials/SwfMaskedGrabShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfMaskedGrabShader.shader @@ -36,10 +36,8 @@ Shader "FlashTools/SwfGrabMasked" { fixed4 _Tint; sampler2D _MainTex; sampler2D _GrabTexture; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; - #pragma multi_compile FT_DARKEN_BLEND FT_DIFFERENCE_BLEND FT_INVERT_BLEND FT_OVERLAY_BLEND FT_HARDLIGHT_BLEND + #pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND #include "UnityCG.cginc" #include "SwfBaseCG.cginc" diff --git a/Assets/FlashTools/Resources/Materials/SwfMaskedShader.shader b/Assets/FlashTools/Resources/Materials/SwfMaskedShader.shader index ce4916a..e2aa592 100644 --- a/Assets/FlashTools/Resources/Materials/SwfMaskedShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfMaskedShader.shader @@ -34,8 +34,6 @@ Shader "FlashTools/SwfMasked" { fixed4 _Tint; sampler2D _MainTex; sampler2D _GrabTexture; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; #include "UnityCG.cginc" #include "SwfBaseCG.cginc" diff --git a/Assets/FlashTools/Resources/Materials/SwfSimpleGrabShader.shader b/Assets/FlashTools/Resources/Materials/SwfSimpleGrabShader.shader index 58fe74b..f70236d 100644 --- a/Assets/FlashTools/Resources/Materials/SwfSimpleGrabShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfSimpleGrabShader.shader @@ -31,10 +31,8 @@ Shader "FlashTools/SwfGrabSimple" { fixed4 _Tint; sampler2D _MainTex; sampler2D _GrabTexture; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; - #pragma multi_compile FT_DARKEN_BLEND FT_DIFFERENCE_BLEND FT_INVERT_BLEND FT_OVERLAY_BLEND FT_HARDLIGHT_BLEND + #pragma multi_compile SWF_DARKEN_BLEND SWF_DIFFERENCE_BLEND SWF_INVERT_BLEND SWF_OVERLAY_BLEND SWF_HARDLIGHT_BLEND #include "UnityCG.cginc" #include "SwfBaseCG.cginc" diff --git a/Assets/FlashTools/Resources/Materials/SwfSimpleShader.shader b/Assets/FlashTools/Resources/Materials/SwfSimpleShader.shader index 0054240..5d96c5f 100644 --- a/Assets/FlashTools/Resources/Materials/SwfSimpleShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfSimpleShader.shader @@ -29,8 +29,6 @@ Shader "FlashTools/SwfSimple" { fixed4 _Tint; sampler2D _MainTex; sampler2D _GrabTexture; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; #include "UnityCG.cginc" #include "SwfBaseCG.cginc" diff --git a/Assets/FlashTools/Scripts/Internal/SwfSettings.cs b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs index 18ab7c7..73e6738 100644 --- a/Assets/FlashTools/Scripts/Internal/SwfSettings.cs +++ b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs @@ -220,13 +220,13 @@ namespace FlashTools.Internal { material.SetInt("_BlendOp" , (int)BlendOp.Add); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); - material.EnableKeyword("FT_DARKEN_BLEND"); + material.EnableKeyword("SWF_DARKEN_BLEND"); break; case SwfBlendModeData.Types.Difference: material.SetInt("_BlendOp" , (int)BlendOp.Add); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); - material.EnableKeyword("FT_DIFFERENCE_BLEND"); + material.EnableKeyword("SWF_DIFFERENCE_BLEND"); break; case SwfBlendModeData.Types.Add: material.SetInt("_BlendOp" , (int)BlendOp.Add); @@ -242,19 +242,19 @@ namespace FlashTools.Internal { material.SetInt("_BlendOp" , (int)BlendOp.Add); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); - material.EnableKeyword("FT_INVERT_BLEND"); + material.EnableKeyword("SWF_INVERT_BLEND"); break; case SwfBlendModeData.Types.Overlay: material.SetInt("_BlendOp" , (int)BlendOp.Add); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); - material.EnableKeyword("FT_OVERLAY_BLEND"); + material.EnableKeyword("SWF_OVERLAY_BLEND"); break; case SwfBlendModeData.Types.Hardlight: material.SetInt("_BlendOp" , (int)BlendOp.Add); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha); - material.EnableKeyword("FT_HARDLIGHT_BLEND"); + material.EnableKeyword("SWF_HARDLIGHT_BLEND"); break; default: throw new UnityException(string.Format(