-
-
Save isaveu/764aff9e043cf4581f8c8f09439e7f5a 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 "Custom/RimLighting" { | |
Properties{ | |
_MainTex("Texture", 2D) = "white"{} | |
_RimWidth("RimWidth", Range(0.5, 5.0)) = 2.0 | |
_Color("Color", Color) = (1, 1, 1, 0) | |
} | |
SubShader{ | |
Pass{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
float _RimWidth; | |
float4 _Color; | |
float4 _MainTex_ST; | |
struct v2f | |
{ | |
float4 pos : POSITION; | |
float3 viewDir : Any; | |
float3 normal : NORMAL; | |
float2 texcoord : TEXCOORD0; | |
}; | |
v2f vert(appdata_base v) | |
{ | |
v2f o; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.viewDir = normalize(WorldSpaceViewDir(v.vertex)); | |
o.normal = normalize(v.normal); | |
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); | |
return o; | |
} | |
float4 frag(v2f i) : COLOR{ | |
half rim = 1.0 - saturate(dot(i.normal, i.viewDir)); | |
float3 col = _Color.rgb*pow(rim, _RimWidth); | |
col = (col + tex2D(_MainTex, i.texcoord)) / 2; | |
return float4(col, _Color.a); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment