Skip to content

Instantly share code, notes, and snippets.

@baba-s
Last active May 26, 2021 14:57
Show Gist options
  • Select an option

  • Save baba-s/248aac78823925b7b10f2e5578610421 to your computer and use it in GitHub Desktop.

Select an option

Save baba-s/248aac78823925b7b10f2e5578610421 to your computer and use it in GitHub Desktop.
Shader "Custom/AlphaMask_Unlit"
{
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
}
SubShader
{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex: POSITION;
float2 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)
};
fixed4 _TintColor;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _AlphaMask;
half _AlphaAmount;
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 = 2.0f * v.color * _TintColor;
UNITY_TRANSFER_FOG(o, o.vertex);
return o;
}
fixed4 frag(v2f i): SV_Target
{
fixed4 col = i.color * 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
}
}
Fallback off
}
@LaikaGoesHome
Copy link

You are lifesafer) Nice working alpha mask with uv!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment