Created
August 25, 2015 12:16
-
-
Save TheLouisHong/2e5e7bfe5acdca6df4ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "Custom/Circle" { | |
Properties | |
{ | |
_Scale("Scale", Float) = 1 | |
} | |
SubShader{ | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma target 2.0 | |
#include "UnityCG.cginc" | |
float _Scale; | |
struct vertexInput { | |
float4 vertex : POSITION; | |
float4 texcoord0 : TEXCOORD0; | |
}; | |
struct fragmentInput { | |
float4 position : SV_POSITION; | |
float4 texcoord0 : TEXCOORD0; | |
}; | |
fragmentInput vert(vertexInput i) { | |
fragmentInput o; | |
o.position = mul(UNITY_MATRIX_MVP, i.vertex); | |
o.texcoord0 = i.texcoord0; | |
return o; | |
} | |
fixed4 frag(fragmentInput i) : SV_Target | |
{ | |
float dx = 0.5 - i.texcoord0.x, dy = 0.5 - i.texcoord0.y; | |
float dist = dx * dx + dy * dy; | |
float distFromCenter = 0.25 - dist; // positive when inside the circle | |
if (distFromCenter > 0) { | |
if (distFromCenter > 0.025) | |
return 0; | |
return 1; | |
} | |
return 0; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment