Created
November 17, 2014 03:32
-
-
Save jagt/9a563fc6c367bc24d716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unlit alpha-blended shader with MainColor | |
// - no lighting | |
// - no lightmap support | |
// - with holes | |
Shader "Unlit/Transparent With Holes" { | |
Properties { | |
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} | |
_Radius ("Hole Radius", Float) = 50.0 | |
_CutOff1 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole1 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff2 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole2 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff3 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole3 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff4 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole4 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff5 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole5 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff6 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole6 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff7 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole7 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
_CutOff8 ("Cut Off Ratio, ranges from [0, 1", Float) = 0.6 | |
_Hole8 ("Hole 1 World Pos, set .w to 1 to use", Vector) = (0, 0, 0, 0) | |
} | |
SubShader { | |
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} | |
LOD 1 | |
ZWrite Off | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata_t { | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 vertex : SV_POSITION; | |
half2 texcoord : TEXCOORD0; | |
float4 posWorld : TEXCOORD1; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
uniform float _Radius; | |
uniform float _CutOff1; | |
uniform float4 _Hole1; | |
uniform float _CutOff2; | |
uniform float4 _Hole2; | |
uniform float _CutOff3; | |
uniform float4 _Hole3; | |
uniform float _CutOff4; | |
uniform float4 _Hole4; | |
uniform float _CutOff5; | |
uniform float4 _Hole5; | |
uniform float _CutOff6; | |
uniform float4 _Hole6; | |
uniform float _CutOff7; | |
uniform float4 _Hole7; | |
uniform float _CutOff8; | |
uniform float4 _Hole8; | |
v2f vert (appdata_t v) | |
{ | |
v2f o; | |
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); | |
o.posWorld = mul(_Object2World, v.vertex); | |
return o; | |
} | |
void calc_alpha(in float4 posWorld, in float4 hole, in float cutoff, inout fixed4 col) | |
{ | |
float dist = distance(posWorld.xy, hole.xy); | |
float cutoffDist = _Radius * cutoff; | |
float calcAlpha; | |
if (hole.w == 0 || dist > _Radius) calcAlpha = 1.0; | |
else if (dist < cutoffDist) calcAlpha = 0.0; | |
else calcAlpha = lerp(0, 1, (dist - cutoffDist)/(_Radius - cutoffDist)); | |
if (calcAlpha < col.a) | |
{ | |
col.a = calcAlpha; | |
} | |
return; | |
} | |
fixed4 frag (v2f i) : COLOR | |
{ | |
fixed4 col = tex2D(_MainTex, i.texcoord); | |
calc_alpha(i.posWorld, _Hole1, _CutOff1, col); | |
calc_alpha(i.posWorld, _Hole2, _CutOff2, col); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment