Created
March 12, 2018 20:21
-
-
Save ohookins/ac4ce3f7ee964fbb7982c5b36d80a0fb to your computer and use it in GitHub Desktop.
Edges-only shader for cube-like things
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 "Custom/EdgesOnly" | |
{ | |
Properties | |
{ | |
_EdgeColor ("Edge Color", Color) = (1,1,1,1) | |
_EdgeWidth ("Edge Width", Range(0, 0.3)) = 0.1 | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
fixed4 _EdgeColor; | |
float _EdgeWidth; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = v.uv; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed4 col = (i.uv.x < _EdgeWidth || i.uv.x > 1-_EdgeWidth || i.uv.y < _EdgeWidth || i.uv.y > 1-_EdgeWidth) ? _EdgeColor : (0,0,0,0); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment