diff --git a/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc b/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc index 3cc365e..7aac043 100644 --- a/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc +++ b/Assets/FlashTools/Resources/Materials/SwfBaseCG.cginc @@ -5,40 +5,39 @@ // blending functions // -inline fixed4 swf_darken(fixed4 a, fixed4 b) { - fixed4 r = min(a, b); - r.a = b.a; +inline fixed4 swf_darken(fixed4 ca, fixed4 cb) { + fixed4 r = min(ca, cb); + r.a = cb.a; return r; } -inline fixed4 swf_difference(fixed4 a, fixed4 b) { - fixed4 r = abs(a - b); - r.a = b.a; +inline fixed4 swf_difference(fixed4 ca, fixed4 cb) { + fixed4 r = abs(ca - cb); + r.a = cb.a; return r; } -inline fixed4 swf_invert(fixed4 a, fixed4 b) { - fixed4 r = 1 - a; - r.a = b.a; +inline fixed4 swf_invert(fixed4 ca, fixed4 cb) { + fixed4 r = 1.0 - ca; + r.a = cb.a; return r; } -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; +inline fixed4 swf_overlay(fixed4 ca, fixed4 cb) { + fixed4 r = ca > 0.5 ? 1.0 - 2.0 * (1.0 - ca) * (1.0 - cb) : 2.0 * ca * cb; + r.a = cb.a; return r; } -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; +inline fixed4 swf_hardlight(fixed4 ca, fixed4 cb) { + fixed4 r = cb > 0.5 ? 1.0 - (1.0 - ca) * (1.0 - 2.0 * (cb - 0.5)) : ca * (2.0 * cb); + r.a = cb.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; + grab_uv = (grab_uv + 1.0) * 0.5; #if UNITY_UV_STARTS_AT_TOP grab_uv.y = 1.0 - grab_uv.y; #endif @@ -68,6 +67,18 @@ struct swf_appdata_t { float4 addcolor : TEXCOORD1; }; +struct swf_grab_appdata_t { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + float4 mulcolor : COLOR; + float4 addcolor : TEXCOORD1; +}; + +struct swf_mask_appdata_t { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; +}; + struct swf_v2f_t { float4 vertex : SV_POSITION; float2 uv : TEXCOORD0; @@ -83,6 +94,11 @@ struct swf_grab_v2f_t { float4 screenpos : TEXCOORD2; }; +struct swf_mask_v2f_t { + float4 vertex : SV_POSITION; + float2 uv : TEXCOORD0; +}; + // // vert functions // @@ -96,7 +112,7 @@ inline swf_v2f_t swf_vert(swf_appdata_t IN) { return OUT; } -inline swf_grab_v2f_t swf_grab_vert(swf_appdata_t IN) { +inline swf_grab_v2f_t swf_grab_vert(swf_grab_appdata_t IN) { swf_grab_v2f_t OUT; OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); OUT.uv = IN.uv; @@ -106,6 +122,13 @@ inline swf_grab_v2f_t swf_grab_vert(swf_appdata_t IN) { return OUT; } +inline swf_mask_v2f_t swf_mask_vert(swf_mask_appdata_t IN) { + swf_mask_v2f_t OUT; + OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); + OUT.uv = IN.uv; + return OUT; +} + // // frag functions // @@ -123,10 +146,18 @@ inline fixed4 swf_grab_frag(swf_grab_v2f_t IN) : SV_Target { fixed4 c = tex2D(_MainTex, IN.uv); if ( c.a > 0.01 ) { c = c * IN.mulcolor + IN.addcolor; + c = grab_blend(_GrabTexture, IN.screenpos, c); } - c = grab_blend(_GrabTexture, IN.screenpos, c); c.rgb *= c.a; return c; } +inline fixed4 swf_mask_frag(swf_mask_v2f_t IN) : SV_Target { + fixed4 c = tex2D(_MainTex, IN.uv); + if ( c.a < 0.01 ) { + discard; + } + return c; +} + #endif // SWF_BASE_CG_INCLUDED \ No newline at end of file diff --git a/Assets/FlashTools/Resources/Materials/SwfDecrMaskShader.shader b/Assets/FlashTools/Resources/Materials/SwfDecrMaskShader.shader index 67d59e7..95bfe39 100644 --- a/Assets/FlashTools/Resources/Materials/SwfDecrMaskShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfDecrMaskShader.shader @@ -12,10 +12,11 @@ Shader "FlashTools/SwfDecrMask" { "CanUseSpriteAtlas" = "True" } - ColorMask 0 Cull Off Lighting Off ZWrite Off + + ColorMask 0 Blend One OneMinusSrcAlpha Pass { @@ -25,47 +26,15 @@ Shader "FlashTools/SwfDecrMask" { Pass DecrSat } CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #include "UnityCG.cginc" - - struct appdata_t { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; - - struct v2f { - float4 vertex : SV_POSITION; - float2 uv : TEXCOORD0; - }; - - v2f vert(appdata_t IN) { - v2f OUT; - OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); - OUT.uv = IN.uv; - return OUT; - } - + fixed4 _Tint; sampler2D _MainTex; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; + sampler2D _GrabTexture; - fixed4 SampleSpriteTexture(float2 uv) { - fixed4 color = tex2D(_MainTex, uv); - #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED - if (_AlphaSplitEnabled) - color.a = tex2D(_AlphaTex, uv).r; - #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED - return color; - } + #include "UnityCG.cginc" + #include "SwfBaseCG.cginc" - fixed4 frag(v2f IN) : SV_Target { - fixed4 c = SampleSpriteTexture(IN.uv); - if ( c.a < 0.01 ) { - discard; - } - return c; - } + #pragma vertex swf_mask_vert + #pragma fragment swf_mask_frag ENDCG } } diff --git a/Assets/FlashTools/Resources/Materials/SwfIncrMaskShader.shader b/Assets/FlashTools/Resources/Materials/SwfIncrMaskShader.shader index 5530826..ba7dbde 100644 --- a/Assets/FlashTools/Resources/Materials/SwfIncrMaskShader.shader +++ b/Assets/FlashTools/Resources/Materials/SwfIncrMaskShader.shader @@ -12,10 +12,11 @@ Shader "FlashTools/SwfIncrMask" { "CanUseSpriteAtlas" = "True" } - ColorMask 0 Cull Off Lighting Off ZWrite Off + + ColorMask 0 Blend One OneMinusSrcAlpha Pass { @@ -25,47 +26,15 @@ Shader "FlashTools/SwfIncrMask" { Pass IncrSat } CGPROGRAM - #pragma vertex vert - #pragma fragment frag - #include "UnityCG.cginc" - - struct appdata_t { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; - - struct v2f { - float4 vertex : SV_POSITION; - float2 uv : TEXCOORD0; - }; - - v2f vert(appdata_t IN) { - v2f OUT; - OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); - OUT.uv = IN.uv; - return OUT; - } - + fixed4 _Tint; sampler2D _MainTex; - sampler2D _AlphaTex; - float _AlphaSplitEnabled; + sampler2D _GrabTexture; - fixed4 SampleSpriteTexture(float2 uv) { - fixed4 color = tex2D(_MainTex, uv); - #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED - if (_AlphaSplitEnabled) - color.a = tex2D(_AlphaTex, uv).r; - #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED - return color; - } + #include "UnityCG.cginc" + #include "SwfBaseCG.cginc" - fixed4 frag(v2f IN) : SV_Target { - fixed4 c = SampleSpriteTexture(IN.uv); - if ( c.a < 0.01 ) { - discard; - } - return c; - } + #pragma vertex swf_mask_vert + #pragma fragment swf_mask_frag ENDCG } } diff --git a/unityflash.userprefs b/unityflash.userprefs index ce070d9..cd9316b 100644 --- a/unityflash.userprefs +++ b/unityflash.userprefs @@ -1,10 +1,12 @@  - + - - - + + + + +