• Unity
  • Fill shader for non PMA texture?

  • Изменено
Related Discussions
...

Hey, I'm forced to not use the default premultiplied alpha and and just using regular alpha. It works with the Sprites/default shader but I was using the skeleton Fill shader to change color on my skeletons. I tried messing with float4 frag (VertexOutput i) : COLOR but couldn't get the right effect. Any hints?

// - Requires PMA texture.
// - Unlit + no shadow
// - Premultiplied Alpha Blending (One OneMinusSrcAlpha)
// - Double-sided, no depth
// - Can render a sprite with a solid color overlay (_FillColor). Use _FillPhase to adjust color overlay amount. 

Shader "Spine/Skeleton Fill" {
   Properties {
      _FillColor ("FillColor", Color) = (1,1,1,1)
      _FillPhase ("FillPhase", Range(0, 1)) = 0
      [NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {}
   }
   SubShader {
      Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" "PreviewType"="Plane" }
      Blend One OneMinusSrcAlpha
      Cull Off
      ZWrite Off
      Lighting Off

  Pass {
     CGPROGRAM
     #pragma vertex vert
     #pragma fragment frag
     #include "UnityCG.cginc"
     sampler2D _MainTex;
     float4 _FillColor;
     float _FillPhase;

     struct VertexInput {
        float4 vertex : POSITION;
        float2 uv : TEXCOORD0;
        float4 vertexColor : COLOR;
     };

     struct VertexOutput {
        float4 pos : SV_POSITION;
        float2 uv : TEXCOORD0;
        float4 vertexColor : COLOR;
     };

     VertexOutput vert (VertexInput v) {
        VertexOutput o = (VertexOutput)0;
        o.uv = v.uv;
        o.vertexColor = v.vertexColor;
        o.pos = UnityObjectToClipPos(v.vertex); // Unity 5.6
        return o;
     }

     float4 frag (VertexOutput i) : COLOR {
        float4 rawColor = tex2D(_MainTex,i.uv);
        float finalAlpha = (rawColor.a * i.vertexColor.a);
        float3 finalColor = lerp((rawColor.rgb * i.vertexColor.rgb), (_FillColor.rgb * finalAlpha), _FillPhase); // make sure to PMA _FillColor.
        return fixed4(finalColor, finalAlpha);
     }
     ENDCG
  }
   }
   FallBack "Diffuse"
}

Here you go:
spine-runtimes/Spine-Straight-Skeleton-Fill.shader at 3.6

Note the different shader name Spine/Straight Alpha/Skeleton Fill

It's technically still a PMA shader but doesn't require a PMA texture. This follows the way Unity's Sprite/Default shader works.

Thanks it works.