Skip to content

Instantly share code, notes, and snippets.

@isaveu
Forked from EsProgram/RimLighting.shader
Created May 16, 2016 00:37
Show Gist options
  • Save isaveu/764aff9e043cf4581f8c8f09439e7f5a to your computer and use it in GitHub Desktop.
Save isaveu/764aff9e043cf4581f8c8f09439e7f5a to your computer and use it in GitHub Desktop.
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