surface shader homeworld (space) colorize transparent

Hi,

I have a problem regarding a fragment-shader. I tried to port a homeworld shader to unity which is working very nice except one problem remaining.

The teamcolors should only be shown on the transparent areas of the texture. Actually the whole ship is colorized.

Here is the unity part:

Shader "Kilomoana/s_ship" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_SpecSI ("SpecSI (RGB)", 2D) = "white" {}
		_Shininess ("Shininess", Range (0.01, 10)) = 0.078125
		_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
		_SelfIlluminationBlue("Glow Blue", Range (0, 1)) = 0.5
		_ColorA("Team Color A", Color) = (1,0.8,0,1)
		_ColorB("Team Color B", Color) = (0,0,1,1)
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf BlinnPhong
		sampler2D _MainTex;
		sampler2D _SpecSI;
		float _Shininess;
		float _SelfIlluminationBlue;
		float4 _ColorA;
		float4 _ColorB;
		
		struct Input {
			float2 uv_MainTex;
			float3 worldRefl;
		};

		void surf (Input IN, inout SurfaceOutput o)
		{
			// diffuse color
			half4 c  = tex2D (_MainTex, IN.uv_MainTex);
			
			// specular & glow strength
			half4 c2 = tex2D (_SpecSI , IN.uv_MainTex);

			// two colors
			float4 teamBaseCol   = (c + 0.5f) * _ColorA + (c - 0.5f);
			float4 teamStripeCol = (c + 0.5f) * _ColorB + (c - 0.5f);
			
			// team color amount is defined by alpha values
			float teamBaseAmount   = 1 - c.a;
			float teamStripeAmount = 1 - c2.a;

			// compute final base color
			float4 base = float4(1,1,1,1);

			base.rgb = lerp( teamBaseCol.rgb  , c.rgb   , teamBaseAmount   );
			base.rgb = lerp( teamStripeCol.rgb, base.rgb, teamStripeAmount );
	
			half spec     = c2.b;
			half selfIlluBlue = c2.g;
			half selfIlluChangedBlue = selfIlluBlue * _SelfIlluminationBlue;
						
			o.Gloss    = spec;
			o.Specular = _Shininess;
			
			o.Emission = (selfIlluChangedBlue) * c;
			
			o.Albedo   = lerp( base.rgb, float3(0,0,0), selfIlluChangedBlue);
			o.Alpha    = base.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

This is the original shader:

static Texture $diffuse
static Texture $glow

simple base(Texture $diffuse, Texture $glow, Colour $teambase, Colour $teamstripe, Colour $fogColour, Colour $addColour, Colour $shadowColour)
{
    setCap depthBufferCap true
    setCap gouraudCap true
    setCap cullCap true
    setCap texture0Cap true
	setCap lightingCap true

    fillMode solidFill
    cullMode backCull

    material ambient   1 1 1 1
    material diffuse   1 1 1 1
    material specular  1 1 1 1
    material shininess 96 96 96 96
    setVertexColour    1 1 1 1

    textureBind 0 $diffuse
//    textureMode	replaceMode
}

simple light(Texture $diffuse, Texture $glow, Colour $teambase, Colour $teamstripe, Colour $fogColour, Colour $addColour, Colour $shadowColour)
{
    setCap depthBufferCap true
    setCap gouraudCap true
    setCap cullCap true
    setCap texture0Cap false
    setCap texture1Cap false
	setCap lightingCap true
	setCap blendCap true

    srcBlend	destColourBlend
    destBlend	zeroBlend

    fillMode solidFill
    cullMode backCull

    material ambient   1 1 1 1
    material diffuse   1 1 1 1
    material specular  1 1 1 1
    material shininess 96 96 96 96
    setVertexColour    1 1 1 1
}


simple fog(Texture $diffuse, Texture $glow, Colour $teambase, Colour $teamstripe, Colour $fogColour, Colour $addColour, Colour $shadowColour)
{
    setCap depthBufferCap true
    setCap gouraudCap true
    setCap blendCap true
    setCap cullCap		true

    srcBlend srcAlphaBlend
    destBlend invSrcAlphaBlend

    fillMode solidFill
    cullMode backCull

    setVertexColour    $fogColour    
}

compound ship()
{
    addPass base
    //addPass light
    addPass fog
}

Tinted in a dark gray it already looks nicely:

When tinted in red you can see the wrong effect:

35286-h2.png

Hope someone could help me out.

Finally solved it by myself.

Don’t know why I did not saw it:

  float teamBaseAmount   = 1 - c.a + c2.a;
  float teamStripeAmount = 1 - c2.a + c.a;