Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Chaosed0
Created April 17, 2019 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chaosed0/77111cd7185b19fc894bb35d42ffd9bc to your computer and use it in GitHub Desktop.
Save Chaosed0/77111cd7185b19fc894bb35d42ffd9bc to your computer and use it in GitHub Desktop.
Simple rim light shader
Shader "Custom/Rimlight" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RimValue ("Rim value", Range(0, 1)) = 0.5
}
SubShader {
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
fixed _RimValue;
struct Input {
float2 uv_MainTex;
float3 viewDir;
float3 worldNormal;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
float3 normal = normalize(IN.worldNormal);
float3 dir = normalize(IN.viewDir);
float val = 1 - (abs(dot(dir, normal)));
float rim = val * val * _RimValue;
o.Alpha = c.a * rim;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment