Unity Custom CutOut Shader

Hey guys!

I’ve been searching Google, Unity forums and Unity Answers, all looking for a simple solution to my problem.

I downloaded the latest source files for built in shaders.

I then adapted the Cutout Diffuse/Spec/Normal/NormSpec shaders to use a custom texture for my alpha. This is primarily for carpet edges, fade out effects, etc.

The problem I’ve come across is that for lightmapping, it seems to always want to use the Alpha Channel of “_MainTex”, regardless of how I have set up the surface shader.

In a previous thread I read that downloading the Extended Lightmapper plugin would help, but I didn’t see any settings that would help with this case.

So is this to do with Unity’s internal workings, or is it because of the fallback shader handling the shadow casting.

If it’s the latter, how do I fix this?

Here’s the Cutout Diffuse Shader. You can see how little of a change I made.

Shader "Fade/Diffuse"
{
	Properties
	{
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
		_AlphaTex ("Alpha", 2D) = "white" {}
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
	}

	SubShader
	{
		Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
		LOD 300
		
		CGPROGRAM
		#pragma surface surf Lambert alphatest:_Cutoff

		sampler2D _MainTex;
		sampler2D _AlphaTex;
		fixed4 _Color;

		struct Input
		{
			float2 uv_MainTex;
			float2 uv_AlphaTex;
		};

		void surf (Input IN, inout SurfaceOutput o)
		{
			fixed4 MAIN = tex2D(_MainTex, IN.uv_MainTex) * _Color;
			fixed4 ALPHA = tex2D(_AlphaTex, IN.uv_AlphaTex);
			o.Albedo = MAIN.rgb;
			o.Alpha = ALPHA;
		}
		ENDCG
	}

	FallBack "Transparent/Cutout/Diffuse"
}

Thanks!

If you just want the alpha from your alpha texture, you should use ALPHA.a.

Unless you are trying to calculate alpha from the RGB values as well. In such a case, you would need to tell the shader which calculation to use (like adding the RGB values together or using the dot product).