remove external alpha IF from shaders

This commit is contained in:
2017-05-15 04:49:25 +07:00
parent d591379acc
commit a38e05f955
5 changed files with 16 additions and 16 deletions

View File

@@ -3,6 +3,7 @@
* Fix locked elements problem
* Fix optimizator bitmap trim problems
* Add shape tween warning
* Remove excess "if" instruction from shaders
###### Version 1.3.7
* Fix multiple import

View File

@@ -135,9 +135,8 @@ 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;
}
fixed4 a = tex2D(_AlphaTex, IN.uv).r;
c.a = lerp(c.a, a.r, _ExternalAlpha);
if ( c.a > 0.01 ) {
c = c * IN.mulcolor + IN.addcolor;
}
@@ -147,9 +146,8 @@ 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;
}
fixed4 a = tex2D(_AlphaTex, IN.uv).r;
c.a = lerp(c.a, a.r, _ExternalAlpha);
if ( c.a > 0.01 ) {
c = c * IN.mulcolor + IN.addcolor;
c = grab_blend(_GrabTexture, IN.screenpos, c);
@@ -160,9 +158,8 @@ 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;
}
fixed4 a = tex2D(_AlphaTex, IN.uv).r;
c.a = lerp(c.a, a.r, _ExternalAlpha);
if ( c.a < 0.01 ) {
discard;
}

View File

@@ -174,13 +174,14 @@ namespace FTEditor.Editors {
if ( isTargetValidForPreview ) {
_previewUtils.BeginPreview(r, background);
{
if ( targetAtlas ) {
_matPropBlock.SetTexture("_MainTex", targetAtlas);
}
_matPropBlock.SetTexture(
"_MainTex",
targetAtlas ? targetAtlas : Texture2D.whiteTexture);
if ( targetAtlasA ) {
_matPropBlock.SetTexture("_AlphaTex", targetAtlasA);
_matPropBlock.SetFloat("_ExternalAlpha", 1.0f);
} else {
_matPropBlock.SetTexture("_AlphaTex", Texture2D.whiteTexture);
_matPropBlock.SetFloat("_ExternalAlpha", 0.0f);
}
ConfigureCameraForSequence(_previewUtils.m_Camera, targetSequence);

View File

@@ -348,13 +348,14 @@ namespace FTRuntime {
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);
}
_curPropBlock.SetTexture(
"_MainTex",
atlas ? atlas : Texture2D.whiteTexture);
if ( atlasA ) {
_curPropBlock.SetTexture("_AlphaTex", atlasA);
_curPropBlock.SetFloat("_ExternalAlpha", 1.0f);
} else {
_curPropBlock.SetTexture("_AlphaTex", Texture2D.whiteTexture);
_curPropBlock.SetFloat("_ExternalAlpha", 0.0f);
}
_meshRenderer.SetPropertyBlock(_curPropBlock);