Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zombiemachines/4eb5ce917ddd36921dc67d5c3f7a7c1d to your computer and use it in GitHub Desktop.

Select an option

Save zombiemachines/4eb5ce917ddd36921dc67d5c3f7a7c1d to your computer and use it in GitHub Desktop.
Shader "Custom/AlphaMask_Additive"
{
Properties
{
_TintColor ("Tint Color", Color) = (0.5, 0.5, 0.5, 0.5)
_MainTex ("Base (RGB)", 2D) = "white" { }
_AlphaMask ("Alpha Mask", 2D) = "white" { }
_AlphaAmount ("Alpha Amount", Range(-1, 1)) = 1
}
CGINCLUDE
#include "UnityCG.cginc"
fixed4 _TintColor;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _AlphaMask;
half _AlphaAmount;
struct appdata_t
{
float4 vertex: POSITION;
float4 texcoord: TEXCOORD0;
float2 uv_AlphaMask: TEXCOORD1;
fixed4 color: COLOR;
};
struct v2f
{
float4 vertex: SV_POSITION;
float2 texcoord: TEXCOORD0;
float2 uv_AlphaMask: TEXCOORD1;
fixed4 color: COLOR;
UNITY_FOG_COORDS(1)
};
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv_AlphaMask = v.uv_AlphaMask;
o.color = v.color;
UNITY_TRANSFER_FOG(o, o.vertex);
return o;
}
fixed4 frag(v2f i): SV_Target
{
fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
float aMask = tex2D(_AlphaMask, i.uv_AlphaMask).g - _AlphaAmount;
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, (fixed4)0);
col.a = aMask;
return col;
}
ENDCG
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Blend SrcAlpha One
Cull Off Lighting Off ZWrite Off Fog
{
Mode Off
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
#pragma multi_compile_fog
ENDCG
}
}
Fallback off
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment