SpriteRe 2d Hologram Shader
Shader "Unlit/maskedSprite"
{
Properties
{
[Toggle]_ShowMask ("Preview mask", Float) = 0
[Space]
[Toggle]_UseAlpha ("Vertex Alpha > Threshold", Float) = 0
[Space]
_MaskThrs ("Mask Threshold", Range(0,1)) = .5
_MaskSoft ("Mask Width", Range (0.001, 3)) = 1
_MaskRot ("Mask rotation", Range (0, 1)) = 0
[Space]
[Toggle]_AutoThresh ("AutoCycle Threshold", Float) = 0
_AutoSpeed ("Auto Speed", Range(0,120)) = 5
[Space(20)]
[Header(Calibration)]
_MaskOffs ("Offset", Float) = 0
_MaskScal ("Scale", Float) = 1
[Space(20)]
[HDR]_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white"
_MaskTxtr ("Mask Gradient", 2D) = "white"
}
Category
{
Lighting Off
ZWrite Off
//ZWrite On // uncomment if you have problems like the sprite disappear in some rotations.
Cull off
Blend SrcAlpha OneMinusSrcAlpha
// AlphaTest Greater 0.001 // uncomment if you have problems like the sprites or 3d text have white quads instead of alpha pixels.
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
"DisableBatching"="True" // this disables batching (fixes issue when mask can be applied to multiple objects)
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
half4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _MaskTxtr;
float4 _MaskTxtr_ST;
half _ShowMask, _AutoThresh, _UseAlpha;
float _MaskThrs, _MaskAngl, _MaskSoft, _MaskRot, _MaskOffs, _MaskScal, _AutoSpeed;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 uv : TEXCOORD0;
float2 mask : TEXCOORD1;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.color = lerp(v.color, half4(v.color.rgb, 1), _UseAlpha);
o.uv = v.uv;
o.mask.x = (lerp(v.vertex.x,v.vertex.y,_MaskRot) + _MaskOffs) * _MaskScal;
float thsh = lerp( lerp(_MaskThrs, v.color.a, _UseAlpha), frac(_Time.x*_AutoSpeed), _AutoThresh);
o.mask.y = (thsh-.5) * (1 + _MaskSoft*2) + (thsh-.5);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float maskX = smoothstep( i.mask.y-_MaskSoft, i.mask.y+_MaskSoft, i.mask.x);
float mask = tex2D(_MaskTxtr, half2(maskX, _MaskTxtr_ST.z));
fixed4 smpl = tex2D(_MainTex, i.uv);
smpl.a *= mask;
smpl = lerp(smpl, fixed4(mask,mask,mask,1), _ShowMask);
clip(smpl.a-.001);
fixed4 color = i.color * _Color;
return smpl * color;
}
ENDCG
}
}
}
}