Last active
January 22, 2016 03:49
-
-
Save hiepnd/b8e9949c55e922c8b8c4 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 "Screw/Silhouetted Diffuse" { | |
Properties { | |
_Color ("Main Color", Color) = (.5,.5,.5,1) | |
_FrontColor ("Front Color", Color) = (.5,.5,.5,1) | |
_OutlineColor ("Outline Color", Color) = (0,0,0,1) | |
_Outline ("Outline width", Range (0.0, 0.1)) = .005 | |
_MainTex ("Base (RGB)", 2D) = "white" { } | |
_Alpha ("Alpha", Range(0, 1)) = 1 | |
} | |
CGINCLUDE | |
#include "UnityCG.cginc" | |
struct appdata { | |
half4 vertex : POSITION; | |
half3 normal : NORMAL; | |
half2 texcoord : TEXCOORD0; | |
half4 color : COLOR; | |
}; | |
struct v2f { | |
half4 pos : POSITION; | |
half4 color : COLOR; | |
half2 uv : TEXCOORD0; | |
half3 normalDir : NORMAL; | |
}; | |
uniform float _Outline; | |
uniform float4 _OutlineColor; | |
v2f vert(appdata v) { | |
v2f o; | |
// half3 vertex = v.vertex.xyz; | |
// vertex += _Outline * v.color; | |
// o.pos = mul(UNITY_MATRIX_MVP, half4(vertex, v.vertex.w)); | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
half3 norm = normalize(mul ((float3x3)UNITY_MATRIX_IT_MV, v.color.xyz)); | |
o.pos.xyz += _Outline * norm; | |
o.color = _OutlineColor; | |
return o; | |
} | |
ENDCG | |
SubShader { | |
Tags { "Queue" = "Transparent" } | |
Pass { | |
Name "OUTLINE" | |
Cull Off | |
ZWrite Off | |
ZTest Always | |
ColorMask RGB | |
Blend SrcAlpha OneMinusSrcAlpha | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
half _Alpha; | |
half4 frag(v2f i) :COLOR { | |
return half4(i.color.rgb, _Alpha); | |
} | |
ENDCG | |
} | |
Pass { | |
Name "BASE" | |
ZWrite On | |
ZTest LEqual | |
Blend SrcAlpha OneMinusSrcAlpha | |
CGPROGRAM | |
#pragma vertex vert2 | |
#pragma fragment frag | |
v2f vert2 (appdata v) | |
{ | |
v2f o; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.uv = v.texcoord; | |
o.normalDir = normalize(mul(half4(v.normal, 0), _World2Object).xyz); | |
return o; | |
} | |
uniform sampler2D _MainTex; | |
half4 _Color; | |
half4 _FrontColor; | |
half _Alpha; | |
half4 frag (v2f i) : COLOR | |
{ | |
half4 color = _Color; | |
if (dot(i.normalDir, half3(0, 0, -1)) > 1/sqrt(2) || dot(i.normalDir, half3(0, 0, 1)) > 1/sqrt(2)) { | |
color = _FrontColor; | |
} | |
color.a = _Alpha; | |
return color; | |
} | |
ENDCG | |
} | |
} | |
Fallback "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment