Created
January 25, 2018 06:36
-
-
Save beinteractive/34e43c0da55e23ea20b2cb4107b5a797 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
Shader "Dots" | |
{ | |
Properties | |
{ | |
_MainTex ("Main Texture", 2D) = "white" {} | |
_Color ("Main Color", Color) = (1, 1, 1, 1) | |
_Alpha ("Alpha", Float) = 1.0 | |
[MaterialToggle] _Invert ("Invert", Float) = 0.0 | |
} | |
CGINCLUDE | |
#pragma multi_compile_fwdbase | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
fixed4 _Color; | |
fixed _Alpha; | |
fixed _Invert; | |
float4 _MainTex_ST; | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 pos : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
float2 uv_nonscale : TEXCOORD1; | |
half3 normal : NORMAL; | |
}; | |
v2f vert(appdata v) | |
{ | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex); | |
o.normal = normalize(mul(unity_ObjectToWorld, float4(v.normal, 0))); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
o.uv_nonscale = v.uv; | |
return o; | |
} | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
fixed4 main = tex2D(_MainTex, i.uv); | |
fixed3 albedo = _Color.rgb; | |
fixed vertical = i.uv_nonscale.y; | |
if (_Invert > 0.0) | |
{ | |
vertical = 1.0 - vertical; | |
} | |
fixed threshold = 1.0 - (_Alpha * 2.0 - vertical); | |
fixed a = main.b > threshold || main.g > threshold; | |
a *= _Color.a; | |
fixed4 col = fixed4(albedo, a); | |
return col; | |
} | |
ENDCG | |
SubShader | |
{ | |
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } | |
Pass | |
{ | |
Lighting Off | |
ZWrite Off | |
Cull Back | |
Blend SrcAlpha OneMinusSrcAlpha | |
Tags { "LightMode" = "ForwardBase" } | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
ENDCG | |
} | |
} | |
Fallback "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment